@safe-global/sdk-starter-kit 2.0.0-alpha.3 → 2.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/cjs/index.cjs
CHANGED
|
@@ -28,15 +28,15 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
29
|
|
|
30
30
|
// src/index.ts
|
|
31
|
-
var
|
|
32
|
-
__export(
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
33
|
SafeClient: () => SafeClient,
|
|
34
34
|
createSafeClient: () => createSafeClient,
|
|
35
35
|
offChainMessages: () => offChainMessages,
|
|
36
36
|
onChainMessages: () => onChainMessages,
|
|
37
37
|
safeOperations: () => safeOperations
|
|
38
38
|
});
|
|
39
|
-
module.exports = __toCommonJS(
|
|
39
|
+
module.exports = __toCommonJS(index_exports);
|
|
40
40
|
var import_protocol_kit6 = __toESM(require("@safe-global/protocol-kit"));
|
|
41
41
|
var import_api_kit = __toESM(require("@safe-global/api-kit"));
|
|
42
42
|
|
|
@@ -313,12 +313,23 @@ var SafeClient = class extends BaseClient {
|
|
|
313
313
|
* @throws {Error} If the transaction confirmation fails.
|
|
314
314
|
*/
|
|
315
315
|
async confirm({ safeTxHash }) {
|
|
316
|
-
let transactionResponse = await this.apiKit.getTransaction(safeTxHash);
|
|
317
316
|
const safeAddress = await this.protocolKit.getAddress();
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
317
|
+
let transactionResponse = await this.apiKit.getTransaction(safeTxHash);
|
|
318
|
+
if (transactionResponse.isExecuted) {
|
|
319
|
+
return createSafeClientResult({
|
|
320
|
+
status: "EXECUTED" /* EXECUTED */,
|
|
321
|
+
safeAddress,
|
|
322
|
+
txHash: transactionResponse.transactionHash || "",
|
|
323
|
+
safeTxHash
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
if (this.#needsConfirmation(transactionResponse)) {
|
|
327
|
+
const signedTransaction = await this.protocolKit.signTransaction(transactionResponse);
|
|
328
|
+
const signature = signedTransaction.encodedSignatures();
|
|
329
|
+
await this.apiKit.confirmTransaction(safeTxHash, signature);
|
|
330
|
+
transactionResponse = await this.apiKit.getTransaction(safeTxHash);
|
|
331
|
+
}
|
|
332
|
+
if (!this.#needsConfirmation(transactionResponse)) {
|
|
322
333
|
const executedTransactionResponse = await this.protocolKit.executeTransaction(transactionResponse);
|
|
323
334
|
await waitSafeTxReceipt(executedTransactionResponse);
|
|
324
335
|
return createSafeClientResult({
|
|
@@ -447,6 +458,9 @@ var SafeClient = class extends BaseClient {
|
|
|
447
458
|
safeTxHash
|
|
448
459
|
});
|
|
449
460
|
}
|
|
461
|
+
#needsConfirmation(transactionResponse) {
|
|
462
|
+
return (transactionResponse.confirmations?.length || 0) < transactionResponse.confirmationsRequired;
|
|
463
|
+
}
|
|
450
464
|
async #reconnectSafe() {
|
|
451
465
|
this.protocolKit = await this.protocolKit.connect({
|
|
452
466
|
provider: this.protocolKit.getSafeProvider().provider,
|
|
@@ -728,14 +742,23 @@ var SafeOperationClient = class {
|
|
|
728
742
|
}) {
|
|
729
743
|
const safeAddress = await this.protocolKit.getAddress();
|
|
730
744
|
const threshold = await this.protocolKit.getThreshold();
|
|
731
|
-
await this.apiKit.
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
745
|
+
let safeOperationResponse = await this.apiKit.getSafeOperation(safeOperationHash);
|
|
746
|
+
if (safeOperationResponse.userOperation?.ethereumTxHash) {
|
|
747
|
+
return createSafeClientResult({
|
|
748
|
+
status: "SAFE_OPERATION_EXECUTED" /* SAFE_OPERATION_EXECUTED */,
|
|
749
|
+
safeAddress,
|
|
750
|
+
userOperationHash: safeOperationResponse.userOperation.userOperationHash,
|
|
751
|
+
safeOperationHash
|
|
752
|
+
});
|
|
753
|
+
}
|
|
754
|
+
if (this.#needsConfirmation(safeOperationResponse, threshold)) {
|
|
755
|
+
const signature = (0, import_protocol_kit5.buildSignatureBytes)([await this.protocolKit.signHash(safeOperationHash)]);
|
|
756
|
+
await this.apiKit.confirmSafeOperation(safeOperationHash, signature);
|
|
757
|
+
safeOperationResponse = await this.apiKit.getSafeOperation(safeOperationHash);
|
|
758
|
+
}
|
|
759
|
+
if (!this.#needsConfirmation(safeOperationResponse, threshold)) {
|
|
737
760
|
const userOperationHash = await this.safe4337Pack.executeTransaction({
|
|
738
|
-
executable:
|
|
761
|
+
executable: safeOperationResponse
|
|
739
762
|
});
|
|
740
763
|
await this.#waitForOperationToFinish({ userOperationHash });
|
|
741
764
|
return createSafeClientResult({
|
|
@@ -763,6 +786,9 @@ var SafeOperationClient = class {
|
|
|
763
786
|
const safeAddress = await this.protocolKit.getAddress();
|
|
764
787
|
return this.apiKit.getPendingSafeOperations(safeAddress, options);
|
|
765
788
|
}
|
|
789
|
+
#needsConfirmation(safeOperationResponse, threshold) {
|
|
790
|
+
return (safeOperationResponse.confirmations?.length || 0) < threshold;
|
|
791
|
+
}
|
|
766
792
|
/**
|
|
767
793
|
* Helper method to wait for the operation to finish
|
|
768
794
|
* @param userOperationHash The userOperationHash to wait for. This comes from the bundler and can be obtained from the
|
package/dist/esm/index.mjs
CHANGED
|
@@ -275,12 +275,23 @@ var SafeClient = class extends BaseClient {
|
|
|
275
275
|
* @throws {Error} If the transaction confirmation fails.
|
|
276
276
|
*/
|
|
277
277
|
async confirm({ safeTxHash }) {
|
|
278
|
-
let transactionResponse = await this.apiKit.getTransaction(safeTxHash);
|
|
279
278
|
const safeAddress = await this.protocolKit.getAddress();
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
279
|
+
let transactionResponse = await this.apiKit.getTransaction(safeTxHash);
|
|
280
|
+
if (transactionResponse.isExecuted) {
|
|
281
|
+
return createSafeClientResult({
|
|
282
|
+
status: "EXECUTED" /* EXECUTED */,
|
|
283
|
+
safeAddress,
|
|
284
|
+
txHash: transactionResponse.transactionHash || "",
|
|
285
|
+
safeTxHash
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
if (this.#needsConfirmation(transactionResponse)) {
|
|
289
|
+
const signedTransaction = await this.protocolKit.signTransaction(transactionResponse);
|
|
290
|
+
const signature = signedTransaction.encodedSignatures();
|
|
291
|
+
await this.apiKit.confirmTransaction(safeTxHash, signature);
|
|
292
|
+
transactionResponse = await this.apiKit.getTransaction(safeTxHash);
|
|
293
|
+
}
|
|
294
|
+
if (!this.#needsConfirmation(transactionResponse)) {
|
|
284
295
|
const executedTransactionResponse = await this.protocolKit.executeTransaction(transactionResponse);
|
|
285
296
|
await waitSafeTxReceipt(executedTransactionResponse);
|
|
286
297
|
return createSafeClientResult({
|
|
@@ -409,6 +420,9 @@ var SafeClient = class extends BaseClient {
|
|
|
409
420
|
safeTxHash
|
|
410
421
|
});
|
|
411
422
|
}
|
|
423
|
+
#needsConfirmation(transactionResponse) {
|
|
424
|
+
return (transactionResponse.confirmations?.length || 0) < transactionResponse.confirmationsRequired;
|
|
425
|
+
}
|
|
412
426
|
async #reconnectSafe() {
|
|
413
427
|
this.protocolKit = await this.protocolKit.connect({
|
|
414
428
|
provider: this.protocolKit.getSafeProvider().provider,
|
|
@@ -690,14 +704,23 @@ var SafeOperationClient = class {
|
|
|
690
704
|
}) {
|
|
691
705
|
const safeAddress = await this.protocolKit.getAddress();
|
|
692
706
|
const threshold = await this.protocolKit.getThreshold();
|
|
693
|
-
await this.apiKit.
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
707
|
+
let safeOperationResponse = await this.apiKit.getSafeOperation(safeOperationHash);
|
|
708
|
+
if (safeOperationResponse.userOperation?.ethereumTxHash) {
|
|
709
|
+
return createSafeClientResult({
|
|
710
|
+
status: "SAFE_OPERATION_EXECUTED" /* SAFE_OPERATION_EXECUTED */,
|
|
711
|
+
safeAddress,
|
|
712
|
+
userOperationHash: safeOperationResponse.userOperation.userOperationHash,
|
|
713
|
+
safeOperationHash
|
|
714
|
+
});
|
|
715
|
+
}
|
|
716
|
+
if (this.#needsConfirmation(safeOperationResponse, threshold)) {
|
|
717
|
+
const signature = buildSignatureBytes2([await this.protocolKit.signHash(safeOperationHash)]);
|
|
718
|
+
await this.apiKit.confirmSafeOperation(safeOperationHash, signature);
|
|
719
|
+
safeOperationResponse = await this.apiKit.getSafeOperation(safeOperationHash);
|
|
720
|
+
}
|
|
721
|
+
if (!this.#needsConfirmation(safeOperationResponse, threshold)) {
|
|
699
722
|
const userOperationHash = await this.safe4337Pack.executeTransaction({
|
|
700
|
-
executable:
|
|
723
|
+
executable: safeOperationResponse
|
|
701
724
|
});
|
|
702
725
|
await this.#waitForOperationToFinish({ userOperationHash });
|
|
703
726
|
return createSafeClientResult({
|
|
@@ -725,6 +748,9 @@ var SafeOperationClient = class {
|
|
|
725
748
|
const safeAddress = await this.protocolKit.getAddress();
|
|
726
749
|
return this.apiKit.getPendingSafeOperations(safeAddress, options);
|
|
727
750
|
}
|
|
751
|
+
#needsConfirmation(safeOperationResponse, threshold) {
|
|
752
|
+
return (safeOperationResponse.confirmations?.length || 0) < threshold;
|
|
753
|
+
}
|
|
728
754
|
/**
|
|
729
755
|
* Helper method to wait for the operation to finish
|
|
730
756
|
* @param userOperationHash The userOperationHash to wait for. This comes from the bundler and can be obtained from the
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SafeClient.d.ts","sourceRoot":"","sources":["../../src/SafeClient.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,2BAA2B,CAAA;AAC5C,OAAO,UAAU,EAAE,EAAE,mCAAmC,EAAE,MAAM,sBAAsB,CAAA;
|
|
1
|
+
{"version":3,"file":"SafeClient.d.ts","sourceRoot":"","sources":["../../src/SafeClient.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,2BAA2B,CAAA;AAC5C,OAAO,UAAU,EAAE,EAAE,mCAAmC,EAAE,MAAM,sBAAsB,CAAA;AAetF,OAAO,EACL,uBAAuB,EACvB,gBAAgB,EAChB,oBAAoB,EACrB,MAAM,oCAAoC,CAAA;AAE3C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAEzC;;;;;;;;;;GAUG;AACH,qBAAa,UAAW,SAAQ,UAAU;;gBAC5B,WAAW,EAAE,IAAI,EAAE,MAAM,EAAE,UAAU;IAIjD;;;;;;;;;;;;;;;;OAgBG;IACG,IAAI,CAAC,EACT,YAAY,EACZ,GAAG,kBAAkB,EACtB,EAAE,oBAAoB,GAAG,OAAO,CAAC,gBAAgB,CAAC;IA2BnD;;;;;;;OAOG;IACG,OAAO,CAAC,EAAE,UAAU,EAAE,EAAE,uBAAuB,GAAG,OAAO,CAAC,gBAAgB,CAAC;IA2CjF;;;;;;OAMG;IACG,sBAAsB,IAAI,OAAO,CAAC,mCAAmC,CAAC;IAM5E;;;;;OAKG;IACH,MAAM,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,MAAM,EAAE,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,GAAG,CAAC,CAAC;IACtE,MAAM,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,MAAM,EAAE,IAAI,KAAK,CAAC,GAAG,IAAI,GAAG,CAAC;CAuIrD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SafeOperationClient.d.ts","sourceRoot":"","sources":["../../../../src/extensions/safe-operations/SafeOperationClient.ts"],"names":[],"mappings":"AAAA,OAAO,IAA6B,MAAM,2BAA2B,CAAA;AACrE,OAAO,UAAU,EAAE,EAAE,WAAW,EAAE,4BAA4B,EAAE,MAAM,sBAAsB,CAAA;AAC5F,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAA;AAIrD,OAAO,EACL,yBAAyB,EACzB,gBAAgB,EAChB,sBAAsB,EACvB,MAAM,oCAAoC,CAAA;
|
|
1
|
+
{"version":3,"file":"SafeOperationClient.d.ts","sourceRoot":"","sources":["../../../../src/extensions/safe-operations/SafeOperationClient.ts"],"names":[],"mappings":"AAAA,OAAO,IAA6B,MAAM,2BAA2B,CAAA;AACrE,OAAO,UAAU,EAAE,EAAE,WAAW,EAAE,4BAA4B,EAAE,MAAM,sBAAsB,CAAA;AAC5F,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAA;AAIrD,OAAO,EACL,yBAAyB,EACzB,gBAAgB,EAChB,sBAAsB,EACvB,MAAM,oCAAoC,CAAA;AAG3C;;;;GAIG;AACH,qBAAa,mBAAmB;;IAC9B,WAAW,EAAE,IAAI,CAAA;IACjB,MAAM,EAAE,UAAU,CAAA;IAClB,YAAY,EAAE,YAAY,CAAA;gBAEd,YAAY,EAAE,YAAY,EAAE,MAAM,EAAE,UAAU;IAM1D;;;;;;;;;;;;;;OAcG;IACG,iBAAiB,CAAC,EACtB,YAAY,EACZ,GAAG,wBAAwB,EAC5B,EAAE,sBAAsB,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAoCrD;;;;;;;;OAQG;IACG,oBAAoB,CAAC,EACzB,iBAAiB,EAClB,EAAE,yBAAyB,GAAG,OAAO,CAAC,gBAAgB,CAAC;IA4CxD;;;;;;;OAOG;IACG,wBAAwB,CAAC,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,4BAA4B,CAAC;CA0B7F"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@safe-global/sdk-starter-kit",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "SDK that provides the basic tools to interact with the Safe Smart Account.",
|
|
5
5
|
"types": "dist/src/index.d.ts",
|
|
6
6
|
"main": "dist/cjs/index.cjs",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"SDK"
|
|
20
20
|
],
|
|
21
21
|
"scripts": {
|
|
22
|
-
"unbuild": "rimraf dist",
|
|
22
|
+
"unbuild": "rimraf dist coverage",
|
|
23
23
|
"build": "yarn unbuild && yarn build:esm && yarn build:cjs && yarn build:types",
|
|
24
24
|
"build:esm": "esbuild ./src/index --format=esm --bundle --packages=external --outdir=dist/esm --out-extension:.js=.mjs",
|
|
25
25
|
"build:cjs": "esbuild ./src/index --format=cjs --bundle --packages=external --outdir=dist/cjs --out-extension:.js=.cjs",
|
|
@@ -45,10 +45,10 @@
|
|
|
45
45
|
"access": "public"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@safe-global/api-kit": "^3.0.
|
|
49
|
-
"@safe-global/protocol-kit": "^6.0.
|
|
50
|
-
"@safe-global/relay-kit": "^4.0.
|
|
51
|
-
"@safe-global/types-kit": "^2.0.0
|
|
48
|
+
"@safe-global/api-kit": "^3.0.1",
|
|
49
|
+
"@safe-global/protocol-kit": "^6.0.1",
|
|
50
|
+
"@safe-global/relay-kit": "^4.0.1",
|
|
51
|
+
"@safe-global/types-kit": "^2.0.0",
|
|
52
52
|
"viem": "^2.21.8"
|
|
53
53
|
}
|
|
54
54
|
}
|