@safe-global/api-kit 3.0.0-alpha.1 → 3.0.0-alpha.3
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/cjs/index.cjs +254 -250
- package/dist/esm/index.mjs +253 -249
- package/dist/src/SafeApiKit.d.ts +80 -83
- package/dist/src/SafeApiKit.d.ts.map +1 -1
- package/dist/src/types/safeTransactionServiceTypes.d.ts +40 -22
- package/dist/src/types/safeTransactionServiceTypes.d.ts.map +1 -1
- package/dist/src/utils/config.d.ts.map +1 -1
- package/dist/src/utils/httpRequests.d.ts.map +1 -1
- package/dist/src/utils/queryParamsMap.d.ts +5 -0
- package/dist/src/utils/queryParamsMap.d.ts.map +1 -0
- package/package.json +5 -5
package/dist/cjs/index.cjs
CHANGED
|
@@ -35,9 +35,9 @@ __export(src_exports, {
|
|
|
35
35
|
module.exports = __toCommonJS(src_exports);
|
|
36
36
|
|
|
37
37
|
// src/utils/httpRequests.ts
|
|
38
|
-
var import_node_fetch = __toESM(require("node-fetch"));
|
|
39
38
|
async function sendRequest({ url, method, body }) {
|
|
40
|
-
const
|
|
39
|
+
const fetch = await (typeof window === "undefined" ? import("node-fetch").then((m) => m.default) : Promise.resolve(window.fetch));
|
|
40
|
+
const response = await fetch(url, {
|
|
41
41
|
method,
|
|
42
42
|
headers: {
|
|
43
43
|
Accept: "application/json",
|
|
@@ -111,9 +111,11 @@ var TRANSACTION_SERVICE_URLS = {
|
|
|
111
111
|
"10": "https://safe-transaction-optimism.safe.global/api",
|
|
112
112
|
"56": "https://safe-transaction-bsc.safe.global/api",
|
|
113
113
|
"100": "https://safe-transaction-gnosis-chain.safe.global/api",
|
|
114
|
+
"130": "https://safe-transaction-unichain.safe.global/api",
|
|
114
115
|
"137": "https://safe-transaction-polygon.safe.global/api",
|
|
115
116
|
"196": "https://safe-transaction-xlayer.safe.global/api",
|
|
116
117
|
"324": "https://safe-transaction-zksync.safe.global/api",
|
|
118
|
+
"480": "https://safe-transaction-worldchain.safe.global/api",
|
|
117
119
|
"1101": "https://safe-transaction-zkevm.safe.global/api",
|
|
118
120
|
"5000": "https://safe-transaction-mantle.safe.global/api",
|
|
119
121
|
"8453": "https://safe-transaction-base.safe.global/api",
|
|
@@ -153,6 +155,11 @@ var isSafeOperation = (obj) => {
|
|
|
153
155
|
return "signatures" in obj && "getUserOperation" in obj && "getHash" in obj;
|
|
154
156
|
};
|
|
155
157
|
|
|
158
|
+
// src/utils/queryParamsMap.ts
|
|
159
|
+
var QUERY_PARAMS_MAP = {
|
|
160
|
+
from: "_from"
|
|
161
|
+
};
|
|
162
|
+
|
|
156
163
|
// src/SafeApiKit.ts
|
|
157
164
|
var SafeApiKit = class {
|
|
158
165
|
#chainId;
|
|
@@ -182,6 +189,24 @@ var SafeApiKit = class {
|
|
|
182
189
|
#getEip3770Address(fullAddress) {
|
|
183
190
|
return (0, import_protocol_kit.validateEip3770Address)(fullAddress, this.#chainId);
|
|
184
191
|
}
|
|
192
|
+
/**
|
|
193
|
+
* Adds query parameters from an options object to a given URL.
|
|
194
|
+
* Converts parameter names to snake_case automatically. If a specific mapping exists in QUERY_PARAMS_MAP,
|
|
195
|
+
* it will be used instead of the converted name.
|
|
196
|
+
*
|
|
197
|
+
* @param {URL} url - The URL object to which query parameters will be added.
|
|
198
|
+
* @param {T} options - An object containing key-value pairs representing query parameters.
|
|
199
|
+
* @returns {void}
|
|
200
|
+
*/
|
|
201
|
+
#addUrlQueryParams(url, options) {
|
|
202
|
+
const camelToSnake = (str) => str.replace(/([A-Z])/g, "_$1").toLowerCase();
|
|
203
|
+
Object.entries(options || {}).forEach(([key, value]) => {
|
|
204
|
+
if (value !== void 0) {
|
|
205
|
+
const name = QUERY_PARAMS_MAP[key] ?? camelToSnake(key);
|
|
206
|
+
url.searchParams.set(name, value.toString());
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
}
|
|
185
210
|
/**
|
|
186
211
|
* Returns the information and configuration of the service.
|
|
187
212
|
*
|
|
@@ -228,125 +253,6 @@ var SafeApiKit = class {
|
|
|
228
253
|
body: dataDecoderRequest
|
|
229
254
|
});
|
|
230
255
|
}
|
|
231
|
-
/**
|
|
232
|
-
* Returns the list of Safes where the address provided is an owner.
|
|
233
|
-
*
|
|
234
|
-
* @param ownerAddress - The owner address
|
|
235
|
-
* @returns The list of Safes where the address provided is an owner
|
|
236
|
-
* @throws "Invalid owner address"
|
|
237
|
-
* @throws "Checksum address validation failed"
|
|
238
|
-
*/
|
|
239
|
-
async getSafesByOwner(ownerAddress) {
|
|
240
|
-
if (ownerAddress === "") {
|
|
241
|
-
throw new Error("Invalid owner address");
|
|
242
|
-
}
|
|
243
|
-
const { address } = this.#getEip3770Address(ownerAddress);
|
|
244
|
-
return sendRequest({
|
|
245
|
-
url: `${this.#txServiceBaseUrl}/v1/owners/${address}/safes/`,
|
|
246
|
-
method: "get" /* Get */
|
|
247
|
-
});
|
|
248
|
-
}
|
|
249
|
-
/**
|
|
250
|
-
* Returns the list of Safes where the module address provided is enabled.
|
|
251
|
-
*
|
|
252
|
-
* @param moduleAddress - The Safe module address
|
|
253
|
-
* @returns The list of Safe addresses where the module provided is enabled
|
|
254
|
-
* @throws "Invalid module address"
|
|
255
|
-
* @throws "Module address checksum not valid"
|
|
256
|
-
*/
|
|
257
|
-
async getSafesByModule(moduleAddress) {
|
|
258
|
-
if (moduleAddress === "") {
|
|
259
|
-
throw new Error("Invalid module address");
|
|
260
|
-
}
|
|
261
|
-
const { address } = this.#getEip3770Address(moduleAddress);
|
|
262
|
-
return sendRequest({
|
|
263
|
-
url: `${this.#txServiceBaseUrl}/v1/modules/${address}/safes/`,
|
|
264
|
-
method: "get" /* Get */
|
|
265
|
-
});
|
|
266
|
-
}
|
|
267
|
-
/**
|
|
268
|
-
* Returns all the information of a Safe transaction.
|
|
269
|
-
*
|
|
270
|
-
* @param safeTxHash - Hash of the Safe transaction
|
|
271
|
-
* @returns The information of a Safe transaction
|
|
272
|
-
* @throws "Invalid safeTxHash"
|
|
273
|
-
* @throws "Not found."
|
|
274
|
-
*/
|
|
275
|
-
async getTransaction(safeTxHash) {
|
|
276
|
-
if (safeTxHash === "") {
|
|
277
|
-
throw new Error("Invalid safeTxHash");
|
|
278
|
-
}
|
|
279
|
-
return sendRequest({
|
|
280
|
-
url: `${this.#txServiceBaseUrl}/v1/multisig-transactions/${safeTxHash}/`,
|
|
281
|
-
method: "get" /* Get */
|
|
282
|
-
});
|
|
283
|
-
}
|
|
284
|
-
/**
|
|
285
|
-
* Returns the list of confirmations for a given a Safe transaction.
|
|
286
|
-
*
|
|
287
|
-
* @param safeTxHash - The hash of the Safe transaction
|
|
288
|
-
* @returns The list of confirmations
|
|
289
|
-
* @throws "Invalid safeTxHash"
|
|
290
|
-
*/
|
|
291
|
-
async getTransactionConfirmations(safeTxHash) {
|
|
292
|
-
if (safeTxHash === "") {
|
|
293
|
-
throw new Error("Invalid safeTxHash");
|
|
294
|
-
}
|
|
295
|
-
return sendRequest({
|
|
296
|
-
url: `${this.#txServiceBaseUrl}/v1/multisig-transactions/${safeTxHash}/confirmations/`,
|
|
297
|
-
method: "get" /* Get */
|
|
298
|
-
});
|
|
299
|
-
}
|
|
300
|
-
/**
|
|
301
|
-
* Adds a confirmation for a Safe transaction.
|
|
302
|
-
*
|
|
303
|
-
* @param safeTxHash - Hash of the Safe transaction that will be confirmed
|
|
304
|
-
* @param signature - Signature of the transaction
|
|
305
|
-
* @returns
|
|
306
|
-
* @throws "Invalid safeTxHash"
|
|
307
|
-
* @throws "Invalid signature"
|
|
308
|
-
* @throws "Malformed data"
|
|
309
|
-
* @throws "Error processing data"
|
|
310
|
-
*/
|
|
311
|
-
async confirmTransaction(safeTxHash, signature) {
|
|
312
|
-
if (safeTxHash === "") {
|
|
313
|
-
throw new Error("Invalid safeTxHash");
|
|
314
|
-
}
|
|
315
|
-
if (signature === "") {
|
|
316
|
-
throw new Error("Invalid signature");
|
|
317
|
-
}
|
|
318
|
-
return sendRequest({
|
|
319
|
-
url: `${this.#txServiceBaseUrl}/v1/multisig-transactions/${safeTxHash}/confirmations/`,
|
|
320
|
-
method: "post" /* Post */,
|
|
321
|
-
body: {
|
|
322
|
-
signature
|
|
323
|
-
}
|
|
324
|
-
});
|
|
325
|
-
}
|
|
326
|
-
/**
|
|
327
|
-
* Returns the information and configuration of the provided Safe address.
|
|
328
|
-
*
|
|
329
|
-
* @param safeAddress - The Safe address
|
|
330
|
-
* @returns The information and configuration of the provided Safe address
|
|
331
|
-
* @throws "Invalid Safe address"
|
|
332
|
-
* @throws "Checksum address validation failed"
|
|
333
|
-
*/
|
|
334
|
-
async getSafeInfo(safeAddress) {
|
|
335
|
-
if (safeAddress === "") {
|
|
336
|
-
throw new Error("Invalid Safe address");
|
|
337
|
-
}
|
|
338
|
-
const { address } = this.#getEip3770Address(safeAddress);
|
|
339
|
-
return sendRequest({
|
|
340
|
-
url: `${this.#txServiceBaseUrl}/v1/safes/${address}/`,
|
|
341
|
-
method: "get" /* Get */
|
|
342
|
-
}).then((response) => {
|
|
343
|
-
if (!response?.singleton) {
|
|
344
|
-
const { masterCopy, ...rest } = response;
|
|
345
|
-
return { ...rest, singleton: masterCopy };
|
|
346
|
-
}
|
|
347
|
-
return response;
|
|
348
|
-
});
|
|
349
|
-
}
|
|
350
256
|
/**
|
|
351
257
|
* Returns the list of delegates.
|
|
352
258
|
*
|
|
@@ -468,6 +374,189 @@ var SafeApiKit = class {
|
|
|
468
374
|
}
|
|
469
375
|
});
|
|
470
376
|
}
|
|
377
|
+
/**
|
|
378
|
+
* Get a message by its safe message hash
|
|
379
|
+
* @param messageHash The Safe message hash
|
|
380
|
+
* @returns The message
|
|
381
|
+
*/
|
|
382
|
+
async getMessage(messageHash) {
|
|
383
|
+
if (!messageHash) {
|
|
384
|
+
throw new Error("Invalid messageHash");
|
|
385
|
+
}
|
|
386
|
+
return sendRequest({
|
|
387
|
+
url: `${this.#txServiceBaseUrl}/v1/messages/${messageHash}/`,
|
|
388
|
+
method: "get" /* Get */
|
|
389
|
+
});
|
|
390
|
+
}
|
|
391
|
+
/**
|
|
392
|
+
* Get the list of messages associated to a Safe account
|
|
393
|
+
* @param safeAddress The safe address
|
|
394
|
+
* @param options The options to filter the list of messages
|
|
395
|
+
* @returns The paginated list of messages
|
|
396
|
+
*/
|
|
397
|
+
async getMessages(safeAddress, options = {}) {
|
|
398
|
+
if (!this.#isValidAddress(safeAddress)) {
|
|
399
|
+
throw new Error("Invalid safeAddress");
|
|
400
|
+
}
|
|
401
|
+
const url = new URL(`${this.#txServiceBaseUrl}/v1/safes/${safeAddress}/messages/`);
|
|
402
|
+
this.#addUrlQueryParams(url, options);
|
|
403
|
+
return sendRequest({
|
|
404
|
+
url: url.toString(),
|
|
405
|
+
method: "get" /* Get */
|
|
406
|
+
});
|
|
407
|
+
}
|
|
408
|
+
/**
|
|
409
|
+
* Creates a new message with an initial signature
|
|
410
|
+
* Add more signatures from other owners using addMessageSignature()
|
|
411
|
+
* @param safeAddress The safe address
|
|
412
|
+
* @param options The raw message to add, signature and safeAppId if any
|
|
413
|
+
*/
|
|
414
|
+
async addMessage(safeAddress, addMessageOptions) {
|
|
415
|
+
if (!this.#isValidAddress(safeAddress)) {
|
|
416
|
+
throw new Error("Invalid safeAddress");
|
|
417
|
+
}
|
|
418
|
+
return sendRequest({
|
|
419
|
+
url: `${this.#txServiceBaseUrl}/v1/safes/${safeAddress}/messages/`,
|
|
420
|
+
method: "post" /* Post */,
|
|
421
|
+
body: addMessageOptions
|
|
422
|
+
});
|
|
423
|
+
}
|
|
424
|
+
/**
|
|
425
|
+
* Add a signature to an existing message
|
|
426
|
+
* @param messageHash The safe message hash
|
|
427
|
+
* @param signature The signature
|
|
428
|
+
*/
|
|
429
|
+
async addMessageSignature(messageHash, signature) {
|
|
430
|
+
if (!messageHash || !signature) {
|
|
431
|
+
throw new Error("Invalid messageHash or signature");
|
|
432
|
+
}
|
|
433
|
+
return sendRequest({
|
|
434
|
+
url: `${this.#txServiceBaseUrl}/v1/messages/${messageHash}/signatures/`,
|
|
435
|
+
method: "post" /* Post */,
|
|
436
|
+
body: {
|
|
437
|
+
signature
|
|
438
|
+
}
|
|
439
|
+
});
|
|
440
|
+
}
|
|
441
|
+
/**
|
|
442
|
+
* Returns the list of Safes where the address provided is an owner.
|
|
443
|
+
*
|
|
444
|
+
* @param ownerAddress - The owner address
|
|
445
|
+
* @returns The list of Safes where the address provided is an owner
|
|
446
|
+
* @throws "Invalid owner address"
|
|
447
|
+
* @throws "Checksum address validation failed"
|
|
448
|
+
*/
|
|
449
|
+
async getSafesByOwner(ownerAddress) {
|
|
450
|
+
if (ownerAddress === "") {
|
|
451
|
+
throw new Error("Invalid owner address");
|
|
452
|
+
}
|
|
453
|
+
const { address } = this.#getEip3770Address(ownerAddress);
|
|
454
|
+
return sendRequest({
|
|
455
|
+
url: `${this.#txServiceBaseUrl}/v1/owners/${address}/safes/`,
|
|
456
|
+
method: "get" /* Get */
|
|
457
|
+
});
|
|
458
|
+
}
|
|
459
|
+
/**
|
|
460
|
+
* Returns the list of Safes where the module address provided is enabled.
|
|
461
|
+
*
|
|
462
|
+
* @param moduleAddress - The Safe module address
|
|
463
|
+
* @returns The list of Safe addresses where the module provided is enabled
|
|
464
|
+
* @throws "Invalid module address"
|
|
465
|
+
* @throws "Module address checksum not valid"
|
|
466
|
+
*/
|
|
467
|
+
async getSafesByModule(moduleAddress) {
|
|
468
|
+
if (moduleAddress === "") {
|
|
469
|
+
throw new Error("Invalid module address");
|
|
470
|
+
}
|
|
471
|
+
const { address } = this.#getEip3770Address(moduleAddress);
|
|
472
|
+
return sendRequest({
|
|
473
|
+
url: `${this.#txServiceBaseUrl}/v1/modules/${address}/safes/`,
|
|
474
|
+
method: "get" /* Get */
|
|
475
|
+
});
|
|
476
|
+
}
|
|
477
|
+
/**
|
|
478
|
+
* Returns all the information of a Safe transaction.
|
|
479
|
+
*
|
|
480
|
+
* @param safeTxHash - Hash of the Safe transaction
|
|
481
|
+
* @returns The information of a Safe transaction
|
|
482
|
+
* @throws "Invalid safeTxHash"
|
|
483
|
+
* @throws "Not found."
|
|
484
|
+
*/
|
|
485
|
+
async getTransaction(safeTxHash) {
|
|
486
|
+
if (safeTxHash === "") {
|
|
487
|
+
throw new Error("Invalid safeTxHash");
|
|
488
|
+
}
|
|
489
|
+
return sendRequest({
|
|
490
|
+
url: `${this.#txServiceBaseUrl}/v1/multisig-transactions/${safeTxHash}/`,
|
|
491
|
+
method: "get" /* Get */
|
|
492
|
+
});
|
|
493
|
+
}
|
|
494
|
+
/**
|
|
495
|
+
* Returns the list of confirmations for a given a Safe transaction.
|
|
496
|
+
*
|
|
497
|
+
* @param safeTxHash - The hash of the Safe transaction
|
|
498
|
+
* @returns The list of confirmations
|
|
499
|
+
* @throws "Invalid safeTxHash"
|
|
500
|
+
*/
|
|
501
|
+
async getTransactionConfirmations(safeTxHash) {
|
|
502
|
+
if (safeTxHash === "") {
|
|
503
|
+
throw new Error("Invalid safeTxHash");
|
|
504
|
+
}
|
|
505
|
+
return sendRequest({
|
|
506
|
+
url: `${this.#txServiceBaseUrl}/v1/multisig-transactions/${safeTxHash}/confirmations/`,
|
|
507
|
+
method: "get" /* Get */
|
|
508
|
+
});
|
|
509
|
+
}
|
|
510
|
+
/**
|
|
511
|
+
* Adds a confirmation for a Safe transaction.
|
|
512
|
+
*
|
|
513
|
+
* @param safeTxHash - Hash of the Safe transaction that will be confirmed
|
|
514
|
+
* @param signature - Signature of the transaction
|
|
515
|
+
* @returns
|
|
516
|
+
* @throws "Invalid safeTxHash"
|
|
517
|
+
* @throws "Invalid signature"
|
|
518
|
+
* @throws "Malformed data"
|
|
519
|
+
* @throws "Error processing data"
|
|
520
|
+
*/
|
|
521
|
+
async confirmTransaction(safeTxHash, signature) {
|
|
522
|
+
if (safeTxHash === "") {
|
|
523
|
+
throw new Error("Invalid safeTxHash");
|
|
524
|
+
}
|
|
525
|
+
if (signature === "") {
|
|
526
|
+
throw new Error("Invalid signature");
|
|
527
|
+
}
|
|
528
|
+
return sendRequest({
|
|
529
|
+
url: `${this.#txServiceBaseUrl}/v1/multisig-transactions/${safeTxHash}/confirmations/`,
|
|
530
|
+
method: "post" /* Post */,
|
|
531
|
+
body: {
|
|
532
|
+
signature
|
|
533
|
+
}
|
|
534
|
+
});
|
|
535
|
+
}
|
|
536
|
+
/**
|
|
537
|
+
* Returns the information and configuration of the provided Safe address.
|
|
538
|
+
*
|
|
539
|
+
* @param safeAddress - The Safe address
|
|
540
|
+
* @returns The information and configuration of the provided Safe address
|
|
541
|
+
* @throws "Invalid Safe address"
|
|
542
|
+
* @throws "Checksum address validation failed"
|
|
543
|
+
*/
|
|
544
|
+
async getSafeInfo(safeAddress) {
|
|
545
|
+
if (safeAddress === "") {
|
|
546
|
+
throw new Error("Invalid Safe address");
|
|
547
|
+
}
|
|
548
|
+
const { address } = this.#getEip3770Address(safeAddress);
|
|
549
|
+
return sendRequest({
|
|
550
|
+
url: `${this.#txServiceBaseUrl}/v1/safes/${address}/`,
|
|
551
|
+
method: "get" /* Get */
|
|
552
|
+
}).then((response) => {
|
|
553
|
+
if (!response?.singleton) {
|
|
554
|
+
const { masterCopy, ...rest } = response;
|
|
555
|
+
return { ...rest, singleton: masterCopy };
|
|
556
|
+
}
|
|
557
|
+
return response;
|
|
558
|
+
});
|
|
559
|
+
}
|
|
471
560
|
/**
|
|
472
561
|
* Returns the creation information of a Safe.
|
|
473
562
|
*
|
|
@@ -558,17 +647,20 @@ var SafeApiKit = class {
|
|
|
558
647
|
* Returns the history of incoming transactions of a Safe account.
|
|
559
648
|
*
|
|
560
649
|
* @param safeAddress - The Safe address
|
|
650
|
+
* @param options - Optional parameters to filter or modify the response
|
|
561
651
|
* @returns The history of incoming transactions
|
|
562
652
|
* @throws "Invalid Safe address"
|
|
563
653
|
* @throws "Checksum address validation failed"
|
|
564
654
|
*/
|
|
565
|
-
async getIncomingTransactions(safeAddress) {
|
|
655
|
+
async getIncomingTransactions(safeAddress, options) {
|
|
566
656
|
if (safeAddress === "") {
|
|
567
657
|
throw new Error("Invalid Safe address");
|
|
568
658
|
}
|
|
569
659
|
const { address } = this.#getEip3770Address(safeAddress);
|
|
660
|
+
const url = new URL(`${this.#txServiceBaseUrl}/v1/safes/${address}/incoming-transfers/`);
|
|
661
|
+
this.#addUrlQueryParams(url, options);
|
|
570
662
|
return sendRequest({
|
|
571
|
-
url:
|
|
663
|
+
url: url.toString(),
|
|
572
664
|
method: "get" /* Get */
|
|
573
665
|
});
|
|
574
666
|
}
|
|
@@ -576,18 +668,21 @@ var SafeApiKit = class {
|
|
|
576
668
|
* Returns the history of module transactions of a Safe account.
|
|
577
669
|
*
|
|
578
670
|
* @param safeAddress - The Safe address
|
|
671
|
+
* @param options - Optional parameters to filter or modify the response
|
|
579
672
|
* @returns The history of module transactions
|
|
580
673
|
* @throws "Invalid Safe address"
|
|
581
674
|
* @throws "Invalid data"
|
|
582
675
|
* @throws "Invalid ethereum address"
|
|
583
676
|
*/
|
|
584
|
-
async getModuleTransactions(safeAddress) {
|
|
677
|
+
async getModuleTransactions(safeAddress, options) {
|
|
585
678
|
if (safeAddress === "") {
|
|
586
679
|
throw new Error("Invalid Safe address");
|
|
587
680
|
}
|
|
588
681
|
const { address } = this.#getEip3770Address(safeAddress);
|
|
682
|
+
const url = new URL(`${this.#txServiceBaseUrl}/v1/safes/${address}/module-transactions/`);
|
|
683
|
+
this.#addUrlQueryParams(url, options);
|
|
589
684
|
return sendRequest({
|
|
590
|
-
url:
|
|
685
|
+
url: url.toString(),
|
|
591
686
|
method: "get" /* Get */
|
|
592
687
|
});
|
|
593
688
|
}
|
|
@@ -595,38 +690,38 @@ var SafeApiKit = class {
|
|
|
595
690
|
* Returns the history of multi-signature transactions of a Safe account.
|
|
596
691
|
*
|
|
597
692
|
* @param safeAddress - The Safe address
|
|
693
|
+
* @param options - Optional parameters to filter or modify the response
|
|
598
694
|
* @returns The history of multi-signature transactions
|
|
599
695
|
* @throws "Invalid Safe address"
|
|
600
696
|
* @throws "Checksum address validation failed"
|
|
601
697
|
*/
|
|
602
|
-
async getMultisigTransactions(safeAddress) {
|
|
698
|
+
async getMultisigTransactions(safeAddress, options) {
|
|
603
699
|
if (safeAddress === "") {
|
|
604
700
|
throw new Error("Invalid Safe address");
|
|
605
701
|
}
|
|
606
702
|
const { address } = this.#getEip3770Address(safeAddress);
|
|
703
|
+
const url = new URL(`${this.#txServiceBaseUrl}/v1/safes/${address}/multisig-transactions/`);
|
|
704
|
+
this.#addUrlQueryParams(url, options);
|
|
607
705
|
return sendRequest({
|
|
608
|
-
url:
|
|
706
|
+
url: url.toString(),
|
|
609
707
|
method: "get" /* Get */
|
|
610
708
|
});
|
|
611
709
|
}
|
|
612
|
-
|
|
710
|
+
/**
|
|
711
|
+
* Returns the list of multi-signature transactions that are waiting for the confirmation of the Safe owners.
|
|
712
|
+
*
|
|
713
|
+
* @param safeAddress - The Safe address
|
|
714
|
+
* @param {PendingTransactionsOptions} options The options to filter the list of transactions
|
|
715
|
+
* @returns The list of transactions waiting for the confirmation of the Safe owners
|
|
716
|
+
* @throws "Invalid Safe address"
|
|
717
|
+
* @throws "Invalid data"
|
|
718
|
+
* @throws "Invalid ethereum address"
|
|
719
|
+
*/
|
|
720
|
+
async getPendingTransactions(safeAddress, options = {}) {
|
|
613
721
|
if (safeAddress === "") {
|
|
614
722
|
throw new Error("Invalid Safe address");
|
|
615
723
|
}
|
|
616
|
-
|
|
617
|
-
let hasConfirmations;
|
|
618
|
-
let ordering;
|
|
619
|
-
let limit;
|
|
620
|
-
let offset;
|
|
621
|
-
if (typeof propsOrCurrentNonce === "object") {
|
|
622
|
-
;
|
|
623
|
-
({ currentNonce, hasConfirmations, ordering, limit, offset } = propsOrCurrentNonce);
|
|
624
|
-
} else {
|
|
625
|
-
console.warn(
|
|
626
|
-
"Deprecated: Use `currentNonce` inside an object instead. See `PendingTransactionsOptions`."
|
|
627
|
-
);
|
|
628
|
-
currentNonce = propsOrCurrentNonce;
|
|
629
|
-
}
|
|
724
|
+
const { currentNonce, hasConfirmations, ordering, limit, offset } = options;
|
|
630
725
|
const { address } = this.#getEip3770Address(safeAddress);
|
|
631
726
|
const nonce = currentNonce ? currentNonce : (await this.getSafeInfo(address)).nonce;
|
|
632
727
|
const url = new URL(
|
|
@@ -653,9 +748,11 @@ var SafeApiKit = class {
|
|
|
653
748
|
* Returns a list of transactions for a Safe. The list has different structures depending on the transaction type
|
|
654
749
|
*
|
|
655
750
|
* @param safeAddress - The Safe address
|
|
751
|
+
* @param options - Optional parameters to filter or modify the response
|
|
656
752
|
* @returns The list of transactions waiting for the confirmation of the Safe owners
|
|
657
753
|
* @throws "Invalid Safe address"
|
|
658
754
|
* @throws "Checksum address validation failed"
|
|
755
|
+
* @throws "Ordering field is not valid"
|
|
659
756
|
*/
|
|
660
757
|
async getAllTransactions(safeAddress, options) {
|
|
661
758
|
if (safeAddress === "") {
|
|
@@ -663,12 +760,7 @@ var SafeApiKit = class {
|
|
|
663
760
|
}
|
|
664
761
|
const { address } = this.#getEip3770Address(safeAddress);
|
|
665
762
|
const url = new URL(`${this.#txServiceBaseUrl}/v1/safes/${address}/all-transactions/`);
|
|
666
|
-
|
|
667
|
-
url.searchParams.set("trusted", trusted);
|
|
668
|
-
const queued = options?.queued?.toString() || "true";
|
|
669
|
-
url.searchParams.set("queued", queued);
|
|
670
|
-
const executed = options?.executed?.toString() || "false";
|
|
671
|
-
url.searchParams.set("executed", executed);
|
|
763
|
+
this.#addUrlQueryParams(url, options);
|
|
672
764
|
return sendRequest({
|
|
673
765
|
url: url.toString(),
|
|
674
766
|
method: "get" /* Get */
|
|
@@ -702,11 +794,14 @@ var SafeApiKit = class {
|
|
|
702
794
|
/**
|
|
703
795
|
* Returns the list of all the ERC20 tokens handled by the Safe.
|
|
704
796
|
*
|
|
797
|
+
* @param options - Optional parameters to filter or modify the response
|
|
705
798
|
* @returns The list of all the ERC20 tokens
|
|
706
799
|
*/
|
|
707
|
-
async getTokenList() {
|
|
800
|
+
async getTokenList(options) {
|
|
801
|
+
const url = new URL(`${this.#txServiceBaseUrl}/v1/tokens/`);
|
|
802
|
+
this.#addUrlQueryParams(url, options);
|
|
708
803
|
return sendRequest({
|
|
709
|
-
url:
|
|
804
|
+
url: url.toString(),
|
|
710
805
|
method: "get" /* Get */
|
|
711
806
|
});
|
|
712
807
|
}
|
|
@@ -728,113 +823,21 @@ var SafeApiKit = class {
|
|
|
728
823
|
method: "get" /* Get */
|
|
729
824
|
});
|
|
730
825
|
}
|
|
731
|
-
/**
|
|
732
|
-
* Get a message by its safe message hash
|
|
733
|
-
* @param messageHash The Safe message hash
|
|
734
|
-
* @returns The message
|
|
735
|
-
*/
|
|
736
|
-
async getMessage(messageHash) {
|
|
737
|
-
if (!messageHash) {
|
|
738
|
-
throw new Error("Invalid messageHash");
|
|
739
|
-
}
|
|
740
|
-
return sendRequest({
|
|
741
|
-
url: `${this.#txServiceBaseUrl}/v1/messages/${messageHash}/`,
|
|
742
|
-
method: "get" /* Get */
|
|
743
|
-
});
|
|
744
|
-
}
|
|
745
|
-
/**
|
|
746
|
-
* Get the list of messages associated to a Safe account
|
|
747
|
-
* @param safeAddress The safe address
|
|
748
|
-
* @param options The options to filter the list of messages
|
|
749
|
-
* @returns The paginated list of messages
|
|
750
|
-
*/
|
|
751
|
-
async getMessages(safeAddress, { ordering, limit, offset } = {}) {
|
|
752
|
-
if (!this.#isValidAddress(safeAddress)) {
|
|
753
|
-
throw new Error("Invalid safeAddress");
|
|
754
|
-
}
|
|
755
|
-
const url = new URL(`${this.#txServiceBaseUrl}/v1/safes/${safeAddress}/messages/`);
|
|
756
|
-
if (ordering) {
|
|
757
|
-
url.searchParams.set("ordering", ordering);
|
|
758
|
-
}
|
|
759
|
-
if (limit != null) {
|
|
760
|
-
url.searchParams.set("limit", limit.toString());
|
|
761
|
-
}
|
|
762
|
-
if (offset != null) {
|
|
763
|
-
url.searchParams.set("offset", offset.toString());
|
|
764
|
-
}
|
|
765
|
-
return sendRequest({
|
|
766
|
-
url: url.toString(),
|
|
767
|
-
method: "get" /* Get */
|
|
768
|
-
});
|
|
769
|
-
}
|
|
770
|
-
/**
|
|
771
|
-
* Creates a new message with an initial signature
|
|
772
|
-
* Add more signatures from other owners using addMessageSignature()
|
|
773
|
-
* @param safeAddress The safe address
|
|
774
|
-
* @param options The raw message to add, signature and safeAppId if any
|
|
775
|
-
*/
|
|
776
|
-
async addMessage(safeAddress, addMessageProps) {
|
|
777
|
-
if (!this.#isValidAddress(safeAddress)) {
|
|
778
|
-
throw new Error("Invalid safeAddress");
|
|
779
|
-
}
|
|
780
|
-
return sendRequest({
|
|
781
|
-
url: `${this.#txServiceBaseUrl}/v1/safes/${safeAddress}/messages/`,
|
|
782
|
-
method: "post" /* Post */,
|
|
783
|
-
body: addMessageProps
|
|
784
|
-
});
|
|
785
|
-
}
|
|
786
|
-
/**
|
|
787
|
-
* Add a signature to an existing message
|
|
788
|
-
* @param messageHash The safe message hash
|
|
789
|
-
* @param signature The signature
|
|
790
|
-
*/
|
|
791
|
-
async addMessageSignature(messageHash, signature) {
|
|
792
|
-
if (!messageHash || !signature) {
|
|
793
|
-
throw new Error("Invalid messageHash or signature");
|
|
794
|
-
}
|
|
795
|
-
return sendRequest({
|
|
796
|
-
url: `${this.#txServiceBaseUrl}/v1/messages/${messageHash}/signatures/`,
|
|
797
|
-
method: "post" /* Post */,
|
|
798
|
-
body: {
|
|
799
|
-
signature
|
|
800
|
-
}
|
|
801
|
-
});
|
|
802
|
-
}
|
|
803
826
|
/**
|
|
804
827
|
* Get the SafeOperations that were sent from a particular address.
|
|
805
|
-
* @param
|
|
828
|
+
* @param safeAddress - The Safe address
|
|
829
|
+
* @param options - Optional parameters to filter or modify the response
|
|
806
830
|
* @throws "Safe address must not be empty"
|
|
807
831
|
* @throws "Invalid Ethereum address {safeAddress}"
|
|
808
832
|
* @returns The SafeOperations sent from the given Safe's address
|
|
809
833
|
*/
|
|
810
|
-
async getSafeOperationsByAddress({
|
|
811
|
-
safeAddress,
|
|
812
|
-
executed,
|
|
813
|
-
hasConfirmations,
|
|
814
|
-
ordering,
|
|
815
|
-
limit,
|
|
816
|
-
offset
|
|
817
|
-
}) {
|
|
834
|
+
async getSafeOperationsByAddress(safeAddress, options) {
|
|
818
835
|
if (!safeAddress) {
|
|
819
836
|
throw new Error("Safe address must not be empty");
|
|
820
837
|
}
|
|
821
838
|
const { address } = this.#getEip3770Address(safeAddress);
|
|
822
839
|
const url = new URL(`${this.#txServiceBaseUrl}/v1/safes/${address}/safe-operations/`);
|
|
823
|
-
|
|
824
|
-
url.searchParams.set("ordering", ordering);
|
|
825
|
-
}
|
|
826
|
-
if (limit != null) {
|
|
827
|
-
url.searchParams.set("limit", limit.toString());
|
|
828
|
-
}
|
|
829
|
-
if (offset != null) {
|
|
830
|
-
url.searchParams.set("offset", offset.toString());
|
|
831
|
-
}
|
|
832
|
-
if (hasConfirmations != null) {
|
|
833
|
-
url.searchParams.set("has_confirmations", hasConfirmations.toString());
|
|
834
|
-
}
|
|
835
|
-
if (executed != null) {
|
|
836
|
-
url.searchParams.set("executed", executed.toString());
|
|
837
|
-
}
|
|
840
|
+
this.#addUrlQueryParams(url, options);
|
|
838
841
|
return sendRequest({
|
|
839
842
|
url: url.toString(),
|
|
840
843
|
method: "get" /* Get */
|
|
@@ -842,14 +845,15 @@ var SafeApiKit = class {
|
|
|
842
845
|
}
|
|
843
846
|
/**
|
|
844
847
|
* Get the SafeOperations that are pending to send to the bundler
|
|
845
|
-
* @param
|
|
848
|
+
* @param safeAddress - The Safe address
|
|
849
|
+
* @param options - Optional parameters to filter or modify the response
|
|
846
850
|
* @throws "Safe address must not be empty"
|
|
847
851
|
* @throws "Invalid Ethereum address {safeAddress}"
|
|
848
852
|
* @returns The pending SafeOperations
|
|
849
853
|
*/
|
|
850
|
-
async getPendingSafeOperations(
|
|
851
|
-
return this.getSafeOperationsByAddress({
|
|
852
|
-
...
|
|
854
|
+
async getPendingSafeOperations(safeAddress, options) {
|
|
855
|
+
return this.getSafeOperationsByAddress(safeAddress, {
|
|
856
|
+
...options,
|
|
853
857
|
executed: false
|
|
854
858
|
});
|
|
855
859
|
}
|