@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.
- package/README.md +35 -0
- package/dist/src/BaseClient.d.ts +82 -0
- package/dist/src/BaseClient.js +123 -0
- package/dist/src/BaseClient.js.map +1 -0
- package/dist/src/SafeClient.d.ts +62 -0
- package/dist/src/SafeClient.js +215 -0
- package/dist/src/SafeClient.js.map +1 -0
- package/dist/src/constants.d.ts +24 -0
- package/dist/src/constants.js +36 -0
- package/dist/src/constants.js.map +1 -0
- package/dist/src/extensions/index.d.ts +3 -0
- package/dist/src/extensions/index.js +20 -0
- package/dist/src/extensions/index.js.map +1 -0
- package/dist/src/extensions/messages/SafeMessageClient.d.ts +41 -0
- package/dist/src/extensions/messages/SafeMessageClient.js +161 -0
- package/dist/src/extensions/messages/SafeMessageClient.js.map +1 -0
- package/dist/src/extensions/messages/offChainMessages.d.ts +38 -0
- package/dist/src/extensions/messages/offChainMessages.js +52 -0
- package/dist/src/extensions/messages/offChainMessages.js.map +1 -0
- package/dist/src/extensions/messages/onChainMessages.d.ts +28 -0
- package/dist/src/extensions/messages/onChainMessages.js +48 -0
- package/dist/src/extensions/messages/onChainMessages.js.map +1 -0
- package/dist/src/extensions/safe-operations/SafeOperationClient.d.ts +51 -0
- package/dist/src/extensions/safe-operations/SafeOperationClient.js +127 -0
- package/dist/src/extensions/safe-operations/SafeOperationClient.js.map +1 -0
- package/dist/src/extensions/safe-operations/safeOperations.d.ts +49 -0
- package/dist/src/extensions/safe-operations/safeOperations.js +85 -0
- package/dist/src/extensions/safe-operations/safeOperations.js.map +1 -0
- package/dist/src/index.d.ts +12 -0
- package/dist/src/index.js +92 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/types.d.ts +69 -0
- package/dist/src/types.js +3 -0
- package/dist/src/types.js.map +1 -0
- package/dist/src/utils/index.d.ts +19 -0
- package/dist/src/utils/index.js +57 -0
- package/dist/src/utils/index.js.map +1 -0
- package/dist/src/utils/proposeTransaction.d.ts +16 -0
- package/dist/src/utils/proposeTransaction.js +29 -0
- package/dist/src/utils/proposeTransaction.js.map +1 -0
- package/dist/src/utils/sendTransaction.d.ts +14 -0
- package/dist/src/utils/sendTransaction.js +28 -0
- package/dist/src/utils/sendTransaction.js.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/package.json +45 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import Safe from '@safe-global/protocol-kit';
|
|
2
|
+
import SafeApiKit, { ListOptions, SafeMessageListResponse } from '@safe-global/api-kit';
|
|
3
|
+
import { ConfirmOffChainMessageProps, SafeClientResult, SendOffChainMessageProps } from '../../types';
|
|
4
|
+
/**
|
|
5
|
+
* @class
|
|
6
|
+
* This class provides the functionality to create and confirm off-chain messages
|
|
7
|
+
*/
|
|
8
|
+
export declare class SafeMessageClient {
|
|
9
|
+
#private;
|
|
10
|
+
protocolKit: Safe;
|
|
11
|
+
apiKit: SafeApiKit;
|
|
12
|
+
/**
|
|
13
|
+
* @constructor
|
|
14
|
+
* @param {Safe} protocolKit A Safe instance
|
|
15
|
+
* @param {SafeApiKit} apiKit A SafeApiKit instance
|
|
16
|
+
*/
|
|
17
|
+
constructor(protocolKit: Safe, apiKit: SafeApiKit);
|
|
18
|
+
/**
|
|
19
|
+
* Send off-chain messages using the Transaction service
|
|
20
|
+
*
|
|
21
|
+
* @param {SendOffChainMessageProps} props The message properties
|
|
22
|
+
* @param {string | EIP712TypedData} props.message The message to be sent. Can be a raw string or an EIP712TypedData object
|
|
23
|
+
* @returns {Promise<SafeClientResult>} A SafeClientResult. You can get the messageHash to confirmMessage() afterwards from the messages property
|
|
24
|
+
*/
|
|
25
|
+
sendMessage({ message }: SendOffChainMessageProps): Promise<SafeClientResult>;
|
|
26
|
+
/**
|
|
27
|
+
* Confirms an off-chain message using the Transaction service
|
|
28
|
+
*
|
|
29
|
+
* @param {ConfirmOffChainMessageProps} props The confirmation properties
|
|
30
|
+
* @param {string} props.messageHash The messageHash. Returned from the sendMessage() method inside the SafeClientResult messages property
|
|
31
|
+
* @returns {Promise<SafeClientResult>} A SafeClientResult with the result of the confirmation
|
|
32
|
+
*/
|
|
33
|
+
confirmMessage({ messageHash }: ConfirmOffChainMessageProps): Promise<SafeClientResult>;
|
|
34
|
+
/**
|
|
35
|
+
* Get the list of pending off-chain messages. This messages can be confirmed using the confirmMessage() method
|
|
36
|
+
*
|
|
37
|
+
* @param {ListOptions} options The pagination options
|
|
38
|
+
* @returns {Promise<SafeMessageListResponse>} A list of pending messages
|
|
39
|
+
*/
|
|
40
|
+
getPendingMessages(options?: ListOptions): Promise<SafeMessageListResponse>;
|
|
41
|
+
}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
4
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
5
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
6
|
+
};
|
|
7
|
+
var _SafeMessageClient_instances, _SafeMessageClient_deployAndAddMessage, _SafeMessageClient_addMessage, _SafeMessageClient_updateProtocolKitWithDeployedSafe;
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.SafeMessageClient = void 0;
|
|
10
|
+
const protocol_kit_1 = require("@safe-global/protocol-kit");
|
|
11
|
+
const utils_1 = require("../../utils");
|
|
12
|
+
const constants_1 = require("../../constants");
|
|
13
|
+
/**
|
|
14
|
+
* @class
|
|
15
|
+
* This class provides the functionality to create and confirm off-chain messages
|
|
16
|
+
*/
|
|
17
|
+
class SafeMessageClient {
|
|
18
|
+
/**
|
|
19
|
+
* @constructor
|
|
20
|
+
* @param {Safe} protocolKit A Safe instance
|
|
21
|
+
* @param {SafeApiKit} apiKit A SafeApiKit instance
|
|
22
|
+
*/
|
|
23
|
+
constructor(protocolKit, apiKit) {
|
|
24
|
+
_SafeMessageClient_instances.add(this);
|
|
25
|
+
this.protocolKit = protocolKit;
|
|
26
|
+
this.apiKit = apiKit;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Send off-chain messages using the Transaction service
|
|
30
|
+
*
|
|
31
|
+
* @param {SendOffChainMessageProps} props The message properties
|
|
32
|
+
* @param {string | EIP712TypedData} props.message The message to be sent. Can be a raw string or an EIP712TypedData object
|
|
33
|
+
* @returns {Promise<SafeClientResult>} A SafeClientResult. You can get the messageHash to confirmMessage() afterwards from the messages property
|
|
34
|
+
*/
|
|
35
|
+
async sendMessage({ message }) {
|
|
36
|
+
const isSafeDeployed = await this.protocolKit.isSafeDeployed();
|
|
37
|
+
const safeMessage = this.protocolKit.createMessage(message);
|
|
38
|
+
if (isSafeDeployed) {
|
|
39
|
+
return __classPrivateFieldGet(this, _SafeMessageClient_instances, "m", _SafeMessageClient_addMessage).call(this, { safeMessage });
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
return __classPrivateFieldGet(this, _SafeMessageClient_instances, "m", _SafeMessageClient_deployAndAddMessage).call(this, { safeMessage });
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Confirms an off-chain message using the Transaction service
|
|
47
|
+
*
|
|
48
|
+
* @param {ConfirmOffChainMessageProps} props The confirmation properties
|
|
49
|
+
* @param {string} props.messageHash The messageHash. Returned from the sendMessage() method inside the SafeClientResult messages property
|
|
50
|
+
* @returns {Promise<SafeClientResult>} A SafeClientResult with the result of the confirmation
|
|
51
|
+
*/
|
|
52
|
+
async confirmMessage({ messageHash }) {
|
|
53
|
+
let messageResponse = await this.apiKit.getMessage(messageHash);
|
|
54
|
+
const safeAddress = await this.protocolKit.getAddress();
|
|
55
|
+
const threshold = await this.protocolKit.getThreshold();
|
|
56
|
+
let safeMessage = this.protocolKit.createMessage(messageResponse.message);
|
|
57
|
+
safeMessage = await this.protocolKit.signMessage(safeMessage);
|
|
58
|
+
await this.apiKit.addMessageSignature(messageHash, safeMessage.encodedSignatures());
|
|
59
|
+
messageResponse = await this.apiKit.getMessage(messageHash);
|
|
60
|
+
return (0, utils_1.createSafeClientResult)({
|
|
61
|
+
status: messageResponse.confirmations.length === threshold
|
|
62
|
+
? constants_1.SafeClientTxStatus.MESSAGE_CONFIRMED
|
|
63
|
+
: constants_1.SafeClientTxStatus.MESSAGE_PENDING_SIGNATURES,
|
|
64
|
+
safeAddress,
|
|
65
|
+
messageHash
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Get the list of pending off-chain messages. This messages can be confirmed using the confirmMessage() method
|
|
70
|
+
*
|
|
71
|
+
* @param {ListOptions} options The pagination options
|
|
72
|
+
* @returns {Promise<SafeMessageListResponse>} A list of pending messages
|
|
73
|
+
*/
|
|
74
|
+
async getPendingMessages(options) {
|
|
75
|
+
const safeAddress = await this.protocolKit.getAddress();
|
|
76
|
+
return this.apiKit.getMessages(safeAddress, options);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
exports.SafeMessageClient = SafeMessageClient;
|
|
80
|
+
_SafeMessageClient_instances = new WeakSet(), _SafeMessageClient_deployAndAddMessage =
|
|
81
|
+
/**
|
|
82
|
+
* Deploys a new Safe account based on the provided config and adds a message using the Transaction service
|
|
83
|
+
* - If the Safe threshold > 1, we need to deploy the Safe account first and afterwards add the message
|
|
84
|
+
* The message should be confirmed with other owners using the confirmMessage() method until the threshold is reached in order to be valid
|
|
85
|
+
* - If the threshold = 1, we can deploy the Safe account and add the message in one step. The message will be valid immediately
|
|
86
|
+
*
|
|
87
|
+
* @param {SafeTransaction} safeMessage The safe message
|
|
88
|
+
* @returns {Promise<SafeClientResult>} The SafeClientResult
|
|
89
|
+
*/
|
|
90
|
+
async function _SafeMessageClient_deployAndAddMessage({ safeMessage }) {
|
|
91
|
+
let deploymentTxHash;
|
|
92
|
+
const threshold = await this.protocolKit.getThreshold();
|
|
93
|
+
const safeDeploymentTransaction = await this.protocolKit.createSafeDeploymentTransaction();
|
|
94
|
+
try {
|
|
95
|
+
deploymentTxHash = await (0, utils_1.sendTransaction)({
|
|
96
|
+
transaction: safeDeploymentTransaction,
|
|
97
|
+
protocolKit: this.protocolKit
|
|
98
|
+
});
|
|
99
|
+
await __classPrivateFieldGet(this, _SafeMessageClient_instances, "m", _SafeMessageClient_updateProtocolKitWithDeployedSafe).call(this);
|
|
100
|
+
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
throw new Error('Could not deploy the Safe account');
|
|
103
|
+
}
|
|
104
|
+
try {
|
|
105
|
+
const { messages } = await __classPrivateFieldGet(this, _SafeMessageClient_instances, "m", _SafeMessageClient_addMessage).call(this, { safeMessage });
|
|
106
|
+
const messageResponse = await this.apiKit.getMessage(messages?.messageHash || '0x');
|
|
107
|
+
return (0, utils_1.createSafeClientResult)({
|
|
108
|
+
safeAddress: await this.protocolKit.getAddress(),
|
|
109
|
+
status: messageResponse.confirmations.length === threshold
|
|
110
|
+
? constants_1.SafeClientTxStatus.DEPLOYED_AND_MESSAGE_CONFIRMED
|
|
111
|
+
: constants_1.SafeClientTxStatus.DEPLOYED_AND_MESSAGE_PENDING_SIGNATURES,
|
|
112
|
+
deploymentTxHash,
|
|
113
|
+
messageHash: messages?.messageHash
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
catch (error) {
|
|
117
|
+
throw new Error('Could not add a new off-chain message to the Safe account');
|
|
118
|
+
}
|
|
119
|
+
}, _SafeMessageClient_addMessage =
|
|
120
|
+
/**
|
|
121
|
+
* Add a new off-chain message using the Transaction service
|
|
122
|
+
* - If the threshold > 1, remember to confirmMessage() after sendMessage()
|
|
123
|
+
* - If the threshold = 1, then the message is confirmed and valid immediately
|
|
124
|
+
*
|
|
125
|
+
* @param {SafeMessage} safeMessage The message
|
|
126
|
+
* @returns {Promise<SafeClientResult>} The SafeClientResult
|
|
127
|
+
*/
|
|
128
|
+
async function _SafeMessageClient_addMessage({ safeMessage }) {
|
|
129
|
+
const safeAddress = await this.protocolKit.getAddress();
|
|
130
|
+
const threshold = await this.protocolKit.getThreshold();
|
|
131
|
+
const signedMessage = await this.protocolKit.signMessage(safeMessage);
|
|
132
|
+
const messageHash = await this.protocolKit.getSafeMessageHash((0, protocol_kit_1.hashSafeMessage)(safeMessage.data));
|
|
133
|
+
try {
|
|
134
|
+
await this.apiKit.addMessage(safeAddress, {
|
|
135
|
+
message: safeMessage.data,
|
|
136
|
+
signature: signedMessage.encodedSignatures()
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
catch (error) {
|
|
140
|
+
throw new Error('Could not add a new off-chain message to the Safe account');
|
|
141
|
+
}
|
|
142
|
+
const message = await this.apiKit.getMessage(messageHash);
|
|
143
|
+
return (0, utils_1.createSafeClientResult)({
|
|
144
|
+
safeAddress: await this.protocolKit.getAddress(),
|
|
145
|
+
status: message.confirmations.length === threshold
|
|
146
|
+
? constants_1.SafeClientTxStatus.MESSAGE_CONFIRMED
|
|
147
|
+
: constants_1.SafeClientTxStatus.MESSAGE_PENDING_SIGNATURES,
|
|
148
|
+
messageHash
|
|
149
|
+
});
|
|
150
|
+
}, _SafeMessageClient_updateProtocolKitWithDeployedSafe =
|
|
151
|
+
/**
|
|
152
|
+
* This method updates the Safe instance with the deployed Safe account
|
|
153
|
+
*/
|
|
154
|
+
async function _SafeMessageClient_updateProtocolKitWithDeployedSafe() {
|
|
155
|
+
this.protocolKit = await this.protocolKit.connect({
|
|
156
|
+
provider: this.protocolKit.getSafeProvider().provider,
|
|
157
|
+
signer: this.protocolKit.getSafeProvider().signer,
|
|
158
|
+
safeAddress: await this.protocolKit.getAddress()
|
|
159
|
+
});
|
|
160
|
+
};
|
|
161
|
+
//# sourceMappingURL=SafeMessageClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3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IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CAAC,2DAA2D,CAAC,CAAA;IAC9E,CAAC;IAED,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,WAAW,CAAC,CAAA;IAEzD,OAAO,IAAA,8BAAsB,EAAC;QAC5B,WAAW,EAAE,MAAM,IAAI,CAAC,WAAW,CAAC,UAAU,EAAE;QAChD,MAAM,EACJ,OAAO,CAAC,aAAa,CAAC,MAAM,KAAK,SAAS;YACxC,CAAC,CAAC,8BAAkB,CAAC,iBAAiB;YACtC,CAAC,CAAC,8BAAkB,CAAC,0BAA0B;QACnD,WAAW;KACZ,CAAC,CAAA;AACJ,CAAC;AAED;;GAEG;AACH,KAAK;IACH,IAAI,CAAC,WAAW,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC;QAChD,QAAQ,EAAE,IAAI,CAAC,WAAW,CAAC,eAAe,EAAE,CAAC,QAAQ;QACrD,MAAM,EAAE,IAAI,CAAC,WAAW,CAAC,eAAe,EAAE,CAAC,MAAM;QACjD,WAAW,EAAE,MAAM,IAAI,CAAC,WAAW,CAAC,UAAU,EAAE;KACjD,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { ListOptions, SafeMessageListResponse } from '@safe-global/api-kit';
|
|
2
|
+
import { SafeClient } from '../../SafeClient';
|
|
3
|
+
import { ConfirmOffChainMessageProps, SafeClientResult, SendOffChainMessageProps } from '../../types';
|
|
4
|
+
/**
|
|
5
|
+
* Extend the SafeClient with the ability to use off-chain messages
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* const safeClient = await createSafeClient({ ... })
|
|
9
|
+
*
|
|
10
|
+
* const safeMessagesClient = await safeClient.extend(
|
|
11
|
+
* offChainMessages()
|
|
12
|
+
* )
|
|
13
|
+
*
|
|
14
|
+
* const { messages } = await safeMessagesClient.sendOffChainMessage({ message })
|
|
15
|
+
* await safeMessagesClient.confirmOffChainMessage({ messageHash: messages?.messageHash})
|
|
16
|
+
*/
|
|
17
|
+
export declare function offChainMessages(): (client: SafeClient) => {
|
|
18
|
+
/**
|
|
19
|
+
* Creates an off-chain message using the Transaction service
|
|
20
|
+
*
|
|
21
|
+
* @param {SendOffChainMessageProps} props The message properties
|
|
22
|
+
* @returns {Promise<SafeClientResult>} A SafeClientResult. You can get the messageHash to confirmMessage() afterwards from the messages property */
|
|
23
|
+
sendOffChainMessage(props: SendOffChainMessageProps): Promise<SafeClientResult>;
|
|
24
|
+
/**
|
|
25
|
+
* Confirms an off-chain message using the Transaction service
|
|
26
|
+
*
|
|
27
|
+
* @param {ConfirmOffChainMessageProps} props The confirmation properties
|
|
28
|
+
* @returns {Promise<SafeClientResult>} A SafeClientResult with the result of the confirmation
|
|
29
|
+
*/
|
|
30
|
+
confirmOffChainMessage(props: ConfirmOffChainMessageProps): Promise<SafeClientResult>;
|
|
31
|
+
/**
|
|
32
|
+
* Get the list of pending off-chain messages. This messages can be confirmed using the confirmMessage() method
|
|
33
|
+
*
|
|
34
|
+
* @param {ListOptions} options The pagination options
|
|
35
|
+
* @returns {Promise<SafeMessageListResponse>} A list of pending messages
|
|
36
|
+
*/
|
|
37
|
+
getPendingOffChainMessages(options?: ListOptions): Promise<SafeMessageListResponse>;
|
|
38
|
+
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.offChainMessages = void 0;
|
|
4
|
+
const SafeMessageClient_1 = require("../../extensions/messages/SafeMessageClient");
|
|
5
|
+
/**
|
|
6
|
+
* Extend the SafeClient with the ability to use off-chain messages
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* const safeClient = await createSafeClient({ ... })
|
|
10
|
+
*
|
|
11
|
+
* const safeMessagesClient = await safeClient.extend(
|
|
12
|
+
* offChainMessages()
|
|
13
|
+
* )
|
|
14
|
+
*
|
|
15
|
+
* const { messages } = await safeMessagesClient.sendOffChainMessage({ message })
|
|
16
|
+
* await safeMessagesClient.confirmOffChainMessage({ messageHash: messages?.messageHash})
|
|
17
|
+
*/
|
|
18
|
+
function offChainMessages() {
|
|
19
|
+
return (client) => {
|
|
20
|
+
const safeMessageClient = new SafeMessageClient_1.SafeMessageClient(client.protocolKit, client.apiKit);
|
|
21
|
+
return {
|
|
22
|
+
/**
|
|
23
|
+
* Creates an off-chain message using the Transaction service
|
|
24
|
+
*
|
|
25
|
+
* @param {SendOffChainMessageProps} props The message properties
|
|
26
|
+
* @returns {Promise<SafeClientResult>} A SafeClientResult. You can get the messageHash to confirmMessage() afterwards from the messages property */
|
|
27
|
+
async sendOffChainMessage(props) {
|
|
28
|
+
return safeMessageClient.sendMessage(props);
|
|
29
|
+
},
|
|
30
|
+
/**
|
|
31
|
+
* Confirms an off-chain message using the Transaction service
|
|
32
|
+
*
|
|
33
|
+
* @param {ConfirmOffChainMessageProps} props The confirmation properties
|
|
34
|
+
* @returns {Promise<SafeClientResult>} A SafeClientResult with the result of the confirmation
|
|
35
|
+
*/
|
|
36
|
+
async confirmOffChainMessage(props) {
|
|
37
|
+
return safeMessageClient.confirmMessage(props);
|
|
38
|
+
},
|
|
39
|
+
/**
|
|
40
|
+
* Get the list of pending off-chain messages. This messages can be confirmed using the confirmMessage() method
|
|
41
|
+
*
|
|
42
|
+
* @param {ListOptions} options The pagination options
|
|
43
|
+
* @returns {Promise<SafeMessageListResponse>} A list of pending messages
|
|
44
|
+
*/
|
|
45
|
+
async getPendingOffChainMessages(options) {
|
|
46
|
+
return safeMessageClient.getPendingMessages(options);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
exports.offChainMessages = offChainMessages;
|
|
52
|
+
//# sourceMappingURL=offChainMessages.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"offChainMessages.js","sourceRoot":"","sources":["../../../../src/extensions/messages/offChainMessages.ts"],"names":[],"mappings":";;;AAGA,0GAAsG;AAOtG;;;;;;;;;;;;GAYG;AACH,SAAgB,gBAAgB;IAC9B,OAAO,CAAC,MAAkB,EAAE,EAAE;QAC5B,MAAM,iBAAiB,GAAG,IAAI,qCAAiB,CAAC,MAAM,CAAC,WAAW,EAAE,MAAM,CAAC,MAAM,CAAC,CAAA;QAElF,OAAO;YACL;;;;sKAI0J;YAC1J,KAAK,CAAC,mBAAmB,CAAC,KAA+B;gBACvD,OAAO,iBAAiB,CAAC,WAAW,CAAC,KAAK,CAAC,CAAA;YAC7C,CAAC;YACD;;;;;eAKG;YACH,KAAK,CAAC,sBAAsB,CAAC,KAAkC;gBAC7D,OAAO,iBAAiB,CAAC,cAAc,CAAC,KAAK,CAAC,CAAA;YAChD,CAAC;YACD;;;;;eAKG;YACH,KAAK,CAAC,0BAA0B,CAAC,OAAqB;gBACpD,OAAO,iBAAiB,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAA;YACtD,CAAC;SACF,CAAA;IACH,CAAC,CAAA;AACH,CAAC;AAjCD,4CAiCC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { SafeClient } from '../../SafeClient';
|
|
2
|
+
import { SafeClientResult, SendOnChainMessageProps } from '../../types';
|
|
3
|
+
/**
|
|
4
|
+
* Extend the SafeClient with the ability to use on-chain messages
|
|
5
|
+
* The on-chain messages are regular transactions created using the SignMessageLib so after sendMessage()
|
|
6
|
+
* you can confirm the transaction using the safeTxHash anf the confirm() method for transactions
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* const safeClient = await createSafeClient({ ... })
|
|
10
|
+
*
|
|
11
|
+
* const safeMessageClient = await safeClient.extend(
|
|
12
|
+
* onChainMessages()
|
|
13
|
+
* )
|
|
14
|
+
*
|
|
15
|
+
* const { transactions } = await safeMessageClient.sendOnChainMessage({ message })
|
|
16
|
+
* await safeMessageClient.confirm({ safeTxHash: transactions?.safeTxHash})
|
|
17
|
+
*/
|
|
18
|
+
export declare function onChainMessages(): (client: SafeClient) => {
|
|
19
|
+
/**
|
|
20
|
+
* Creates and sends a message as a regular transaction using the SignMessageLib contract
|
|
21
|
+
* The message can be a string or an EIP712TypedData object
|
|
22
|
+
* As this method creates a new transaction you can confirm it using the safeTxHash and the confirm() method and
|
|
23
|
+
* retrieve the pending transactions using the getPendingTransactions() method from the general client
|
|
24
|
+
* @param {SendOnChainMessageProps} props The message properties
|
|
25
|
+
* @returns {Promise<SafeClientResult>} A SafeClientResult. You can get the safeTxHash to confirm from the transaction property
|
|
26
|
+
*/
|
|
27
|
+
sendOnChainMessage(props: SendOnChainMessageProps): Promise<SafeClientResult>;
|
|
28
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.onChainMessages = void 0;
|
|
4
|
+
const protocol_kit_1 = require("@safe-global/protocol-kit");
|
|
5
|
+
const types_kit_1 = require("@safe-global/types-kit");
|
|
6
|
+
/**
|
|
7
|
+
* Extend the SafeClient with the ability to use on-chain messages
|
|
8
|
+
* The on-chain messages are regular transactions created using the SignMessageLib so after sendMessage()
|
|
9
|
+
* you can confirm the transaction using the safeTxHash anf the confirm() method for transactions
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* const safeClient = await createSafeClient({ ... })
|
|
13
|
+
*
|
|
14
|
+
* const safeMessageClient = await safeClient.extend(
|
|
15
|
+
* onChainMessages()
|
|
16
|
+
* )
|
|
17
|
+
*
|
|
18
|
+
* const { transactions } = await safeMessageClient.sendOnChainMessage({ message })
|
|
19
|
+
* await safeMessageClient.confirm({ safeTxHash: transactions?.safeTxHash})
|
|
20
|
+
*/
|
|
21
|
+
function onChainMessages() {
|
|
22
|
+
return (client) => ({
|
|
23
|
+
/**
|
|
24
|
+
* Creates and sends a message as a regular transaction using the SignMessageLib contract
|
|
25
|
+
* The message can be a string or an EIP712TypedData object
|
|
26
|
+
* As this method creates a new transaction you can confirm it using the safeTxHash and the confirm() method and
|
|
27
|
+
* retrieve the pending transactions using the getPendingTransactions() method from the general client
|
|
28
|
+
* @param {SendOnChainMessageProps} props The message properties
|
|
29
|
+
* @returns {Promise<SafeClientResult>} A SafeClientResult. You can get the safeTxHash to confirm from the transaction property
|
|
30
|
+
*/
|
|
31
|
+
async sendOnChainMessage(props) {
|
|
32
|
+
const { message, ...transactionOptions } = props;
|
|
33
|
+
const signMessageLibContract = await (0, protocol_kit_1.getSignMessageLibContract)({
|
|
34
|
+
safeProvider: client.protocolKit.getSafeProvider(),
|
|
35
|
+
safeVersion: client.protocolKit.getContractVersion()
|
|
36
|
+
});
|
|
37
|
+
const transaction = {
|
|
38
|
+
to: signMessageLibContract.getAddress(),
|
|
39
|
+
value: '0',
|
|
40
|
+
data: signMessageLibContract.encode('signMessage', [(0, protocol_kit_1.hashSafeMessage)(message)]),
|
|
41
|
+
operation: types_kit_1.OperationType.DelegateCall
|
|
42
|
+
};
|
|
43
|
+
return client.send({ transactions: [transaction], ...transactionOptions });
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
exports.onChainMessages = onChainMessages;
|
|
48
|
+
//# sourceMappingURL=onChainMessages.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"onChainMessages.js","sourceRoot":"","sources":["../../../../src/extensions/messages/onChainMessages.ts"],"names":[],"mappings":";;;AAAA,4DAAsF;AACtF,sDAAsD;AAMtD;;;;;;;;;;;;;;GAcG;AACH,SAAgB,eAAe;IAC7B,OAAO,CAAC,MAAkB,EAAE,EAAE,CAAC,CAAC;QAC9B;;;;;;;WAOG;QACH,KAAK,CAAC,kBAAkB,CAAC,KAA8B;YACrD,MAAM,EAAE,OAAO,EAAE,GAAG,kBAAkB,EAAE,GAAG,KAAK,CAAA;YAEhD,MAAM,sBAAsB,GAAG,MAAM,IAAA,wCAAyB,EAAC;gBAC7D,YAAY,EAAE,MAAM,CAAC,WAAW,CAAC,eAAe,EAAE;gBAClD,WAAW,EAAE,MAAM,CAAC,WAAW,CAAC,kBAAkB,EAAE;aACrD,CAAC,CAAA;YAEF,MAAM,WAAW,GAAG;gBAClB,EAAE,EAAE,sBAAsB,CAAC,UAAU,EAAE;gBACvC,KAAK,EAAE,GAAG;gBACV,IAAI,EAAE,sBAAsB,CAAC,MAAM,CAAC,aAAa,EAAE,CAAC,IAAA,8BAAe,EAAC,OAAO,CAAS,CAAC,CAAC;gBACtF,SAAS,EAAE,yBAAa,CAAC,YAAY;aACtC,CAAA;YAED,OAAO,MAAM,CAAC,IAAI,CAAC,EAAE,YAAY,EAAE,CAAC,WAAW,CAAC,EAAE,GAAG,kBAAkB,EAAE,CAAC,CAAA;QAC5E,CAAC;KACF,CAAC,CAAA;AACJ,CAAC;AA5BD,0CA4BC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import Safe from '@safe-global/protocol-kit';
|
|
2
|
+
import SafeApiKit, { ListOptions, GetSafeOperationListResponse } from '@safe-global/api-kit';
|
|
3
|
+
import { Safe4337Pack } from '@safe-global/relay-kit';
|
|
4
|
+
import { ConfirmSafeOperationProps, SafeClientResult, SendSafeOperationProps } from '../../types';
|
|
5
|
+
/**
|
|
6
|
+
* @class
|
|
7
|
+
* This class provides the functionality to use a bundler and a paymaster with your Safe account
|
|
8
|
+
* With the features implemented here we can add EIP-4377 support to the Safe account
|
|
9
|
+
*/
|
|
10
|
+
export declare class SafeOperationClient {
|
|
11
|
+
#private;
|
|
12
|
+
protocolKit: Safe;
|
|
13
|
+
apiKit: SafeApiKit;
|
|
14
|
+
safe4337Pack: Safe4337Pack;
|
|
15
|
+
constructor(safe4337Pack: Safe4337Pack, apiKit: SafeApiKit);
|
|
16
|
+
/**
|
|
17
|
+
* Send SafeOperations from a group of transactions.
|
|
18
|
+
* This method will convert your transactions in a batch and:
|
|
19
|
+
* - If the threshold > 1 it will save for later the SafeOperation using the Transaction service
|
|
20
|
+
* You must confirmSafeOperation() with other owners
|
|
21
|
+
* - If the threshold = 1 the SafeOperation can be submitted to the bundler so it will execute it immediately
|
|
22
|
+
*
|
|
23
|
+
* @param {Safe4337CreateTransactionProps} props The Safe4337CreateTransactionProps object
|
|
24
|
+
* @param {SafeTransaction[]} props.transactions An array of transactions to be batched
|
|
25
|
+
* @param {TransactionOptions} [props.amountToApprove] The amount to approve for the SafeOperation
|
|
26
|
+
* @param {TransactionOptions} [props.validUntil] The validUntil timestamp for the SafeOperation
|
|
27
|
+
* @param {TransactionOptions} [props.validAfter] The validAfter timestamp for the SafeOperation
|
|
28
|
+
* @param {TransactionOptions} [props.feeEstimator] The feeEstimator to calculate the fees
|
|
29
|
+
* @returns {Promise<SafeClientResult>} A promise that resolves with the status of the SafeOperation
|
|
30
|
+
*/
|
|
31
|
+
sendSafeOperation({ transactions, ...sendSafeOperationOptions }: SendSafeOperationProps): Promise<SafeClientResult>;
|
|
32
|
+
/**
|
|
33
|
+
* Confirms the stored safeOperation
|
|
34
|
+
*
|
|
35
|
+
* @param {ConfirmSafeOperationProps} props The confirmation properties
|
|
36
|
+
* @param {string} props.safeOperationHash The hash of the safe operation to confirm.
|
|
37
|
+
* The safeOperationHash can be extracted from the SafeClientResult of the sendSafeOperation method under the safeOperations property
|
|
38
|
+
* You must confirmSafeOperation() with the other owners and once the threshold is reached the SafeOperation will be sent to the bundler
|
|
39
|
+
* @returns {Promise<SafeClientResult>} A promise that resolves to the result of the safeOperation.
|
|
40
|
+
*/
|
|
41
|
+
confirmSafeOperation({ safeOperationHash }: ConfirmSafeOperationProps): Promise<SafeClientResult>;
|
|
42
|
+
/**
|
|
43
|
+
* Retrieves the pending Safe operations for the current Safe account
|
|
44
|
+
*
|
|
45
|
+
* @async
|
|
46
|
+
* @param {ListOptions} options The pagination options
|
|
47
|
+
* @returns {Promise<GetSafeOperationListResponse>} A promise that resolves to an array of pending Safe operations.
|
|
48
|
+
* @throws {Error} If there is an issue retrieving the safe address or pending Safe operations.
|
|
49
|
+
*/
|
|
50
|
+
getPendingSafeOperations(options?: ListOptions): Promise<GetSafeOperationListResponse>;
|
|
51
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
4
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
5
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
6
|
+
};
|
|
7
|
+
var _SafeOperationClient_instances, _SafeOperationClient_waitForOperationToFinish;
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.SafeOperationClient = void 0;
|
|
10
|
+
const protocol_kit_1 = require("@safe-global/protocol-kit");
|
|
11
|
+
const utils_1 = require("../../utils");
|
|
12
|
+
const constants_1 = require("../../constants");
|
|
13
|
+
/**
|
|
14
|
+
* @class
|
|
15
|
+
* This class provides the functionality to use a bundler and a paymaster with your Safe account
|
|
16
|
+
* With the features implemented here we can add EIP-4377 support to the Safe account
|
|
17
|
+
*/
|
|
18
|
+
class SafeOperationClient {
|
|
19
|
+
constructor(safe4337Pack, apiKit) {
|
|
20
|
+
_SafeOperationClient_instances.add(this);
|
|
21
|
+
this.protocolKit = safe4337Pack.protocolKit;
|
|
22
|
+
this.apiKit = apiKit;
|
|
23
|
+
this.safe4337Pack = safe4337Pack;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Send SafeOperations from a group of transactions.
|
|
27
|
+
* This method will convert your transactions in a batch and:
|
|
28
|
+
* - If the threshold > 1 it will save for later the SafeOperation using the Transaction service
|
|
29
|
+
* You must confirmSafeOperation() with other owners
|
|
30
|
+
* - If the threshold = 1 the SafeOperation can be submitted to the bundler so it will execute it immediately
|
|
31
|
+
*
|
|
32
|
+
* @param {Safe4337CreateTransactionProps} props The Safe4337CreateTransactionProps object
|
|
33
|
+
* @param {SafeTransaction[]} props.transactions An array of transactions to be batched
|
|
34
|
+
* @param {TransactionOptions} [props.amountToApprove] The amount to approve for the SafeOperation
|
|
35
|
+
* @param {TransactionOptions} [props.validUntil] The validUntil timestamp for the SafeOperation
|
|
36
|
+
* @param {TransactionOptions} [props.validAfter] The validAfter timestamp for the SafeOperation
|
|
37
|
+
* @param {TransactionOptions} [props.feeEstimator] The feeEstimator to calculate the fees
|
|
38
|
+
* @returns {Promise<SafeClientResult>} A promise that resolves with the status of the SafeOperation
|
|
39
|
+
*/
|
|
40
|
+
async sendSafeOperation({ transactions, ...sendSafeOperationOptions }) {
|
|
41
|
+
const safeAddress = await this.protocolKit.getAddress();
|
|
42
|
+
const isMultisigSafe = (await this.protocolKit.getThreshold()) > 1;
|
|
43
|
+
let safeOperation = await this.safe4337Pack.createTransaction({
|
|
44
|
+
transactions,
|
|
45
|
+
options: sendSafeOperationOptions
|
|
46
|
+
});
|
|
47
|
+
safeOperation = await this.safe4337Pack.signSafeOperation(safeOperation);
|
|
48
|
+
if (isMultisigSafe) {
|
|
49
|
+
await this.apiKit.addSafeOperation(safeOperation);
|
|
50
|
+
const safeOperationHash = safeOperation.getHash();
|
|
51
|
+
return (0, utils_1.createSafeClientResult)({
|
|
52
|
+
safeAddress,
|
|
53
|
+
status: constants_1.SafeClientTxStatus.SAFE_OPERATION_PENDING_SIGNATURES,
|
|
54
|
+
safeOperationHash
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
const userOperationHash = await this.safe4337Pack.executeTransaction({
|
|
58
|
+
executable: safeOperation
|
|
59
|
+
});
|
|
60
|
+
await __classPrivateFieldGet(this, _SafeOperationClient_instances, "m", _SafeOperationClient_waitForOperationToFinish).call(this, { userOperationHash });
|
|
61
|
+
return (0, utils_1.createSafeClientResult)({
|
|
62
|
+
safeAddress,
|
|
63
|
+
status: constants_1.SafeClientTxStatus.SAFE_OPERATION_EXECUTED,
|
|
64
|
+
userOperationHash,
|
|
65
|
+
safeOperationHash: safeOperation.getHash()
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Confirms the stored safeOperation
|
|
70
|
+
*
|
|
71
|
+
* @param {ConfirmSafeOperationProps} props The confirmation properties
|
|
72
|
+
* @param {string} props.safeOperationHash The hash of the safe operation to confirm.
|
|
73
|
+
* The safeOperationHash can be extracted from the SafeClientResult of the sendSafeOperation method under the safeOperations property
|
|
74
|
+
* You must confirmSafeOperation() with the other owners and once the threshold is reached the SafeOperation will be sent to the bundler
|
|
75
|
+
* @returns {Promise<SafeClientResult>} A promise that resolves to the result of the safeOperation.
|
|
76
|
+
*/
|
|
77
|
+
async confirmSafeOperation({ safeOperationHash }) {
|
|
78
|
+
const safeAddress = await this.protocolKit.getAddress();
|
|
79
|
+
const threshold = await this.protocolKit.getThreshold();
|
|
80
|
+
await this.apiKit.confirmSafeOperation(safeOperationHash, (0, protocol_kit_1.buildSignatureBytes)([await this.protocolKit.signHash(safeOperationHash)]));
|
|
81
|
+
const confirmedSafeOperation = await this.apiKit.getSafeOperation(safeOperationHash);
|
|
82
|
+
if (confirmedSafeOperation?.confirmations?.length === threshold) {
|
|
83
|
+
const userOperationHash = await this.safe4337Pack.executeTransaction({
|
|
84
|
+
executable: confirmedSafeOperation
|
|
85
|
+
});
|
|
86
|
+
await __classPrivateFieldGet(this, _SafeOperationClient_instances, "m", _SafeOperationClient_waitForOperationToFinish).call(this, { userOperationHash });
|
|
87
|
+
return (0, utils_1.createSafeClientResult)({
|
|
88
|
+
status: constants_1.SafeClientTxStatus.SAFE_OPERATION_EXECUTED,
|
|
89
|
+
safeAddress,
|
|
90
|
+
userOperationHash,
|
|
91
|
+
safeOperationHash
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
return (0, utils_1.createSafeClientResult)({
|
|
95
|
+
status: constants_1.SafeClientTxStatus.SAFE_OPERATION_PENDING_SIGNATURES,
|
|
96
|
+
safeAddress,
|
|
97
|
+
safeOperationHash
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Retrieves the pending Safe operations for the current Safe account
|
|
102
|
+
*
|
|
103
|
+
* @async
|
|
104
|
+
* @param {ListOptions} options The pagination options
|
|
105
|
+
* @returns {Promise<GetSafeOperationListResponse>} A promise that resolves to an array of pending Safe operations.
|
|
106
|
+
* @throws {Error} If there is an issue retrieving the safe address or pending Safe operations.
|
|
107
|
+
*/
|
|
108
|
+
async getPendingSafeOperations(options) {
|
|
109
|
+
const safeAddress = await this.protocolKit.getAddress();
|
|
110
|
+
return this.apiKit.getSafeOperationsByAddress({ safeAddress, ...options });
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
exports.SafeOperationClient = SafeOperationClient;
|
|
114
|
+
_SafeOperationClient_instances = new WeakSet(), _SafeOperationClient_waitForOperationToFinish =
|
|
115
|
+
/**
|
|
116
|
+
* Helper method to wait for the operation to finish
|
|
117
|
+
* @param userOperationHash The userOperationHash to wait for. This comes from the bundler and can be obtained from the
|
|
118
|
+
* SafeClientResult method under the safeOperations property
|
|
119
|
+
*/
|
|
120
|
+
async function _SafeOperationClient_waitForOperationToFinish({ userOperationHash }) {
|
|
121
|
+
let userOperationReceipt = null;
|
|
122
|
+
while (!userOperationReceipt) {
|
|
123
|
+
await new Promise((resolve) => setTimeout(resolve, 2000));
|
|
124
|
+
userOperationReceipt = await this.safe4337Pack.getUserOperationReceipt(userOperationHash);
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
//# sourceMappingURL=SafeOperationClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SafeOperationClient.js","sourceRoot":"","sources":["../../../../src/extensions/safe-operations/SafeOperationClient.ts"],"names":[],"mappings":";;;;;;;;;AAAA,4DAAqE;AAIrE,8DAA2E;AAC3E,sEAA2E;AAO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AW,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,UAAU,EAAE,CAAA;QAEvD,OAAO,IAAI,CAAC,MAAM,CAAC,0BAA0B,CAAC,EAAE,WAAW,EAAE,GAAG,OAAO,EAAE,CAAC,CAAA;IAC5E,CAAC;CAkBF;AA3ID,kDA2IC;;AAhBC;;;;GAIG;AACH,KAAK,wDAA2B,EAC9B,iBAAiB,EAGlB;IACC,IAAI,oBAAoB,GAAG,IAAI,CAAA;IAC/B,OAAO,CAAC,oBAAoB,EAAE,CAAC;QAC7B,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,CAAA;QACzD,oBAAoB,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,uBAAuB,CAAC,iBAAiB,CAAC,CAAA;IAC3F,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { GetSafeOperationListResponse, ListOptions } from '@safe-global/api-kit';
|
|
2
|
+
import { PaymasterOptions } from '@safe-global/relay-kit';
|
|
3
|
+
import { SafeClient } from '../../SafeClient';
|
|
4
|
+
import { ConfirmSafeOperationProps, SafeClientResult, SendSafeOperationProps } from '../../types';
|
|
5
|
+
export type BundlerOptions = {
|
|
6
|
+
bundlerUrl: string;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Extend the SafeClient with the ability to use a bundler and a paymaster
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* const safeClient = await createSafeClient({ ... })
|
|
13
|
+
*
|
|
14
|
+
* const safeOperationClient = await safeClient.extend(
|
|
15
|
+
* safeOperations({ ... }, { ... })
|
|
16
|
+
* )
|
|
17
|
+
*
|
|
18
|
+
* const { safeOperations } = await safeOperationClient.sendSafeOperation({ transactions })
|
|
19
|
+
* await safeOperationClient.confirmSafeOperation({ safeOperationHash: safeOperations?.safeOperationHash})
|
|
20
|
+
*/
|
|
21
|
+
export declare function safeOperations({ bundlerUrl }: BundlerOptions, paymasterOptions?: PaymasterOptions): (client: SafeClient) => Promise<{
|
|
22
|
+
/**
|
|
23
|
+
* Send SafeOperations from a group of transactions.
|
|
24
|
+
* This method will convert your transactions in a batch and:
|
|
25
|
+
* - If the threshold > 1 it will save for later the SafeOperation using the Transaction service
|
|
26
|
+
* You must confirmSafeOperation() with other owners
|
|
27
|
+
* - If the threshold = 1 the SafeOperation can be submitted to the bundler so it will execute it immediately
|
|
28
|
+
*
|
|
29
|
+
* @param {Safe4337CreateTransactionProps} props The Safe4337CreateTransactionProps object
|
|
30
|
+
* @returns {Promise<SafeClientResult>} A promise that resolves with the status of the SafeOperation
|
|
31
|
+
*/
|
|
32
|
+
sendSafeOperation(props: SendSafeOperationProps): Promise<SafeClientResult>;
|
|
33
|
+
/**
|
|
34
|
+
* Confirms the stored safeOperation
|
|
35
|
+
*
|
|
36
|
+
* @param {ConfirmSafeOperationProps} props The ConfirmSafeOperationProps object
|
|
37
|
+
* @returns {Promise<SafeClientResult>} A promise that resolves to the result of the safeOperation.
|
|
38
|
+
*/
|
|
39
|
+
confirmSafeOperation(props: ConfirmSafeOperationProps): Promise<SafeClientResult>;
|
|
40
|
+
/**
|
|
41
|
+
* Retrieves the pending Safe operations for the current Safe account
|
|
42
|
+
*
|
|
43
|
+
* @async
|
|
44
|
+
* @param {ListOptions} options The pagination options
|
|
45
|
+
* @returns {Promise<GetSafeOperationListResponse>} A promise that resolves to an array of pending Safe operations.
|
|
46
|
+
* @throws {Error} If there is an issue retrieving the safe address or pending Safe operations.
|
|
47
|
+
*/
|
|
48
|
+
getPendingSafeOperations(options?: ListOptions): Promise<GetSafeOperationListResponse>;
|
|
49
|
+
}>;
|