@safe-global/api-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/LICENSE.md ADDED
@@ -0,0 +1,9 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021-2023 Safe Ecosystem Foundation
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,311 @@
1
+ # Safe API Kit
2
+
3
+ [![NPM Version](https://badge.fury.io/js/%40safe-global%2Fapi-kit.svg)](https://badge.fury.io/js/%40safe-global%2Fapi-kit)
4
+ [![GitHub Release](https://img.shields.io/github/release/safe-global/safe-core-sdk.svg?style=flat)](https://github.com/safe-global/safe-core-sdk/releases)
5
+ [![GitHub](https://img.shields.io/github/license/safe-global/safe-core-sdk)](https://github.com/safe-global/safe-core-sdk/blob/main/LICENSE.md)
6
+
7
+ Software development kit that facilitates the interaction with the [Safe Transaction Service API](https://github.com/safe-global/safe-transaction-service).
8
+
9
+ ## Table of contents
10
+
11
+ - [Installation](#installation)
12
+ - [Build](#build)
13
+ - [Initialization](#initialization)
14
+ - [API Reference](#api-reference)
15
+ - [License](#license)
16
+ - [Contributors](#contributors)
17
+
18
+ ## <a name="installation">Installation</a>
19
+
20
+ Install the package with yarn or npm:
21
+
22
+ ```bash
23
+ yarn install
24
+ npm install
25
+ ```
26
+
27
+ ## <a name="build">Build</a>
28
+
29
+ Build the package with yarn or npm:
30
+
31
+ ```bash
32
+ yarn build
33
+ npm build
34
+ ```
35
+
36
+ ## <a name="initialization">Initialization</a>
37
+
38
+ ### Instantiate an EthAdapter
39
+
40
+ First of all, we need to create an `EthAdapter`, which contains all the required utilities for the SDKs to interact with the blockchain. It acts as a wrapper for [web3.js](https://web3js.readthedocs.io/) or [ethers.js](https://docs.ethers.io/v5/) Ethereum libraries.
41
+
42
+ Depending on the library used by the Dapp, there are two options:
43
+
44
+ - [Create an `EthersAdapter` instance](https://github.com/safe-global/safe-core-sdk/tree/main/packages/protocol-kit/src/adapters/ethers)
45
+ - [Create a `Web3Adapter` instance](https://github.com/safe-global/safe-core-sdk/tree/main/packages/protocol-kit/src/adapters/web3)
46
+
47
+ Once the instance of `EthersAdapter` or `Web3Adapter` is created, it can be used in the SDK initialization.
48
+
49
+ ### Initialize the SafeApiKit
50
+
51
+ ```js
52
+ import SafeApiKit from '@safe-global/api-kit'
53
+
54
+ const safeService = new SafeApiKit({
55
+ txServiceUrl: 'https://safe-transaction-mainnet.safe.global',
56
+ ethAdapter
57
+ })
58
+ ```
59
+
60
+ ## <a name="api-reference">API Reference</a>
61
+
62
+ ### getServiceInfo
63
+
64
+ Returns the information and configuration of the service.
65
+
66
+ ```js
67
+ const serviceInfo: SafeServiceInfoResponse = await safeService.getServiceInfo()
68
+ ```
69
+
70
+ ### getServiceMasterCopiesInfo
71
+
72
+ Returns the list of Safe master copies.
73
+
74
+ ```js
75
+ const masterCopies: MasterCopyResponse = await safeService.getServiceMasterCopiesInfo()
76
+ ```
77
+
78
+ ### decodeData
79
+
80
+ Decodes the specified Safe transaction data.
81
+
82
+ ```js
83
+ const decodedData = await safeService.decodeData(data)
84
+ ```
85
+
86
+ ### getSafesByOwner
87
+
88
+ Returns the list of Safes where the address provided is an owner.
89
+
90
+ ```js
91
+ const safes: OwnerResponse = await safeService.getSafesByOwner(ownerAddress)
92
+ ```
93
+
94
+ ### getSafesByModule
95
+
96
+ Returns the list of Safes where the module address provided is enabled.
97
+
98
+ ```js
99
+ const safes: ModulesResponse = await getSafesByModule(moduleAddress)
100
+ ```
101
+
102
+ ### getTransaction
103
+
104
+ Returns all the information of a Safe transaction.
105
+
106
+ ```js
107
+ const tx: SafeMultisigTransactionResponse = await safeService.getTransaction(safeTxHash)
108
+ ```
109
+
110
+ ### getTransactionConfirmations
111
+
112
+ Returns the list of confirmations for a given a Safe transaction.
113
+
114
+ ```js
115
+ const confirmations: SafeMultisigConfirmationListResponse =
116
+ await safeService.getTransactionConfirmations(safeTxHash)
117
+ ```
118
+
119
+ ### confirmTransaction
120
+
121
+ Adds a confirmation for a Safe transaction.
122
+
123
+ ```js
124
+ const signature: SignatureResponse = await safeService.confirmTransaction(safeTxHash, signature)
125
+ ```
126
+
127
+ ### getSafeInfo
128
+
129
+ Returns the information and configuration of the provided Safe address.
130
+
131
+ ```js
132
+ const safeInfo: SafeInfoResponse = await safeService.getSafeInfo(safeAddress)
133
+ ```
134
+
135
+ ### getSafeDelegates
136
+
137
+ Returns the list of delegates for a given Safe address.
138
+
139
+ ```js
140
+ const delegateConfig: GetSafeDelegateProps = {
141
+ safeAddress, // Optional
142
+ delegateAddress, // Optional
143
+ delegatorAddress, // Optional
144
+ label, // Optional
145
+ limit, // Optional
146
+ offset // Optional
147
+ }
148
+ const delegates: SafeDelegateListResponse = await safeService.getSafeDelegates(delegateConfig)
149
+ ```
150
+
151
+ ### addSafeDelegate
152
+
153
+ Adds a new delegate for a given Safe address.
154
+
155
+ ```js
156
+ const delegateConfig: AddSafeDelegateProps = {
157
+ safeAddress, // Optional
158
+ delegateAddress,
159
+ delegatorAddress,
160
+ label,
161
+ signer
162
+ }
163
+ await safeService.addSafeDelegate(delegateConfig)
164
+ ```
165
+
166
+ ### removeSafeDelegate
167
+
168
+ Removes a delegate for a given Safe address.
169
+
170
+ ```js
171
+ const delegateConfig: DeleteSafeDelegateProps = {
172
+ delegateAddress,
173
+ delegatorAddress,
174
+ signer
175
+ }
176
+ await safeService.removeSafeDelegate(delegateConfig)
177
+ ```
178
+
179
+ ### getSafeCreationInfo
180
+
181
+ Returns the creation information of a Safe.
182
+
183
+ ```js
184
+ const safeCreationInfo: SafeCreationInfoResponse = await safeService.getSafeCreationInfo(
185
+ safeAddress
186
+ )
187
+ ```
188
+
189
+ ### estimateSafeTransaction
190
+
191
+ Estimates the safeTxGas for a given Safe multi-signature transaction.
192
+
193
+ ```js
194
+ const estimateTx: SafeMultisigTransactionEstimateResponse =
195
+ await safeService.estimateSafeTransaction(safeAddress, safeTransaction)
196
+ ```
197
+
198
+ ### proposeTransaction
199
+
200
+ Creates a new multi-signature transaction and stores it in the Safe Transaction Service.
201
+
202
+ ```js
203
+ const transactionConfig: ProposeTransactionProps = {
204
+ safeAddress,
205
+ safeTxHash,
206
+ safeTransactionData,
207
+ senderAddress,
208
+ senderSignature,
209
+ origin
210
+ }
211
+ await safeService.proposeTransaction(transactionConfig)
212
+ ```
213
+
214
+ ### getIncomingTransactions
215
+
216
+ Returns the history of incoming transactions of a Safe account.
217
+
218
+ ```js
219
+ const incomingTxs: TransferListResponse = await safeService.getIncomingTransactions(safeAddress)
220
+ ```
221
+
222
+ ### getModuleTransactions
223
+
224
+ Returns the history of module transactions of a Safe account.
225
+
226
+ ```js
227
+ const moduleTxs: SafeModuleTransactionListResponse = await safeService.getModuleTransactions(
228
+ safeAddress
229
+ )
230
+ ```
231
+
232
+ ### getMultisigTransactions
233
+
234
+ Returns the history of multi-signature transactions of a Safe account.
235
+
236
+ ```js
237
+ const multisigTxs: SafeMultisigTransactionListResponse = await safeService.getMultisigTransactions(
238
+ safeAddress
239
+ )
240
+ ```
241
+
242
+ ### getPendingTransactions
243
+
244
+ Returns the list of multi-signature transactions that are waiting for the confirmation of the Safe owners.
245
+
246
+ ```js
247
+ const pendingTxs: SafeMultisigTransactionListResponse = await safeService.getPendingTransactions(
248
+ safeAddress
249
+ )
250
+ ```
251
+
252
+ ```js
253
+ const pendingTxs: SafeMultisigTransactionListResponse = await safeService.getPendingTransactions(
254
+ safeAddress,
255
+ currentNonce
256
+ )
257
+ ```
258
+
259
+ ### getAllTransactions
260
+
261
+ Returns a list of transactions for a Safe. The list has different structures depending on the transaction type.
262
+
263
+ ```js
264
+ const allTxs: SafeMultisigTransactionListResponse = await safeService.getAllTransactions(
265
+ safeAddress
266
+ )
267
+ ```
268
+
269
+ ```js
270
+ const allTxsOptions: AllTransactionsOptions = {
271
+ executed,
272
+ queued,
273
+ trusted
274
+ }
275
+ const allTxs: SafeMultisigTransactionListResponse = await safeService.getAllTransactions(
276
+ safeAddress,
277
+ allTxsOptions
278
+ )
279
+ ```
280
+
281
+ ### getNextNonce
282
+
283
+ Returns the right nonce to propose a new transaction right after the last pending transaction.
284
+
285
+ ```js
286
+ const nextNonce = await safeService.getNextNonce(safeAddress)
287
+ ```
288
+
289
+ ### getTokenList
290
+
291
+ Returns the list of all the ERC20 tokens handled by the Safe.
292
+
293
+ ```js
294
+ const tokens: TokenInfoListResponse = await safeService.getTokenList()
295
+ ```
296
+
297
+ ### getToken
298
+
299
+ Returns the information of a given ERC20 token.
300
+
301
+ ```js
302
+ const token: TokenInfoResponse = await safeService.getToken(tokenAddress)
303
+ ```
304
+
305
+ ## <a name="license">License</a>
306
+
307
+ This library is released under MIT.
308
+
309
+ ## <a name="contributors">Contributors</a>
310
+
311
+ - Germán Martínez ([germartinez](https://github.com/germartinez))
@@ -0,0 +1,232 @@
1
+ import { AddSafeDelegateProps, AllTransactionsListResponse, AllTransactionsOptions, DeleteSafeDelegateProps, GetSafeDelegateProps, MasterCopyResponse, ModulesResponse, OwnerResponse, ProposeTransactionProps, SafeCreationInfoResponse, SafeDelegateListResponse, SafeDelegateResponse, SafeInfoResponse, SafeModuleTransactionListResponse, SafeMultisigTransactionEstimate, SafeMultisigTransactionEstimateResponse, SafeMultisigTransactionListResponse, SafeServiceInfoResponse, SignatureResponse, TokenInfoListResponse, TokenInfoResponse, TransferListResponse } from '@safe-global/api-kit/types/safeTransactionServiceTypes';
2
+ import { EthAdapter, SafeMultisigConfirmationListResponse, SafeMultisigTransactionResponse } from '@safe-global/safe-core-sdk-types';
3
+ export interface SafeApiKitConfig {
4
+ /** txServiceUrl - Safe Transaction Service URL */
5
+ txServiceUrl: string;
6
+ /** ethAdapter - Ethereum adapter */
7
+ ethAdapter: EthAdapter;
8
+ }
9
+ declare class SafeApiKit {
10
+ #private;
11
+ constructor({ txServiceUrl, ethAdapter }: SafeApiKitConfig);
12
+ /**
13
+ * Returns the information and configuration of the service.
14
+ *
15
+ * @returns The information and configuration of the service
16
+ */
17
+ getServiceInfo(): Promise<SafeServiceInfoResponse>;
18
+ /**
19
+ * Returns the list of Safe master copies.
20
+ *
21
+ * @returns The list of Safe master copies
22
+ */
23
+ getServiceMasterCopiesInfo(): Promise<MasterCopyResponse[]>;
24
+ /**
25
+ * Decodes the specified Safe transaction data.
26
+ *
27
+ * @param data - The Safe transaction data
28
+ * @returns The transaction data decoded
29
+ * @throws "Invalid data"
30
+ * @throws "Not Found"
31
+ * @throws "Ensure this field has at least 1 hexadecimal chars (not counting 0x)."
32
+ */
33
+ decodeData(data: string): Promise<any>;
34
+ /**
35
+ * Returns the list of Safes where the address provided is an owner.
36
+ *
37
+ * @param ownerAddress - The owner address
38
+ * @returns The list of Safes where the address provided is an owner
39
+ * @throws "Invalid owner address"
40
+ * @throws "Checksum address validation failed"
41
+ */
42
+ getSafesByOwner(ownerAddress: string): Promise<OwnerResponse>;
43
+ /**
44
+ * Returns the list of Safes where the module address provided is enabled.
45
+ *
46
+ * @param moduleAddress - The Safe module address
47
+ * @returns The list of Safe addresses where the module provided is enabled
48
+ * @throws "Invalid module address"
49
+ * @throws "Module address checksum not valid"
50
+ */
51
+ getSafesByModule(moduleAddress: string): Promise<ModulesResponse>;
52
+ /**
53
+ * Returns all the information of a Safe transaction.
54
+ *
55
+ * @param safeTxHash - Hash of the Safe transaction
56
+ * @returns The information of a Safe transaction
57
+ * @throws "Invalid safeTxHash"
58
+ * @throws "Not found."
59
+ */
60
+ getTransaction(safeTxHash: string): Promise<SafeMultisigTransactionResponse>;
61
+ /**
62
+ * Returns the list of confirmations for a given a Safe transaction.
63
+ *
64
+ * @param safeTxHash - The hash of the Safe transaction
65
+ * @returns The list of confirmations
66
+ * @throws "Invalid safeTxHash"
67
+ */
68
+ getTransactionConfirmations(safeTxHash: string): Promise<SafeMultisigConfirmationListResponse>;
69
+ /**
70
+ * Adds a confirmation for a Safe transaction.
71
+ *
72
+ * @param safeTxHash - Hash of the Safe transaction that will be confirmed
73
+ * @param signature - Signature of the transaction
74
+ * @returns
75
+ * @throws "Invalid safeTxHash"
76
+ * @throws "Invalid signature"
77
+ * @throws "Malformed data"
78
+ * @throws "Error processing data"
79
+ */
80
+ confirmTransaction(safeTxHash: string, signature: string): Promise<SignatureResponse>;
81
+ /**
82
+ * Returns the information and configuration of the provided Safe address.
83
+ *
84
+ * @param safeAddress - The Safe address
85
+ * @returns The information and configuration of the provided Safe address
86
+ * @throws "Invalid Safe address"
87
+ * @throws "Checksum address validation failed"
88
+ */
89
+ getSafeInfo(safeAddress: string): Promise<SafeInfoResponse>;
90
+ /**
91
+ * Returns the list of delegates.
92
+ *
93
+ * @param getSafeDelegateProps - Properties to filter the returned list of delegates
94
+ * @returns The list of delegates
95
+ * @throws "Checksum address validation failed"
96
+ */
97
+ getSafeDelegates({ safeAddress, delegateAddress, delegatorAddress, label, limit, offset }: GetSafeDelegateProps): Promise<SafeDelegateListResponse>;
98
+ /**
99
+ * Adds a new delegate for a given Safe address.
100
+ *
101
+ * @param addSafeDelegateProps - The configuration of the new delegate
102
+ * @returns
103
+ * @throws "Invalid Safe delegate address"
104
+ * @throws "Invalid Safe delegator address"
105
+ * @throws "Invalid label"
106
+ * @throws "Checksum address validation failed"
107
+ * @throws "Address <delegate_address> is not checksumed"
108
+ * @throws "Safe=<safe_address> does not exist or it's still not indexed"
109
+ * @throws "Signing owner is not an owner of the Safe"
110
+ */
111
+ addSafeDelegate({ safeAddress, delegateAddress, delegatorAddress, label, signer }: AddSafeDelegateProps): Promise<SafeDelegateResponse>;
112
+ /**
113
+ * Removes a delegate for a given Safe address.
114
+ *
115
+ * @param deleteSafeDelegateProps - The configuration for the delegate that will be removed
116
+ * @returns
117
+ * @throws "Invalid Safe delegate address"
118
+ * @throws "Invalid Safe delegator address"
119
+ * @throws "Checksum address validation failed"
120
+ * @throws "Signing owner is not an owner of the Safe"
121
+ * @throws "Not found"
122
+ */
123
+ removeSafeDelegate({ delegateAddress, delegatorAddress, signer }: DeleteSafeDelegateProps): Promise<void>;
124
+ /**
125
+ * Returns the creation information of a Safe.
126
+ *
127
+ * @param safeAddress - The Safe address
128
+ * @returns The creation information of a Safe
129
+ * @throws "Invalid Safe address"
130
+ * @throws "Safe creation not found"
131
+ * @throws "Checksum address validation failed"
132
+ * @throws "Problem connecting to Ethereum network"
133
+ */
134
+ getSafeCreationInfo(safeAddress: string): Promise<SafeCreationInfoResponse>;
135
+ /**
136
+ * Estimates the safeTxGas for a given Safe multi-signature transaction.
137
+ *
138
+ * @param safeAddress - The Safe address
139
+ * @param safeTransaction - The Safe transaction to estimate
140
+ * @returns The safeTxGas for the given Safe transaction
141
+ * @throws "Invalid Safe address"
142
+ * @throws "Data not valid"
143
+ * @throws "Safe not found"
144
+ * @throws "Tx not valid"
145
+ */
146
+ estimateSafeTransaction(safeAddress: string, safeTransaction: SafeMultisigTransactionEstimate): Promise<SafeMultisigTransactionEstimateResponse>;
147
+ /**
148
+ * Creates a new multi-signature transaction with its confirmations and stores it in the Safe Transaction Service.
149
+ *
150
+ * @param proposeTransactionConfig - The configuration of the proposed transaction
151
+ * @returns The hash of the Safe transaction proposed
152
+ * @throws "Invalid Safe address"
153
+ * @throws "Invalid safeTxHash"
154
+ * @throws "Invalid data"
155
+ * @throws "Invalid ethereum address/User is not an owner/Invalid signature/Nonce already executed/Sender is not an owner"
156
+ */
157
+ proposeTransaction({ safeAddress, safeTransactionData, safeTxHash, senderAddress, senderSignature, origin }: ProposeTransactionProps): Promise<void>;
158
+ /**
159
+ * Returns the history of incoming transactions of a Safe account.
160
+ *
161
+ * @param safeAddress - The Safe address
162
+ * @returns The history of incoming transactions
163
+ * @throws "Invalid Safe address"
164
+ * @throws "Checksum address validation failed"
165
+ */
166
+ getIncomingTransactions(safeAddress: string): Promise<TransferListResponse>;
167
+ /**
168
+ * Returns the history of module transactions of a Safe account.
169
+ *
170
+ * @param safeAddress - The Safe address
171
+ * @returns The history of module transactions
172
+ * @throws "Invalid Safe address"
173
+ * @throws "Invalid data"
174
+ * @throws "Invalid ethereum address"
175
+ */
176
+ getModuleTransactions(safeAddress: string): Promise<SafeModuleTransactionListResponse>;
177
+ /**
178
+ * Returns the history of multi-signature transactions of a Safe account.
179
+ *
180
+ * @param safeAddress - The Safe address
181
+ * @returns The history of multi-signature transactions
182
+ * @throws "Invalid Safe address"
183
+ * @throws "Checksum address validation failed"
184
+ */
185
+ getMultisigTransactions(safeAddress: string): Promise<SafeMultisigTransactionListResponse>;
186
+ /**
187
+ * Returns the list of multi-signature transactions that are waiting for the confirmation of the Safe owners.
188
+ *
189
+ * @param safeAddress - The Safe address
190
+ * @param currentNonce - Current nonce of the Safe
191
+ * @returns The list of transactions waiting for the confirmation of the Safe owners
192
+ * @throws "Invalid Safe address"
193
+ * @throws "Invalid data"
194
+ * @throws "Invalid ethereum address"
195
+ */
196
+ getPendingTransactions(safeAddress: string, currentNonce?: number): Promise<SafeMultisigTransactionListResponse>;
197
+ /**
198
+ * Returns a list of transactions for a Safe. The list has different structures depending on the transaction type
199
+ *
200
+ * @param safeAddress - The Safe address
201
+ * @returns The list of transactions waiting for the confirmation of the Safe owners
202
+ * @throws "Invalid Safe address"
203
+ * @throws "Checksum address validation failed"
204
+ */
205
+ getAllTransactions(safeAddress: string, options?: AllTransactionsOptions): Promise<AllTransactionsListResponse>;
206
+ /**
207
+ * Returns the right nonce to propose a new transaction after the last pending transaction.
208
+ *
209
+ * @param safeAddress - The Safe address
210
+ * @returns The right nonce to propose a new transaction after the last pending transaction
211
+ * @throws "Invalid Safe address"
212
+ * @throws "Invalid data"
213
+ * @throws "Invalid ethereum address"
214
+ */
215
+ getNextNonce(safeAddress: string): Promise<number>;
216
+ /**
217
+ * Returns the list of all the ERC20 tokens handled by the Safe.
218
+ *
219
+ * @returns The list of all the ERC20 tokens
220
+ */
221
+ getTokenList(): Promise<TokenInfoListResponse>;
222
+ /**
223
+ * Returns the information of a given ERC20 token.
224
+ *
225
+ * @param tokenAddress - The token address
226
+ * @returns The information of the given ERC20 token
227
+ * @throws "Invalid token address"
228
+ * @throws "Checksum address validation failed"
229
+ */
230
+ getToken(tokenAddress: string): Promise<TokenInfoResponse>;
231
+ }
232
+ export default SafeApiKit;