@rabby-wallet/gnosis-sdk 1.4.7-alpha-1 → 1.4.8-alpha-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/api.d.ts +38 -3
- package/dist/api.js +54 -13
- package/dist/index.d.ts +2 -2
- package/dist/index.js +4 -5
- package/dist/utils.js +1 -1
- package/package.json +1 -1
- package/src/api.ts +100 -18
- package/src/index.ts +24 -21
- package/src/utils.ts +1 -1
package/dist/api.d.ts
CHANGED
|
@@ -41,6 +41,39 @@ export interface SafeTransactionItem {
|
|
|
41
41
|
confirmations: ConfirmationItem[];
|
|
42
42
|
signatures: string | null;
|
|
43
43
|
}
|
|
44
|
+
export type SafeOpenApiService = {
|
|
45
|
+
getSafePendingTransactions?: (params: {
|
|
46
|
+
txServiceUrl: string;
|
|
47
|
+
safeAddress: string;
|
|
48
|
+
nonce: number;
|
|
49
|
+
}) => Promise<{
|
|
50
|
+
results: SafeTransactionItem[];
|
|
51
|
+
}>;
|
|
52
|
+
postSafeTransactions?: (params: {
|
|
53
|
+
txServiceUrl: string;
|
|
54
|
+
safeAddress: string;
|
|
55
|
+
data: Record<string, any>;
|
|
56
|
+
}) => Promise<void>;
|
|
57
|
+
getSafeInfo?: (params: {
|
|
58
|
+
txServiceUrl: string;
|
|
59
|
+
safeAddress: string;
|
|
60
|
+
}) => Promise<SafeInfo>;
|
|
61
|
+
confirmSafeTransaction?: (params: {
|
|
62
|
+
txServiceUrl: string;
|
|
63
|
+
safeTransactionHash: string;
|
|
64
|
+
data: Record<string, any>;
|
|
65
|
+
}) => Promise<void>;
|
|
66
|
+
getSafeTxGas?: (params: {
|
|
67
|
+
txServiceUrl: string;
|
|
68
|
+
safeAddress: string;
|
|
69
|
+
safeTxData: {
|
|
70
|
+
to: string;
|
|
71
|
+
value?: string;
|
|
72
|
+
data?: string | null;
|
|
73
|
+
operation?: number;
|
|
74
|
+
};
|
|
75
|
+
}) => Promise<string | undefined>;
|
|
76
|
+
};
|
|
44
77
|
export declare const GNOSIS_SUPPORT_CHAINS: string[];
|
|
45
78
|
export declare const HOST_MAP: {
|
|
46
79
|
/**
|
|
@@ -50,12 +83,14 @@ export declare const HOST_MAP: {
|
|
|
50
83
|
};
|
|
51
84
|
export declare const getTxServiceUrl: (chainId: string) => any;
|
|
52
85
|
export default class RequestProvider {
|
|
53
|
-
|
|
86
|
+
prefix: string;
|
|
54
87
|
request: Axios;
|
|
55
|
-
|
|
88
|
+
openapiService?: SafeOpenApiService;
|
|
89
|
+
shouldUseOpenapiService: boolean;
|
|
90
|
+
constructor({ networkId, adapter, openapiService, }: {
|
|
56
91
|
networkId: string;
|
|
57
92
|
adapter?: AxiosAdapter;
|
|
58
|
-
|
|
93
|
+
openapiService?: SafeOpenApiService;
|
|
59
94
|
});
|
|
60
95
|
getPendingTransactions(safeAddress: string, nonce: number): Promise<{
|
|
61
96
|
results: SafeTransactionItem[];
|
package/dist/api.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { ethers } from "ethers";
|
|
2
2
|
import { isLegacyVersion } from "./utils";
|
|
3
3
|
import axios from "axios";
|
|
4
|
-
const TRANSACTION_SERVICE_URL = "https://api.rabby.io/v1/safe-tx-service";
|
|
5
4
|
// https://github.com/safe-global/safe-core-sdk/blob/main/packages/api-kit/src/utils/config.ts
|
|
6
5
|
const networks = [
|
|
7
6
|
{
|
|
@@ -208,32 +207,38 @@ export const HOST_MAP = {
|
|
|
208
207
|
export const getTxServiceUrl = (chainId) => {
|
|
209
208
|
const shortName = networkMap[chainId];
|
|
210
209
|
if (shortName) {
|
|
211
|
-
return
|
|
210
|
+
return `/v1/safe-tx-service/${shortName}/api`;
|
|
212
211
|
}
|
|
213
212
|
return HOST_MAP[chainId];
|
|
214
213
|
};
|
|
215
214
|
export default class RequestProvider {
|
|
216
|
-
constructor({ networkId, adapter,
|
|
215
|
+
constructor({ networkId, adapter, openapiService, }) {
|
|
217
216
|
const txServiceUrl = getTxServiceUrl(networkId);
|
|
218
217
|
if (!txServiceUrl) {
|
|
219
218
|
throw new Error("Wrong networkId");
|
|
220
219
|
}
|
|
221
|
-
this.
|
|
220
|
+
this.prefix = txServiceUrl;
|
|
221
|
+
this.openapiService = openapiService;
|
|
222
|
+
this.shouldUseOpenapiService = !/^https?:\/\//i.test(this.prefix);
|
|
222
223
|
this.request = axios.create({
|
|
223
|
-
baseURL: this.
|
|
224
|
+
baseURL: this.prefix,
|
|
224
225
|
adapter,
|
|
225
|
-
headers: apiKey
|
|
226
|
-
? {
|
|
227
|
-
Authorization: `Bearer ${apiKey}`,
|
|
228
|
-
}
|
|
229
|
-
: undefined,
|
|
230
226
|
});
|
|
231
227
|
this.request.interceptors.response.use((response) => {
|
|
232
228
|
return response.data;
|
|
233
229
|
});
|
|
234
230
|
}
|
|
235
231
|
getPendingTransactions(safeAddress, nonce) {
|
|
236
|
-
|
|
232
|
+
const checksumAddress = ethers.utils.getAddress(safeAddress);
|
|
233
|
+
if (this.shouldUseOpenapiService &&
|
|
234
|
+
this.openapiService?.getSafePendingTransactions) {
|
|
235
|
+
return this.openapiService.getSafePendingTransactions({
|
|
236
|
+
txServiceUrl: this.prefix,
|
|
237
|
+
safeAddress: checksumAddress,
|
|
238
|
+
nonce,
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
return this.request.get(`/v1/safes/${checksumAddress}/multisig-transactions/`, {
|
|
237
242
|
params: {
|
|
238
243
|
executed: false,
|
|
239
244
|
nonce__gte: nonce,
|
|
@@ -241,12 +246,36 @@ export default class RequestProvider {
|
|
|
241
246
|
});
|
|
242
247
|
}
|
|
243
248
|
postTransactions(safeAddres, data) {
|
|
244
|
-
|
|
249
|
+
const checksumAddress = ethers.utils.getAddress(safeAddres);
|
|
250
|
+
if (this.shouldUseOpenapiService &&
|
|
251
|
+
this.openapiService?.postSafeTransactions) {
|
|
252
|
+
return this.openapiService.postSafeTransactions({
|
|
253
|
+
txServiceUrl: this.prefix,
|
|
254
|
+
safeAddress: checksumAddress,
|
|
255
|
+
data,
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
return this.request.post(`/v1/safes/${checksumAddress}/multisig-transactions/`, data);
|
|
245
259
|
}
|
|
246
260
|
getSafeInfo(safeAddress) {
|
|
247
|
-
|
|
261
|
+
const checksumAddress = ethers.utils.getAddress(safeAddress);
|
|
262
|
+
if (this.shouldUseOpenapiService && this.openapiService?.getSafeInfo) {
|
|
263
|
+
return this.openapiService.getSafeInfo({
|
|
264
|
+
txServiceUrl: this.prefix,
|
|
265
|
+
safeAddress: checksumAddress,
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
return this.request.get(`/v1/safes/${checksumAddress}/`);
|
|
248
269
|
}
|
|
249
270
|
confirmTransaction(safeTransactionHash, data) {
|
|
271
|
+
if (this.shouldUseOpenapiService &&
|
|
272
|
+
this.openapiService?.confirmSafeTransaction) {
|
|
273
|
+
return this.openapiService.confirmSafeTransaction({
|
|
274
|
+
txServiceUrl: this.prefix,
|
|
275
|
+
safeTransactionHash,
|
|
276
|
+
data,
|
|
277
|
+
});
|
|
278
|
+
}
|
|
250
279
|
return this.request.post(`/v1/multisig-transactions/${safeTransactionHash}/confirmations/`, data);
|
|
251
280
|
}
|
|
252
281
|
// https://github.com/safe-global/safe-wallet-web/blob/dev/src/services/tx/tx-sender/recommendedNonce.ts#L24
|
|
@@ -256,6 +285,18 @@ export default class RequestProvider {
|
|
|
256
285
|
if (!isSafeTxGasRequired)
|
|
257
286
|
return "0";
|
|
258
287
|
const address = ethers.utils.getAddress(safeAddress);
|
|
288
|
+
if (this.shouldUseOpenapiService && this.openapiService?.getSafeTxGas) {
|
|
289
|
+
return this.openapiService.getSafeTxGas({
|
|
290
|
+
txServiceUrl: this.prefix,
|
|
291
|
+
safeAddress: address,
|
|
292
|
+
safeTxData: {
|
|
293
|
+
to: ethers.utils.getAddress(safeTxData.to),
|
|
294
|
+
value: safeTxData.value || "0",
|
|
295
|
+
data: safeTxData.data,
|
|
296
|
+
operation: safeTxData.operation,
|
|
297
|
+
},
|
|
298
|
+
});
|
|
299
|
+
}
|
|
259
300
|
try {
|
|
260
301
|
const estimation = await this.request.post(`/v1/safes/${address}/multisig-transactions/estimations/`, {
|
|
261
302
|
to: ethers.utils.getAddress(safeTxData.to),
|
package/dist/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { Contract, providers } from "ethers";
|
|
|
4
4
|
import { TransactionOptions, TransactionResult, SafeSignature, SafeTransaction, SafeTransactionDataPartial } from "@safe-global/types-kit";
|
|
5
5
|
import { EthSafeMessage, EthSafeTransaction } from "@safe-global/protocol-kit";
|
|
6
6
|
import SafeApiKit, { SafeMessage as ApiKitSafeMessage } from "@safe-global/api-kit";
|
|
7
|
-
import RequestProvider, { SafeInfo } from "./api";
|
|
7
|
+
import RequestProvider, { SafeInfo, SafeOpenApiService } from "./api";
|
|
8
8
|
declare class Safe {
|
|
9
9
|
contract: Contract;
|
|
10
10
|
safeAddress: string;
|
|
@@ -16,7 +16,7 @@ declare class Safe {
|
|
|
16
16
|
network: string;
|
|
17
17
|
apiKit: SafeApiKit;
|
|
18
18
|
static adapter: AxiosAdapter;
|
|
19
|
-
static
|
|
19
|
+
static openapiService?: SafeOpenApiService;
|
|
20
20
|
constructor(safeAddress: string, version: string, provider: providers.Web3Provider, network?: string);
|
|
21
21
|
/**
|
|
22
22
|
* @deprecated
|
package/dist/index.js
CHANGED
|
@@ -5,7 +5,7 @@ import { calculateSafeMessageHash } from "@safe-global/protocol-kit/dist/src/uti
|
|
|
5
5
|
import SafeApiKit from "@safe-global/api-kit";
|
|
6
6
|
// import { getTransactionServiceUrl } from "@safe-global/api-kit/dist/src/utils/config";
|
|
7
7
|
import { getSafeSingletonDeployment } from "@safe-global/safe-deployments";
|
|
8
|
-
import RequestProvider, { getTxServiceUrl } from "./api";
|
|
8
|
+
import RequestProvider, { getTxServiceUrl, } from "./api";
|
|
9
9
|
import { generatePreValidatedSignature, generateSignature, sameString, standardizeSafeTransactionData, } from "./utils";
|
|
10
10
|
class Safe {
|
|
11
11
|
constructor(safeAddress, version, provider, network = "1") {
|
|
@@ -56,7 +56,7 @@ class Safe {
|
|
|
56
56
|
this.request = new RequestProvider({
|
|
57
57
|
networkId: network,
|
|
58
58
|
adapter: Safe.adapter,
|
|
59
|
-
|
|
59
|
+
openapiService: Safe.openapiService,
|
|
60
60
|
});
|
|
61
61
|
this.apiKit = Safe.createSafeApiKit(network);
|
|
62
62
|
// this.init();
|
|
@@ -71,7 +71,7 @@ class Safe {
|
|
|
71
71
|
const request = new RequestProvider({
|
|
72
72
|
networkId: network,
|
|
73
73
|
adapter: Safe.adapter,
|
|
74
|
-
|
|
74
|
+
openapiService: Safe.openapiService,
|
|
75
75
|
});
|
|
76
76
|
return request.getSafeInfo(ethers.utils.getAddress(safeAddress));
|
|
77
77
|
}
|
|
@@ -79,7 +79,7 @@ class Safe {
|
|
|
79
79
|
const request = new RequestProvider({
|
|
80
80
|
networkId: network,
|
|
81
81
|
adapter: Safe.adapter,
|
|
82
|
-
|
|
82
|
+
openapiService: Safe.openapiService,
|
|
83
83
|
});
|
|
84
84
|
const transactions = await request.getPendingTransactions(safeAddress, nonce);
|
|
85
85
|
return transactions;
|
|
@@ -263,7 +263,6 @@ Safe.createSafeApiKit = (network) => {
|
|
|
263
263
|
return new SafeApiKit({
|
|
264
264
|
chainId: BigInt(network),
|
|
265
265
|
txServiceUrl: getTxServiceUrl(network) || undefined,
|
|
266
|
-
apiKey: Safe.apiKey,
|
|
267
266
|
});
|
|
268
267
|
};
|
|
269
268
|
export default Safe;
|
package/dist/utils.js
CHANGED
|
@@ -100,7 +100,7 @@ export async function standardizeSafeTransactionData(safeAddress, safeContract,
|
|
|
100
100
|
const request = new RequestProvider({
|
|
101
101
|
networkId: network,
|
|
102
102
|
adapter: Safe.adapter,
|
|
103
|
-
|
|
103
|
+
openapiService: Safe.openapiService,
|
|
104
104
|
});
|
|
105
105
|
const safeTxGas = tx.safeTxGas ??
|
|
106
106
|
(await request.getSafeTxGas(safeAddress, version, standardizedTxs));
|
package/package.json
CHANGED
package/src/api.ts
CHANGED
|
@@ -47,7 +47,37 @@ export interface SafeTransactionItem {
|
|
|
47
47
|
signatures: string | null;
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
|
|
50
|
+
export type SafeOpenApiService = {
|
|
51
|
+
getSafePendingTransactions?: (params: {
|
|
52
|
+
txServiceUrl: string;
|
|
53
|
+
safeAddress: string;
|
|
54
|
+
nonce: number;
|
|
55
|
+
}) => Promise<{ results: SafeTransactionItem[] }>;
|
|
56
|
+
postSafeTransactions?: (params: {
|
|
57
|
+
txServiceUrl: string;
|
|
58
|
+
safeAddress: string;
|
|
59
|
+
data: Record<string, any>;
|
|
60
|
+
}) => Promise<void>;
|
|
61
|
+
getSafeInfo?: (params: {
|
|
62
|
+
txServiceUrl: string;
|
|
63
|
+
safeAddress: string;
|
|
64
|
+
}) => Promise<SafeInfo>;
|
|
65
|
+
confirmSafeTransaction?: (params: {
|
|
66
|
+
txServiceUrl: string;
|
|
67
|
+
safeTransactionHash: string;
|
|
68
|
+
data: Record<string, any>;
|
|
69
|
+
}) => Promise<void>;
|
|
70
|
+
getSafeTxGas?: (params: {
|
|
71
|
+
txServiceUrl: string;
|
|
72
|
+
safeAddress: string;
|
|
73
|
+
safeTxData: {
|
|
74
|
+
to: string;
|
|
75
|
+
value?: string;
|
|
76
|
+
data?: string | null;
|
|
77
|
+
operation?: number;
|
|
78
|
+
};
|
|
79
|
+
}) => Promise<string | undefined>;
|
|
80
|
+
};
|
|
51
81
|
|
|
52
82
|
type NetworkShortName = {
|
|
53
83
|
shortName: string;
|
|
@@ -267,40 +297,38 @@ export const HOST_MAP = {
|
|
|
267
297
|
export const getTxServiceUrl = (chainId: string) => {
|
|
268
298
|
const shortName = networkMap[chainId];
|
|
269
299
|
if (shortName) {
|
|
270
|
-
return
|
|
300
|
+
return `/v1/safe-tx-service/${shortName}/api`;
|
|
271
301
|
}
|
|
272
302
|
return HOST_MAP[chainId];
|
|
273
303
|
};
|
|
274
304
|
|
|
275
305
|
export default class RequestProvider {
|
|
276
|
-
|
|
306
|
+
prefix: string;
|
|
277
307
|
request: Axios;
|
|
308
|
+
openapiService?: SafeOpenApiService;
|
|
309
|
+
shouldUseOpenapiService: boolean;
|
|
278
310
|
|
|
279
311
|
constructor({
|
|
280
312
|
networkId,
|
|
281
313
|
adapter,
|
|
282
|
-
|
|
314
|
+
openapiService,
|
|
283
315
|
}: {
|
|
284
316
|
networkId: string;
|
|
285
317
|
adapter?: AxiosAdapter;
|
|
286
|
-
|
|
318
|
+
openapiService?: SafeOpenApiService;
|
|
287
319
|
}) {
|
|
288
320
|
const txServiceUrl = getTxServiceUrl(networkId);
|
|
289
321
|
if (!txServiceUrl) {
|
|
290
322
|
throw new Error("Wrong networkId");
|
|
291
323
|
}
|
|
292
324
|
|
|
293
|
-
this.
|
|
325
|
+
this.prefix = txServiceUrl;
|
|
326
|
+
this.openapiService = openapiService;
|
|
327
|
+
this.shouldUseOpenapiService = !/^https?:\/\//i.test(this.prefix);
|
|
294
328
|
|
|
295
329
|
this.request = axios.create({
|
|
296
|
-
baseURL: this.
|
|
330
|
+
baseURL: this.prefix,
|
|
297
331
|
adapter,
|
|
298
|
-
|
|
299
|
-
headers: apiKey
|
|
300
|
-
? {
|
|
301
|
-
Authorization: `Bearer ${apiKey}`,
|
|
302
|
-
}
|
|
303
|
-
: undefined,
|
|
304
332
|
});
|
|
305
333
|
|
|
306
334
|
this.request.interceptors.response.use((response) => {
|
|
@@ -312,10 +340,20 @@ export default class RequestProvider {
|
|
|
312
340
|
safeAddress: string,
|
|
313
341
|
nonce: number
|
|
314
342
|
): Promise<{ results: SafeTransactionItem[] }> {
|
|
343
|
+
const checksumAddress = ethers.utils.getAddress(safeAddress);
|
|
344
|
+
if (
|
|
345
|
+
this.shouldUseOpenapiService &&
|
|
346
|
+
this.openapiService?.getSafePendingTransactions
|
|
347
|
+
) {
|
|
348
|
+
return this.openapiService.getSafePendingTransactions({
|
|
349
|
+
txServiceUrl: this.prefix,
|
|
350
|
+
safeAddress: checksumAddress,
|
|
351
|
+
nonce,
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
|
|
315
355
|
return this.request.get(
|
|
316
|
-
`/v1/safes/${
|
|
317
|
-
safeAddress
|
|
318
|
-
)}/multisig-transactions/`,
|
|
356
|
+
`/v1/safes/${checksumAddress}/multisig-transactions/`,
|
|
319
357
|
{
|
|
320
358
|
params: {
|
|
321
359
|
executed: false,
|
|
@@ -326,19 +364,50 @@ export default class RequestProvider {
|
|
|
326
364
|
}
|
|
327
365
|
|
|
328
366
|
postTransactions(safeAddres: string, data): Promise<void> {
|
|
367
|
+
const checksumAddress = ethers.utils.getAddress(safeAddres);
|
|
368
|
+
if (
|
|
369
|
+
this.shouldUseOpenapiService &&
|
|
370
|
+
this.openapiService?.postSafeTransactions
|
|
371
|
+
) {
|
|
372
|
+
return this.openapiService.postSafeTransactions({
|
|
373
|
+
txServiceUrl: this.prefix,
|
|
374
|
+
safeAddress: checksumAddress,
|
|
375
|
+
data,
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
|
|
329
379
|
return this.request.post(
|
|
330
|
-
`/v1/safes/${
|
|
380
|
+
`/v1/safes/${checksumAddress}/multisig-transactions/`,
|
|
331
381
|
data
|
|
332
382
|
);
|
|
333
383
|
}
|
|
334
384
|
|
|
335
385
|
getSafeInfo(safeAddress: string): Promise<SafeInfo> {
|
|
386
|
+
const checksumAddress = ethers.utils.getAddress(safeAddress);
|
|
387
|
+
if (this.shouldUseOpenapiService && this.openapiService?.getSafeInfo) {
|
|
388
|
+
return this.openapiService.getSafeInfo({
|
|
389
|
+
txServiceUrl: this.prefix,
|
|
390
|
+
safeAddress: checksumAddress,
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
|
|
336
394
|
return this.request.get(
|
|
337
|
-
`/v1/safes/${
|
|
395
|
+
`/v1/safes/${checksumAddress}/`
|
|
338
396
|
);
|
|
339
397
|
}
|
|
340
398
|
|
|
341
399
|
confirmTransaction(safeTransactionHash: string, data): Promise<void> {
|
|
400
|
+
if (
|
|
401
|
+
this.shouldUseOpenapiService &&
|
|
402
|
+
this.openapiService?.confirmSafeTransaction
|
|
403
|
+
) {
|
|
404
|
+
return this.openapiService.confirmSafeTransaction({
|
|
405
|
+
txServiceUrl: this.prefix,
|
|
406
|
+
safeTransactionHash,
|
|
407
|
+
data,
|
|
408
|
+
});
|
|
409
|
+
}
|
|
410
|
+
|
|
342
411
|
return this.request.post(
|
|
343
412
|
`/v1/multisig-transactions/${safeTransactionHash}/confirmations/`,
|
|
344
413
|
data
|
|
@@ -358,6 +427,19 @@ export default class RequestProvider {
|
|
|
358
427
|
|
|
359
428
|
const address = ethers.utils.getAddress(safeAddress);
|
|
360
429
|
|
|
430
|
+
if (this.shouldUseOpenapiService && this.openapiService?.getSafeTxGas) {
|
|
431
|
+
return this.openapiService.getSafeTxGas({
|
|
432
|
+
txServiceUrl: this.prefix,
|
|
433
|
+
safeAddress: address,
|
|
434
|
+
safeTxData: {
|
|
435
|
+
to: ethers.utils.getAddress(safeTxData.to),
|
|
436
|
+
value: safeTxData.value || "0",
|
|
437
|
+
data: safeTxData.data,
|
|
438
|
+
operation: safeTxData.operation,
|
|
439
|
+
},
|
|
440
|
+
});
|
|
441
|
+
}
|
|
442
|
+
|
|
361
443
|
try {
|
|
362
444
|
const estimation: { safeTxGas: string } = await this.request.post(
|
|
363
445
|
`/v1/safes/${address}/multisig-transactions/estimations/`,
|
package/src/index.ts
CHANGED
|
@@ -16,7 +16,11 @@ import SafeApiKit, {
|
|
|
16
16
|
} from "@safe-global/api-kit";
|
|
17
17
|
// import { getTransactionServiceUrl } from "@safe-global/api-kit/dist/src/utils/config";
|
|
18
18
|
import { getSafeSingletonDeployment } from "@safe-global/safe-deployments";
|
|
19
|
-
import RequestProvider, {
|
|
19
|
+
import RequestProvider, {
|
|
20
|
+
getTxServiceUrl,
|
|
21
|
+
SafeInfo,
|
|
22
|
+
SafeOpenApiService,
|
|
23
|
+
} from "./api";
|
|
20
24
|
import {
|
|
21
25
|
estimateGasForTransactionExecution,
|
|
22
26
|
generatePreValidatedSignature,
|
|
@@ -37,13 +41,13 @@ class Safe {
|
|
|
37
41
|
apiKit: SafeApiKit;
|
|
38
42
|
|
|
39
43
|
static adapter: AxiosAdapter;
|
|
40
|
-
static
|
|
44
|
+
static openapiService?: SafeOpenApiService;
|
|
41
45
|
|
|
42
46
|
constructor(
|
|
43
47
|
safeAddress: string,
|
|
44
48
|
version: string,
|
|
45
49
|
provider: providers.Web3Provider,
|
|
46
|
-
network = "1"
|
|
50
|
+
network = "1",
|
|
47
51
|
) {
|
|
48
52
|
const contract = getSafeSingletonDeployment({
|
|
49
53
|
version,
|
|
@@ -60,7 +64,7 @@ class Safe {
|
|
|
60
64
|
this.request = new RequestProvider({
|
|
61
65
|
networkId: network,
|
|
62
66
|
adapter: Safe.adapter,
|
|
63
|
-
|
|
67
|
+
openapiService: Safe.openapiService,
|
|
64
68
|
});
|
|
65
69
|
this.apiKit = Safe.createSafeApiKit(network);
|
|
66
70
|
|
|
@@ -77,7 +81,7 @@ class Safe {
|
|
|
77
81
|
const request = new RequestProvider({
|
|
78
82
|
networkId: network,
|
|
79
83
|
adapter: Safe.adapter,
|
|
80
|
-
|
|
84
|
+
openapiService: Safe.openapiService,
|
|
81
85
|
});
|
|
82
86
|
return request.getSafeInfo(ethers.utils.getAddress(safeAddress));
|
|
83
87
|
}
|
|
@@ -85,16 +89,16 @@ class Safe {
|
|
|
85
89
|
static async getPendingTransactions(
|
|
86
90
|
safeAddress: string,
|
|
87
91
|
network: string,
|
|
88
|
-
nonce: number
|
|
92
|
+
nonce: number,
|
|
89
93
|
) {
|
|
90
94
|
const request = new RequestProvider({
|
|
91
95
|
networkId: network,
|
|
92
96
|
adapter: Safe.adapter,
|
|
93
|
-
|
|
97
|
+
openapiService: Safe.openapiService,
|
|
94
98
|
});
|
|
95
99
|
const transactions = await request.getPendingTransactions(
|
|
96
100
|
safeAddress,
|
|
97
|
-
nonce
|
|
101
|
+
nonce,
|
|
98
102
|
);
|
|
99
103
|
|
|
100
104
|
return transactions;
|
|
@@ -104,7 +108,6 @@ class Safe {
|
|
|
104
108
|
return new SafeApiKit({
|
|
105
109
|
chainId: BigInt(network),
|
|
106
110
|
txServiceUrl: getTxServiceUrl(network) || undefined,
|
|
107
|
-
apiKey: Safe.apiKey,
|
|
108
111
|
});
|
|
109
112
|
};
|
|
110
113
|
|
|
@@ -112,7 +115,7 @@ class Safe {
|
|
|
112
115
|
const nonce = await this.getNonce();
|
|
113
116
|
const transactions = await this.request.getPendingTransactions(
|
|
114
117
|
this.safeAddress,
|
|
115
|
-
nonce
|
|
118
|
+
nonce,
|
|
116
119
|
);
|
|
117
120
|
|
|
118
121
|
return transactions;
|
|
@@ -144,7 +147,7 @@ class Safe {
|
|
|
144
147
|
type: "function",
|
|
145
148
|
},
|
|
146
149
|
],
|
|
147
|
-
provider
|
|
150
|
+
provider,
|
|
148
151
|
);
|
|
149
152
|
|
|
150
153
|
const version = await contract.VERSION();
|
|
@@ -157,7 +160,7 @@ class Safe {
|
|
|
157
160
|
this.safeInfo = safeInfo;
|
|
158
161
|
if (this.version !== safeInfo.version) {
|
|
159
162
|
throw new Error(
|
|
160
|
-
`Current version ${this.version} not matched address version ${safeInfo.version}
|
|
163
|
+
`Current version ${this.version} not matched address version ${safeInfo.version}`,
|
|
161
164
|
);
|
|
162
165
|
}
|
|
163
166
|
this.version = safeInfo.version;
|
|
@@ -202,7 +205,7 @@ class Safe {
|
|
|
202
205
|
this.provider,
|
|
203
206
|
data,
|
|
204
207
|
this.network,
|
|
205
|
-
this.version
|
|
208
|
+
this.version,
|
|
206
209
|
);
|
|
207
210
|
return new EthSafeTransaction(transaction);
|
|
208
211
|
}
|
|
@@ -219,7 +222,7 @@ class Safe {
|
|
|
219
222
|
transactionData.gasPrice,
|
|
220
223
|
transactionData.gasToken,
|
|
221
224
|
transactionData.refundReceiver,
|
|
222
|
-
transactionData.nonce
|
|
225
|
+
transactionData.nonce,
|
|
223
226
|
);
|
|
224
227
|
}
|
|
225
228
|
|
|
@@ -228,7 +231,7 @@ class Safe {
|
|
|
228
231
|
const signer = await this.provider.getSigner(0);
|
|
229
232
|
const signerAddress = await signer.getAddress();
|
|
230
233
|
const addressIsOwner = owners.find(
|
|
231
|
-
(owner: string) => signerAddress && sameString(owner, signerAddress)
|
|
234
|
+
(owner: string) => signerAddress && sameString(owner, signerAddress),
|
|
232
235
|
);
|
|
233
236
|
if (!addressIsOwner) {
|
|
234
237
|
throw new Error("Transactions can only be signed by Safe owners");
|
|
@@ -294,7 +297,7 @@ class Safe {
|
|
|
294
297
|
|
|
295
298
|
async executeTransaction(
|
|
296
299
|
safeTransaction: SafeTransaction,
|
|
297
|
-
options?: TransactionOptions
|
|
300
|
+
options?: TransactionOptions,
|
|
298
301
|
): Promise<TransactionResult> {
|
|
299
302
|
const txHash = await this.getTransactionHash(safeTransaction);
|
|
300
303
|
const ownersWhoApprovedTx = await this.getOwnersWhoApprovedTx(txHash);
|
|
@@ -307,7 +310,7 @@ class Safe {
|
|
|
307
310
|
const signerAddress = await signer.getAddress();
|
|
308
311
|
if (owners.includes(signerAddress)) {
|
|
309
312
|
safeTransaction.addSignature(
|
|
310
|
-
generatePreValidatedSignature(signerAddress)
|
|
313
|
+
generatePreValidatedSignature(signerAddress),
|
|
311
314
|
);
|
|
312
315
|
}
|
|
313
316
|
|
|
@@ -319,7 +322,7 @@ class Safe {
|
|
|
319
322
|
signaturesMissing > 1 ? "are" : "is"
|
|
320
323
|
} ${signaturesMissing} signature${
|
|
321
324
|
signaturesMissing > 1 ? "s" : ""
|
|
322
|
-
} missing
|
|
325
|
+
} missing`,
|
|
323
326
|
);
|
|
324
327
|
}
|
|
325
328
|
|
|
@@ -353,7 +356,7 @@ class Safe {
|
|
|
353
356
|
safeTransaction.data.gasToken,
|
|
354
357
|
safeTransaction.data.refundReceiver,
|
|
355
358
|
safeTransaction.encodedSignatures(),
|
|
356
|
-
executionOptions
|
|
359
|
+
executionOptions,
|
|
357
360
|
);
|
|
358
361
|
|
|
359
362
|
return txResponse;
|
|
@@ -379,7 +382,7 @@ class Safe {
|
|
|
379
382
|
ethers.utils.getAddress(safeAddress),
|
|
380
383
|
messageHash,
|
|
381
384
|
safeVersion,
|
|
382
|
-
chainId
|
|
385
|
+
chainId,
|
|
383
386
|
);
|
|
384
387
|
};
|
|
385
388
|
|
|
@@ -405,7 +408,7 @@ class Safe {
|
|
|
405
408
|
});
|
|
406
409
|
} catch (error) {
|
|
407
410
|
throw new Error(
|
|
408
|
-
"Could not add a new off-chain message to the Safe account"
|
|
411
|
+
"Could not add a new off-chain message to the Safe account",
|
|
409
412
|
);
|
|
410
413
|
}
|
|
411
414
|
}
|
package/src/utils.ts
CHANGED
|
@@ -135,7 +135,7 @@ export async function standardizeSafeTransactionData(
|
|
|
135
135
|
const request = new RequestProvider({
|
|
136
136
|
networkId: network,
|
|
137
137
|
adapter: Safe.adapter,
|
|
138
|
-
|
|
138
|
+
openapiService: Safe.openapiService,
|
|
139
139
|
});
|
|
140
140
|
const safeTxGas =
|
|
141
141
|
tx.safeTxGas ??
|