@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.
Files changed (49) hide show
  1. package/README.md +30 -0
  2. package/dist/auth/handler.js +24 -25
  3. package/dist/builder/create.d.ts +3 -2
  4. package/dist/builder/create.js +44 -47
  5. package/dist/builder/derive.d.ts +2 -0
  6. package/dist/builder/derive.js +21 -0
  7. package/dist/builder/index.d.ts +1 -1
  8. package/dist/builder/index.js +1 -1
  9. package/dist/builder/proxy.d.ts +3 -2
  10. package/dist/builder/proxy.js +64 -83
  11. package/dist/builder/safe.d.ts +4 -3
  12. package/dist/builder/safe.js +52 -77
  13. package/dist/client.d.ts +10 -8
  14. package/dist/client.js +119 -133
  15. package/dist/config/index.d.ts +13 -0
  16. package/dist/config/index.js +35 -0
  17. package/dist/constants/index.d.ts +0 -4
  18. package/dist/constants/index.js +1 -5
  19. package/dist/encode/index.d.ts +0 -1
  20. package/dist/encode/index.js +0 -1
  21. package/dist/encode/proxy.d.ts +1 -1
  22. package/dist/encode/proxy.js +12 -7
  23. package/dist/encode/safe.d.ts +1 -1
  24. package/dist/encode/safe.js +11 -9
  25. package/dist/http-helpers/index.js +33 -35
  26. package/dist/index.d.ts +1 -1
  27. package/dist/index.js +1 -1
  28. package/dist/manual/index.d.ts +4 -4
  29. package/dist/manual/index.js +36 -17
  30. package/dist/response/index.d.ts +21 -2
  31. package/dist/response/index.js +41 -3
  32. package/dist/types.d.ts +8 -3
  33. package/dist/utils/index.d.ts +6 -0
  34. package/dist/utils/index.js +28 -0
  35. package/package.json +21 -28
  36. package/dist/builder/utils.d.ts +0 -2
  37. package/dist/builder/utils.js +0 -13
  38. package/dist/encode/utils.d.ts +0 -6
  39. package/dist/encode/utils.js +0 -46
  40. package/dist/response/relayer.d.ts +0 -12
  41. package/dist/response/relayer.js +0 -28
  42. package/dist/response/viem.d.ts +0 -8
  43. package/dist/response/viem.js +0 -19
  44. package/dist/signeradapter/adapter.d.ts +0 -20
  45. package/dist/signeradapter/adapter.js +0 -188
  46. package/dist/signeradapter/index.d.ts +0 -2
  47. package/dist/signeradapter/index.js +0 -5
  48. package/dist/signeradapter/interfaces.d.ts +0 -8
  49. 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 tslib_1.__awaiter(this, void 0, void 0, function* () {
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 tslib_1.__awaiter(this, void 0, void 0, function* () {
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 tslib_1.__awaiter(this, void 0, void 0, function* () {
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 tslib_1.__awaiter(this, void 0, void 0, function* () {
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 tslib_1.__awaiter(this, void 0, void 0, function* () {
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
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
55
- if (this.signer == undefined) {
56
- throw new Error("missing signer");
57
- }
58
- const start = Date.now();
59
- const from = yield this.signer.getAddress();
60
- const rp = yield this.getRelayPayload(from, types_1.TransactionType.PROXY);
61
- const args = {
62
- from: from,
63
- gasPrice: "0",
64
- data: (0, encode_1.encodeProxyTransactionData)(txns),
65
- relay: rp.address,
66
- nonce: rp.nonce,
67
- };
68
- const request = yield (0, builder_1.buildProxyTransactionRequest)(this.signer, args, metadata);
69
- console.log(`Client side proxy request creation took: ${(Date.now() - start) / 1000} seconds`);
70
- const resp = yield this.submitTransaction(request);
71
- return new response_1.ClientRelayerTransactionResponse(resp.transactionID, resp.state, resp.transactionHash, this);
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
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
76
- if (this.signer == undefined) {
77
- throw new Error("missing signer");
78
- }
79
- const start = Date.now();
80
- const from = yield this.signer.getAddress();
81
- // Note: goes over the network
82
- const noncePayload = yield this.getNonce(from, types_1.TransactionType.SAFE);
83
- const args = {
84
- transactions: txns,
85
- from,
86
- nonce: noncePayload.nonce,
87
- chainId: this.chainId,
88
- };
89
- const request = yield (0, builder_1.buildSafeTransactionRequest)(this.signer, args, metadata);
90
- console.log(`Client side safe request creation took: ${(Date.now() - start) / 1000} seconds`);
91
- const resp = yield this.submitTransaction(request);
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
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
97
- if (overrides == undefined) {
98
- overrides = {};
99
- }
100
- if (this.signer == undefined) {
101
- throw new Error("missing signer");
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
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
108
- var _a;
109
- if (this.signer == undefined) {
110
- throw new Error("missing signer");
111
- }
112
- const start = Date.now();
113
- const from = yield ((_a = this.signer) === null || _a === void 0 ? void 0 : _a.getAddress());
114
- const args = {
115
- from: from,
116
- chainId: this.chainId,
117
- paymentToken: ethers_1.ethers.constants.AddressZero,
118
- payment: "0",
119
- paymentReceiver: ethers_1.ethers.constants.AddressZero,
120
- };
121
- const request = yield (0, builder_1.buildSafeCreateTransactionRequest)(this.signer, args);
122
- console.log(`Client side deploy request creation took: ${(Date.now() - start) / 1000} seconds`);
123
- const resp = yield this.submitTransaction(request);
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
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
139
- console.log(`Waiting for transaction ${transactionId} matching states: ${states}...`);
140
- const maxPollCount = maxPolls != undefined ? maxPolls : 10;
141
- let pollFreq = 2000; // Default to polling every 2 seconds
142
- if (pollFrequency != undefined) {
143
- if (pollFrequency >= 1000) {
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
- let pollCount = 0;
148
- while (pollCount < maxPollCount) {
149
- const txns = yield this.getTransaction(transactionId);
150
- if (txns.length > 0) {
151
- const txn = txns[0];
152
- if (states.includes(txn.state)) {
153
- return txn;
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
- console.log(`Transaction not found or not in given states, timing out`);
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 tslib_1.__awaiter(this, void 0, void 0, function* () {
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
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
169
- // Explicitly inject the polymarket session cookies
170
- // In prod environments, this will be unnecessary as the browser will have the needed cookies
171
- // Needed only for local testing
172
- if (!browser_or_node_1.default && this.authHandler !== undefined) {
173
- const cookie = yield this.authHandler.getPolymarketCookies();
174
- if (headers != undefined) {
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
- const resp = yield this.httpClient.send(endpoint, method, headers, data, params);
182
- return resp.data;
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";
@@ -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 = exports.SAFE_MULTISEND_ADDRESS = exports.SAFE_FACTORY_ADDRESS = exports.PROXY_WALLET_FACTORY_ADDRESS = exports.RELAY_HUB_ADDRESS = void 0;
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";
@@ -1,3 +1,2 @@
1
1
  export * from "./proxy";
2
2
  export * from "./safe";
3
- export * from "./utils";
@@ -3,4 +3,3 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  tslib_1.__exportStar(require("./proxy"), exports);
5
5
  tslib_1.__exportStar(require("./safe"), exports);
6
- tslib_1.__exportStar(require("./utils"), exports);
@@ -1,2 +1,2 @@
1
1
  import { ProxyTransaction } from "../types";
2
- export declare const encodeProxyTransactionData: (txns: ProxyTransaction[]) => string;
2
+ export declare function encodeProxyTransactionData(txns: ProxyTransaction[]): string;
@@ -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
+ }
@@ -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;
@@ -1,18 +1,20 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createSafeMultisendTransaction = void 0;
4
- const utils_1 = require("ethers/lib/utils");
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 utils_2 = require("./utils");
9
- const multisendInterface = new utils_1.Interface(abis_1.multisendAbi);
10
- const createSafeMultisendTransaction = (txns) => {
11
- const data = multisendInterface.encodeFunctionData("multiSend", [
12
- (0, utils_2.joinHexData)(txns.map(tx => (0, utils_2.abiEncodePacked)({ type: "uint8", value: tx.operation }, { type: "address", value: tx.to }, { type: "uint256", value: tx.value }, { type: "uint256", value: (0, utils_2.getHexDataLength)(tx.data) }, { type: "bytes", value: tx.data }))),
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: constants_1.SAFE_MULTISEND_ADDRESS,
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
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
16
- var _a, _b, _c;
17
- if (headers != undefined) {
18
- headers["Access-Control-Allow-Credentials"] = true;
19
- }
20
- try {
21
- const resp = yield this.instance.request({
22
- method,
23
- url: endpoint,
24
- headers,
25
- data,
26
- params
27
- });
28
- return resp;
29
- }
30
- catch (err) {
31
- if (axios_1.default.isAxiosError(err)) {
32
- if (err.response) {
33
- const errPayload = {
34
- error: "request error",
35
- status: (_a = err.response) === null || _a === void 0 ? void 0 : _a.status,
36
- statusText: (_b = err.response) === null || _b === void 0 ? void 0 : _b.statusText,
37
- data: (_c = err.response) === null || _c === void 0 ? void 0 : _c.data,
38
- };
39
- console.error("request error", errPayload);
40
- throw new Error(JSON.stringify(errPayload));
41
- }
42
- else {
43
- const errPayload = { error: "connection error" };
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
@@ -1,4 +1,4 @@
1
1
  export * from "./client";
2
+ export * from "./encode";
2
3
  export * from "./types";
3
- export * from "./signeradapter";
4
4
  export * from "./response";
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);
@@ -1,5 +1,5 @@
1
- import { TransactionResponse } from "@ethersproject/abstract-provider";
1
+ import { IAbstractSigner } from "@polymarket/abstract-signer";
2
+ import { SafeContractConfig } from "../config";
2
3
  import { SafeTransaction, ManualOverrides } from "../types";
3
- import { SignerAdapter } from "../signeradapter";
4
- import { ViemTransactionResponse } from "../response";
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>;
@@ -1,20 +1,22 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.executeManualTransactions = executeManualTransactions;
4
- const tslib_1 = require("tslib");
5
- const ethers_1 = require("ethers");
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
- function executeManualTransactions(signer, transactions, overrides) {
10
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
11
- const from = yield signer.getAddress();
12
- const aggTxn = (0, builder_1.aggregateTransaction)(transactions);
13
- const sig = (0, encode_1.abiEncodePacked)({ type: "uint256", value: from }, // r
14
- { type: "uint256", value: 0 }, // s
15
- { type: "uint8", value: 1 });
16
- const safeAddress = (0, builder_1.deriveSafe)(from);
17
- const args = [
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
- ethers_1.ethers.constants.AddressZero,
26
- ethers_1.ethers.constants.AddressZero,
27
+ viem_1.zeroAddress,
28
+ viem_1.zeroAddress,
27
29
  sig,
28
- ];
29
- return signer.writeContract(safeAddress, abis_1.safeAbi, overrides, "execTransaction", args);
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
  }