@safe-global/sdk-starter-kit 1.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 (45) hide show
  1. package/README.md +35 -0
  2. package/dist/src/BaseClient.d.ts +82 -0
  3. package/dist/src/BaseClient.js +123 -0
  4. package/dist/src/BaseClient.js.map +1 -0
  5. package/dist/src/SafeClient.d.ts +62 -0
  6. package/dist/src/SafeClient.js +215 -0
  7. package/dist/src/SafeClient.js.map +1 -0
  8. package/dist/src/constants.d.ts +24 -0
  9. package/dist/src/constants.js +36 -0
  10. package/dist/src/constants.js.map +1 -0
  11. package/dist/src/extensions/index.d.ts +3 -0
  12. package/dist/src/extensions/index.js +20 -0
  13. package/dist/src/extensions/index.js.map +1 -0
  14. package/dist/src/extensions/messages/SafeMessageClient.d.ts +41 -0
  15. package/dist/src/extensions/messages/SafeMessageClient.js +161 -0
  16. package/dist/src/extensions/messages/SafeMessageClient.js.map +1 -0
  17. package/dist/src/extensions/messages/offChainMessages.d.ts +38 -0
  18. package/dist/src/extensions/messages/offChainMessages.js +52 -0
  19. package/dist/src/extensions/messages/offChainMessages.js.map +1 -0
  20. package/dist/src/extensions/messages/onChainMessages.d.ts +28 -0
  21. package/dist/src/extensions/messages/onChainMessages.js +48 -0
  22. package/dist/src/extensions/messages/onChainMessages.js.map +1 -0
  23. package/dist/src/extensions/safe-operations/SafeOperationClient.d.ts +51 -0
  24. package/dist/src/extensions/safe-operations/SafeOperationClient.js +127 -0
  25. package/dist/src/extensions/safe-operations/SafeOperationClient.js.map +1 -0
  26. package/dist/src/extensions/safe-operations/safeOperations.d.ts +49 -0
  27. package/dist/src/extensions/safe-operations/safeOperations.js +85 -0
  28. package/dist/src/extensions/safe-operations/safeOperations.js.map +1 -0
  29. package/dist/src/index.d.ts +12 -0
  30. package/dist/src/index.js +92 -0
  31. package/dist/src/index.js.map +1 -0
  32. package/dist/src/types.d.ts +69 -0
  33. package/dist/src/types.js +3 -0
  34. package/dist/src/types.js.map +1 -0
  35. package/dist/src/utils/index.d.ts +19 -0
  36. package/dist/src/utils/index.js +57 -0
  37. package/dist/src/utils/index.js.map +1 -0
  38. package/dist/src/utils/proposeTransaction.d.ts +16 -0
  39. package/dist/src/utils/proposeTransaction.js +29 -0
  40. package/dist/src/utils/proposeTransaction.js.map +1 -0
  41. package/dist/src/utils/sendTransaction.d.ts +14 -0
  42. package/dist/src/utils/sendTransaction.js +28 -0
  43. package/dist/src/utils/sendTransaction.js.map +1 -0
  44. package/dist/tsconfig.build.tsbuildinfo +1 -0
  45. package/package.json +45 -0
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.safeOperations = void 0;
4
+ const relay_kit_1 = require("@safe-global/relay-kit");
5
+ const SafeOperationClient_1 = require("../../extensions/safe-operations/SafeOperationClient");
6
+ /**
7
+ * Extend the SafeClient with the ability to use a bundler and a paymaster
8
+ *
9
+ * @example
10
+ * const safeClient = await createSafeClient({ ... })
11
+ *
12
+ * const safeOperationClient = await safeClient.extend(
13
+ * safeOperations({ ... }, { ... })
14
+ * )
15
+ *
16
+ * const { safeOperations } = await safeOperationClient.sendSafeOperation({ transactions })
17
+ * await safeOperationClient.confirmSafeOperation({ safeOperationHash: safeOperations?.safeOperationHash})
18
+ */
19
+ function safeOperations({ bundlerUrl }, paymasterOptions) {
20
+ return async (client) => {
21
+ const { provider, signer } = client.protocolKit.getSafeProvider();
22
+ const isSafeDeployed = await client.protocolKit.isSafeDeployed();
23
+ let options;
24
+ if (isSafeDeployed) {
25
+ const safeAddress = await client.protocolKit.getAddress();
26
+ options = {
27
+ safeAddress
28
+ };
29
+ }
30
+ else {
31
+ const { safeDeploymentConfig, safeAccountConfig } = client.protocolKit.getPredictedSafe();
32
+ options = {
33
+ owners: safeAccountConfig.owners,
34
+ threshold: safeAccountConfig.threshold,
35
+ ...safeDeploymentConfig
36
+ };
37
+ }
38
+ const safe4337Pack = await relay_kit_1.Safe4337Pack.init({
39
+ provider,
40
+ signer,
41
+ bundlerUrl,
42
+ options,
43
+ paymasterOptions
44
+ });
45
+ client.protocolKit = safe4337Pack.protocolKit;
46
+ const safeOperationClient = new SafeOperationClient_1.SafeOperationClient(safe4337Pack, client.apiKit);
47
+ return {
48
+ /**
49
+ * Send SafeOperations from a group of transactions.
50
+ * This method will convert your transactions in a batch and:
51
+ * - If the threshold > 1 it will save for later the SafeOperation using the Transaction service
52
+ * You must confirmSafeOperation() with other owners
53
+ * - If the threshold = 1 the SafeOperation can be submitted to the bundler so it will execute it immediately
54
+ *
55
+ * @param {Safe4337CreateTransactionProps} props The Safe4337CreateTransactionProps object
56
+ * @returns {Promise<SafeClientResult>} A promise that resolves with the status of the SafeOperation
57
+ */
58
+ async sendSafeOperation(props) {
59
+ return safeOperationClient.sendSafeOperation(props);
60
+ },
61
+ /**
62
+ * Confirms the stored safeOperation
63
+ *
64
+ * @param {ConfirmSafeOperationProps} props The ConfirmSafeOperationProps object
65
+ * @returns {Promise<SafeClientResult>} A promise that resolves to the result of the safeOperation.
66
+ */
67
+ async confirmSafeOperation(props) {
68
+ return safeOperationClient.confirmSafeOperation(props);
69
+ },
70
+ /**
71
+ * Retrieves the pending Safe operations for the current Safe account
72
+ *
73
+ * @async
74
+ * @param {ListOptions} options The pagination options
75
+ * @returns {Promise<GetSafeOperationListResponse>} A promise that resolves to an array of pending Safe operations.
76
+ * @throws {Error} If there is an issue retrieving the safe address or pending Safe operations.
77
+ */
78
+ async getPendingSafeOperations(options) {
79
+ return safeOperationClient.getPendingSafeOperations(options);
80
+ }
81
+ };
82
+ };
83
+ }
84
+ exports.safeOperations = safeOperations;
85
+ //# sourceMappingURL=safeOperations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"safeOperations.js","sourceRoot":"","sources":["../../../../src/extensions/safe-operations/safeOperations.ts"],"names":[],"mappings":";;;AAEA,sDAAuE;AAGvE,qHAAiH;AAWjH;;;;;;;;;;;;GAYG;AACH,S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xD,CAAC;YACD;;;;;;;eAOG;YACH,KAAK,CAAC,wBAAwB,CAAC,OAAqB;gBAClD,OAAO,mBAAmB,CAAC,wBAAwB,CAAC,OAAO,CAAC,CAAA;YAC9D,CAAC;SACF,CAAA;IACH,CAAC,CAAA;AACH,CAAC;AA1ED,wCA0EC"}
@@ -0,0 +1,12 @@
1
+ import { SafeClient } from './SafeClient';
2
+ import { SdkStarterKitConfig } from './types';
3
+ /**
4
+ * Initializes a Safe client with the given configuration options.
5
+ *
6
+ * @param config - The Safe client configuration options.
7
+ * @returns A Safe client instance.
8
+ */
9
+ export declare function createSafeClient(config: SdkStarterKitConfig): Promise<SafeClient>;
10
+ export * from './types';
11
+ export * from './extensions';
12
+ export * from './SafeClient';
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ var __importDefault = (this && this.__importDefault) || function (mod) {
17
+ return (mod && mod.__esModule) ? mod : { "default": mod };
18
+ };
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ exports.createSafeClient = void 0;
21
+ const protocol_kit_1 = __importDefault(require("@safe-global/protocol-kit"));
22
+ const api_kit_1 = __importDefault(require("@safe-global/api-kit"));
23
+ const SafeClient_1 = require("./SafeClient");
24
+ const utils_1 = require("./utils");
25
+ /**
26
+ * Initializes a Safe client with the given configuration options.
27
+ *
28
+ * @param config - The Safe client configuration options.
29
+ * @returns A Safe client instance.
30
+ */
31
+ async function createSafeClient(config) {
32
+ const protocolKit = await getProtocolKitInstance(config);
33
+ const apiKit = await getApiKitInstance(protocolKit);
34
+ if (!protocolKit || !apiKit)
35
+ throw new Error('Failed to create a kit instances');
36
+ return new SafeClient_1.SafeClient(protocolKit, apiKit);
37
+ }
38
+ exports.createSafeClient = createSafeClient;
39
+ /**
40
+ * Get the Safe protocol kit instance.
41
+ *
42
+ * @param config - The SDK Starter kit configuration options.
43
+ * @returns A protocolKit instance.
44
+ */
45
+ async function getProtocolKitInstance(config) {
46
+ if (config.safeAddress && (0, utils_1.isValidAddress)(config.safeAddress)) {
47
+ // If the safe already exist
48
+ return protocol_kit_1.default.init({
49
+ provider: config.provider,
50
+ signer: config.signer,
51
+ safeAddress: config.safeAddress
52
+ });
53
+ }
54
+ else if (config.safeOptions && (0, utils_1.isValidSafeConfig)(config.safeOptions)) {
55
+ // If the safe does not exist and the configuration is provided
56
+ const protocolKit = await protocol_kit_1.default.init({
57
+ provider: config.provider,
58
+ signer: config.signer,
59
+ predictedSafe: {
60
+ safeAccountConfig: {
61
+ owners: config.safeOptions.owners,
62
+ threshold: config.safeOptions.threshold
63
+ },
64
+ safeDeploymentConfig: {
65
+ saltNonce: config.safeOptions.saltNonce
66
+ }
67
+ }
68
+ });
69
+ const isSafeDeployed = await protocolKit.isSafeDeployed();
70
+ // When the safe is deployed, which can be true given the predicted safe address based on the options,
71
+ // we need to re-initialize the Safe client with the safeAddress
72
+ if (isSafeDeployed) {
73
+ return protocol_kit_1.default.init({
74
+ provider: config.provider,
75
+ signer: config.signer,
76
+ safeAddress: await protocolKit.getAddress()
77
+ });
78
+ }
79
+ return protocolKit;
80
+ }
81
+ else {
82
+ throw new Error('Invalid configuration: either a valid safeAddress or valid safeOptions must be provided.');
83
+ }
84
+ }
85
+ async function getApiKitInstance(protocolKit) {
86
+ const chainId = await protocolKit.getChainId();
87
+ return new api_kit_1.default({ chainId });
88
+ }
89
+ __exportStar(require("./types"), exports);
90
+ __exportStar(require("./extensions"), exports);
91
+ __exportStar(require("./SafeClient"), exports);
92
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,6EAA4C;AAC5C,mEAA6C;AAE7C,wEAAoE;AACpE,8DAAsF;AAGtF;;;;;GAKG;AACI,KAAK,UAAU,gBAAgB,CAAC,MAA2B;IAChE,MAAM,WAAW,GAAG,MAAM,sBAAsB,CAAC,MAAM,CAAC,CAAA;IACxD,MAAM,MAAM,GAAG,MAAM,iBAAiB,CAAC,WAAW,CAAC,CAAA;IAEnD,IAAI,CAAC,WAAW,IAAI,CAAC,MAAM;QAAE,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAA;IAEhF,OAAO,IAAI,uBAAU,CAAC,WAAW,EAAE,MAAM,CAAC,CAAA;AAC5C,CAAC;AAPD,4CAOC;AAED;;;;;GAKG;AACH,KAAK,UAAU,sBAAsB,CAAC,MAA2B;IAC/D,IAAI,MAAM,CAAC,WAAW,IAAI,IAAA,sBAAc,EAAC,MAAM,CAAC,WAAW,CAAC,EAAE,CAAC;QAC7D,4BAA4B;QAC5B,OAAO,sBAAI,CAAC,IAAI,CAAC;YACf,QAAQ,EAAE,MAAM,CAAC,QAAQ;YACzB,MAAM,EAAE,MAAM,CAAC,MAAM;YACrB,WAAW,EAAE,MAAM,CAAC,WAAW;SAChC,CAAC,CAAA;IACJ,CAAC;SAAM,IAAI,MAAM,CAAC,WAAW,IAAI,IAAA,yBAAiB,EAAC,MAAM,CAAC,WAAW,CAAC,EAAE,CAAC;QACvE,+DAA+D;QAC/D,MAAM,WAAW,GAAG,MAAM,sBAAI,CAAC,IAAI,CAAC;YAClC,QAAQ,EAAE,MAAM,CAAC,QAAQ;YACzB,MAAM,EAAE,MAAM,CAAC,MAAM;YACrB,aAAa,EAAE;gBACb,iBAAiB,EAAE;oBACjB,MAAM,EAAE,MAAM,CAAC,WAAW,CAAC,MAAM;oBACjC,SAAS,EAAE,MAAM,CAAC,WAAW,CAAC,SAAS;iBACxC;gBACD,oBAAoB,EAAE;oBACpB,SAAS,EAAE,MAAM,CAAC,WAAW,CAAC,SAAS;iBACxC;aACF;SACF,CAAC,CAAA;QAEF,MAAM,cAAc,GAAG,MAAM,WAAW,CAAC,cAAc,EAAE,CAAA;QAEzD,sGAAsG;QACtG,gEAAgE;QAChE,IAAI,cAAc,EAAE,CAAC;YACnB,OAAO,sBAAI,CAAC,IAAI,CAAC;gBACf,QAAQ,EAAE,MAAM,CAAC,QAAQ;gBACzB,MAAM,EAAE,MAAM,CAAC,MAAM;gBACrB,WAAW,EAAE,MAAM,WAAW,CAAC,UAAU,EAAE;aAC5C,CAAC,CAAA;QACJ,CAAC;QAED,OAAO,WAAW,CAAA;IACpB,CAAC;SAAM,CAAC;QACN,MAAM,IAAI,KAAK,CACb,0FAA0F,CAC3F,CAAA;IACH,CAAC;AACH,CAAC;AAED,KAAK,UAAU,iBAAiB,CAAC,WAAiB;IAChD,MAAM,OAAO,GAAG,MAAM,WAAW,CAAC,UAAU,EAAE,CAAA;IAE9C,OAAO,IAAI,iBAAU,CAAC,EAAE,OAAO,EAAE,CAAC,CAAA;AACpC,CAAC;AAED,0CAAuB;AACvB,+CAA4B;AAC5B,+CAA4B"}
@@ -0,0 +1,69 @@
1
+ import { SafeProvider } from '@safe-global/protocol-kit';
2
+ import { TransactionBase, TransactionOptions, EIP712TypedData, MetaTransactionData } from '@safe-global/types-kit';
3
+ import { IFeeEstimator } from '@safe-global/relay-kit';
4
+ import { SafeClientTxStatus } from './constants';
5
+ export type SendTransactionProps = {
6
+ transactions: TransactionBase[];
7
+ } & TransactionOptions;
8
+ export type ConfirmTransactionProps = {
9
+ safeTxHash: string;
10
+ };
11
+ export type SendOnChainMessageProps = {
12
+ message: string | EIP712TypedData;
13
+ } & TransactionOptions;
14
+ export type SendOffChainMessageProps = {
15
+ message: string | EIP712TypedData;
16
+ };
17
+ export type ConfirmOffChainMessageProps = {
18
+ messageHash: string;
19
+ };
20
+ export type SendSafeOperationProps = {
21
+ transactions: MetaTransactionData[];
22
+ amountToApprove?: bigint;
23
+ validUntil?: number;
24
+ validAfter?: number;
25
+ feeEstimator?: IFeeEstimator;
26
+ };
27
+ export type ConfirmSafeOperationProps = {
28
+ safeOperationHash: string;
29
+ };
30
+ export type SafeConfig = {
31
+ owners: string[];
32
+ threshold: number;
33
+ saltNonce?: string;
34
+ };
35
+ export type ExistingSafeConfig = {
36
+ safeAddress?: string;
37
+ safeOptions?: never;
38
+ };
39
+ export type PredictedSafeConfig = {
40
+ safeAddress?: never;
41
+ safeOptions?: SafeConfig;
42
+ };
43
+ export type SdkStarterKitRootConfig = {
44
+ provider: SafeProvider['provider'];
45
+ signer?: SafeProvider['signer'];
46
+ };
47
+ export type SdkStarterKitConfig = SdkStarterKitRootConfig & (ExistingSafeConfig | PredictedSafeConfig);
48
+ export type SafeClientResult = {
49
+ safeAddress: string;
50
+ description: string;
51
+ status: SafeClientTxStatus;
52
+ transactions?: {
53
+ safeTxHash?: string;
54
+ ethereumTxHash?: string;
55
+ };
56
+ messages?: {
57
+ messageHash?: string;
58
+ };
59
+ safeOperations?: {
60
+ userOperationHash?: string;
61
+ safeOperationHash?: string;
62
+ };
63
+ safeAccountDeployment?: {
64
+ ethereumTxHash?: string;
65
+ };
66
+ };
67
+ export type ChangeThresholdTxParams = {
68
+ threshold: number;
69
+ };
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,19 @@
1
+ import { TransactionResult } from '@safe-global/types-kit';
2
+ import { GetTransactionReceiptReturnType } from 'viem';
3
+ import { SafeClientTxStatus } from '../constants';
4
+ import { SafeClientResult, SafeConfig } from '../types';
5
+ export declare const isValidAddress: (address: string) => boolean;
6
+ export declare const isValidSafeConfig: (config: SafeConfig) => boolean;
7
+ export declare const waitSafeTxReceipt: (txResult: TransactionResult) => Promise<GetTransactionReceiptReturnType | null | undefined>;
8
+ export declare const createSafeClientResult: ({ status, safeAddress, deploymentTxHash, safeTxHash, txHash, messageHash, userOperationHash, safeOperationHash }: {
9
+ status: SafeClientTxStatus;
10
+ safeAddress: string;
11
+ deploymentTxHash?: string | undefined;
12
+ safeTxHash?: string | undefined;
13
+ txHash?: string | undefined;
14
+ messageHash?: string | undefined;
15
+ userOperationHash?: string | undefined;
16
+ safeOperationHash?: string | undefined;
17
+ }) => SafeClientResult;
18
+ export * from './sendTransaction';
19
+ export * from './proposeTransaction';
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.createSafeClientResult = exports.waitSafeTxReceipt = exports.isValidSafeConfig = exports.isValidAddress = void 0;
18
+ const protocol_kit_1 = require("@safe-global/protocol-kit");
19
+ const constants_1 = require("../constants");
20
+ const isValidAddress = (address) => {
21
+ try {
22
+ (0, protocol_kit_1.validateEthereumAddress)(address);
23
+ return true;
24
+ }
25
+ catch {
26
+ return false;
27
+ }
28
+ };
29
+ exports.isValidAddress = isValidAddress;
30
+ const isValidSafeConfig = (config) => {
31
+ if (!config.owners || !config.threshold)
32
+ return false;
33
+ return true;
34
+ };
35
+ exports.isValidSafeConfig = isValidSafeConfig;
36
+ const waitSafeTxReceipt = async (txResult) => {
37
+ const receipt = txResult.transactionResponse
38
+ ? await txResult.transactionResponse.wait()
39
+ : undefined;
40
+ return receipt;
41
+ };
42
+ exports.waitSafeTxReceipt = waitSafeTxReceipt;
43
+ const createSafeClientResult = ({ status, safeAddress, deploymentTxHash, safeTxHash, txHash, messageHash, userOperationHash, safeOperationHash }) => {
44
+ return {
45
+ safeAddress,
46
+ description: constants_1.MESSAGES[status],
47
+ status,
48
+ transactions: txHash || safeTxHash ? { ethereumTxHash: txHash, safeTxHash } : undefined,
49
+ messages: messageHash ? { messageHash } : undefined,
50
+ safeOperations: userOperationHash || safeOperationHash ? { userOperationHash, safeOperationHash } : undefined,
51
+ safeAccountDeployment: deploymentTxHash ? { ethereumTxHash: deploymentTxHash } : undefined
52
+ };
53
+ };
54
+ exports.createSafeClientResult = createSafeClientResult;
55
+ __exportStar(require("./sendTransaction"), exports);
56
+ __exportStar(require("./proposeTransaction"), exports);
57
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,4DAAmE;AAInE,sEAAqF;AAG9E,MAAM,cAAc,GAAG,CAAC,OAAe,EAAW,EAAE;IACzD,IAAI,CAAC;QACH,IAAA,sCAAuB,EAAC,OAAO,CAAC,CAAA;QAChC,OAAO,IAAI,CAAA;IACb,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAA;IACd,CAAC;AACH,CAAC,CAAA;AAPY,QAAA,cAAc,kBAO1B;AAEM,MAAM,iBAAiB,GAAG,CAAC,MAAkB,EAAW,EAAE;IAC/D,IAAI,CAAC,MAAM,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+ import { SafeTransaction } from '@safe-global/types-kit';
4
+ /**
5
+ * Propose a transaction to the Safe
6
+ *
7
+ * @param {SafeTransaction} safeTransaction The Safe transaction to propose
8
+ * @param {Safe} protocolKit The Safe instance
9
+ * @param {SafeApiKit} apiKit The SafeApiKit instance
10
+ * @returns The Safe transaction hash
11
+ */
12
+ export declare const proposeTransaction: ({ safeTransaction, protocolKit, apiKit }: {
13
+ safeTransaction: SafeTransaction;
14
+ protocolKit: Safe;
15
+ apiKit: SafeApiKit;
16
+ }) => Promise<string>;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.proposeTransaction = void 0;
4
+ const protocol_kit_1 = require("@safe-global/protocol-kit");
5
+ /**
6
+ * Propose a transaction to the Safe
7
+ *
8
+ * @param {SafeTransaction} safeTransaction The Safe transaction to propose
9
+ * @param {Safe} protocolKit The Safe instance
10
+ * @param {SafeApiKit} apiKit The SafeApiKit instance
11
+ * @returns The Safe transaction hash
12
+ */
13
+ const proposeTransaction = async ({ safeTransaction, protocolKit, apiKit }) => {
14
+ safeTransaction = await protocolKit.signTransaction(safeTransaction);
15
+ const signerAddress = (await protocolKit.getSafeProvider().getSignerAddress()) || '0x';
16
+ const ethSig = safeTransaction.getSignature(signerAddress);
17
+ const safeTxHash = await protocolKit.getTransactionHash(safeTransaction);
18
+ const txOptions = {
19
+ safeAddress: await protocolKit.getAddress(),
20
+ safeTransactionData: safeTransaction.data,
21
+ safeTxHash,
22
+ senderAddress: signerAddress,
23
+ senderSignature: (0, protocol_kit_1.buildSignatureBytes)([ethSig])
24
+ };
25
+ await apiKit.proposeTransaction(txOptions);
26
+ return safeTxHash;
27
+ };
28
+ exports.proposeTransaction = proposeTransaction;
29
+ //# sourceMappingURL=proposeTransaction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"proposeTransaction.js","sourceRoot":"","sources":["../../../src/utils/proposeTransaction.ts"],"names":[],"mappings":";;;AAAA,4DAAuF;AAIvF;;;;;;;GAOG;AACI,MAAM,kBAAkB,GAAG,KAAK,EAAE,EACvC,eAAe,EACf,WAAW,EACX,MAAM,EAKP,EAAmB,EAAE;IACpB,eAAe,GAAG,MAAM,WAAW,CAAC,eAAe,CAAC,eAAe,CAAC,CAAA;IAEpE,MAAM,aAAa,GAAG,CAAC,MAAM,WAAW,CAAC,eAAe,EAAE,CAAC,gBAAgB,EAAE,CAAC,IAAI,IAAI,CAAA;IACtF,MAAM,MAAM,GAAG,eAAe,CAAC,YAAY,CAAC,aAAa,CAAqB,CAAA;IAC9E,MAAM,UAAU,GAAG,MAAM,WAAW,CAAC,kBAAkB,CAAC,eAAe,CAAC,CAAA;IAExE,MAAM,SAAS,GAAG;QAChB,WAAW,EAAE,MAAM,WAAW,CAAC,UAAU,EAAE;QAC3C,mBAAmB,EAAE,eAAe,CAAC,IAAI;QACzC,UAAU;QACV,aAAa,EAAE,aAAa;QAC5B,eAAe,EAAE,IAAA,kCAAmB,EAAC,CAAC,MAAM,CAAC,CAAC;KAC/C,CAAA;IAED,MAAM,MAAM,CAAC,kBAAkB,CAAC,SAAS,CAAC,CAAA;IAE1C,OAAO,UAAU,CAAA;AACnB,CAAC,CAAA;AA1BY,QAAA,kBAAkB,sBA0B9B"}
@@ -0,0 +1,14 @@
1
+ import Safe from '@safe-global/protocol-kit';
2
+ import { Transaction } from '@safe-global/types-kit';
3
+ /**
4
+ * Sends a transaction using the signer (owner)
5
+ * It's useful to deploy Safe accounts
6
+ *
7
+ * @param {Transaction} transaction The transaction.
8
+ * @param {Safe} protocolKit The protocolKit instance
9
+ * @returns {Promise<string | undefined>} A promise that resolves with the transaction hash
10
+ */
11
+ export declare const sendTransaction: ({ transaction, protocolKit }: {
12
+ transaction: Transaction;
13
+ protocolKit: Safe;
14
+ }) => Promise<string | undefined>;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.sendTransaction = void 0;
4
+ const actions_1 = require("viem/actions");
5
+ /**
6
+ * Sends a transaction using the signer (owner)
7
+ * It's useful to deploy Safe accounts
8
+ *
9
+ * @param {Transaction} transaction The transaction.
10
+ * @param {Safe} protocolKit The protocolKit instance
11
+ * @returns {Promise<string | undefined>} A promise that resolves with the transaction hash
12
+ */
13
+ const sendTransaction = async ({ transaction, protocolKit }) => {
14
+ const signer = (await protocolKit.getSafeProvider().getExternalSigner());
15
+ const client = protocolKit.getSafeProvider().getExternalProvider();
16
+ if (!signer)
17
+ throw new Error('SafeProvider must be initialized with a signer to use this function');
18
+ const hash = await signer.sendTransaction({
19
+ to: transaction.to,
20
+ data: transaction.data,
21
+ value: BigInt(transaction.value),
22
+ account: signer.account
23
+ });
24
+ const receipt = await (0, actions_1.waitForTransactionReceipt)(client, { hash });
25
+ return receipt.transactionHash;
26
+ };
27
+ exports.sendTransaction = sendTransaction;
28
+ //# sourceMappingURL=sendTransaction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sendTransaction.js","sourceRoot":"","sources":["../../../src/utils/sendTransaction.ts"],"names":[],"mappings":";;;AACA,0CAAwD;AAIxD;;;;;;;GAOG;AACI,MAAM,eAAe,GAAG,KAAK,EAAE,EACpC,WAAW,EACX,WAAW,EAIZ,EAA+B,EAAE;IAChC,MAAM,MAAM,GAAG,CAAC,MAAM,WAAW,CAAC,eAAe,EAAE,CAAC,iBAAiB,EAAE,CAItE,CAAA;IACD,MAAM,MAAM,GAAG,WAAW,CAAC,eAAe,EAAE,CAAC,mBAAmB,EAAE,CAAA;IAElE,IAAI,CAAC,MAAM;QACT,MAAM,IAAI,KAAK,CAAC,qEAAqE,CAAC,CAAA;IAExF,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,eAAe,CAAC;QACxC,EAAE,EAAE,WAAW,CAAC,EAAE;QAClB,IAAI,EAAE,WAAW,CAAC,IAAW;QAC7B,KAAK,EAAE,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC;QAChC,OAAO,EAAE,MAAM,CAAC,OAAO;KACxB,CAAC,CAAA;IAEF,MAAM,OAAO,GAAG,MAAM,IAAA,mCAAyB,EAAC,MAAM,EAAE,EAAE,IAAI,EAAE,CAAC,CAAA;IAEjE,OAAO,OAAO,CAAC,eAAe,CAAA;AAChC,CAAC,CAAA;AA3BY,QAAA,eAAe,mBA2B3B"}