@rabby-wallet/gnosis-sdk 1.4.5-alpha.0 → 1.4.5-alpha.2
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 +1 -0
- package/dist/api.js +106 -2
- package/dist/index.js +10 -8
- package/package.json +1 -1
- package/src/api.ts +109 -2
- package/src/index.ts +9 -12
package/dist/api.d.ts
CHANGED
package/dist/api.js
CHANGED
|
@@ -1,6 +1,102 @@
|
|
|
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.safe.global/tx-service";
|
|
5
|
+
const networkMap = {
|
|
6
|
+
/**
|
|
7
|
+
* eth
|
|
8
|
+
*/
|
|
9
|
+
1: "eth",
|
|
10
|
+
/**
|
|
11
|
+
* Optimism
|
|
12
|
+
*/
|
|
13
|
+
10: "oeth",
|
|
14
|
+
/**
|
|
15
|
+
* bsc
|
|
16
|
+
*/
|
|
17
|
+
56: "bnb",
|
|
18
|
+
/**
|
|
19
|
+
* Gnosis Chain
|
|
20
|
+
*/
|
|
21
|
+
100: "gno",
|
|
22
|
+
130: "unichain",
|
|
23
|
+
/**
|
|
24
|
+
* polygon
|
|
25
|
+
*/
|
|
26
|
+
137: "pol",
|
|
27
|
+
/**
|
|
28
|
+
* Sonic
|
|
29
|
+
*/
|
|
30
|
+
146: "sonic",
|
|
31
|
+
/**
|
|
32
|
+
* X Layer
|
|
33
|
+
*/
|
|
34
|
+
196: "okb",
|
|
35
|
+
232: "lens",
|
|
36
|
+
/**
|
|
37
|
+
* zksync era
|
|
38
|
+
*/
|
|
39
|
+
324: "zksync",
|
|
40
|
+
/**
|
|
41
|
+
* World Chain
|
|
42
|
+
*/
|
|
43
|
+
480: "wc",
|
|
44
|
+
/**
|
|
45
|
+
* Polygon zkEVM
|
|
46
|
+
*/
|
|
47
|
+
1101: "zkevm",
|
|
48
|
+
/**
|
|
49
|
+
* mantle
|
|
50
|
+
*/
|
|
51
|
+
5000: "mantle",
|
|
52
|
+
/**
|
|
53
|
+
* Base
|
|
54
|
+
*/
|
|
55
|
+
8453: "base",
|
|
56
|
+
10200: "chi",
|
|
57
|
+
/**
|
|
58
|
+
* arbitrum
|
|
59
|
+
*/
|
|
60
|
+
42161: "arb1",
|
|
61
|
+
/**
|
|
62
|
+
* Celo
|
|
63
|
+
*/
|
|
64
|
+
42220: "celo",
|
|
65
|
+
/**
|
|
66
|
+
* Hemi
|
|
67
|
+
*/
|
|
68
|
+
43111: "hemi",
|
|
69
|
+
/**
|
|
70
|
+
* avalanche
|
|
71
|
+
*/
|
|
72
|
+
43114: "avax",
|
|
73
|
+
/**
|
|
74
|
+
* ink
|
|
75
|
+
*/
|
|
76
|
+
57073: "ink",
|
|
77
|
+
/**
|
|
78
|
+
* linea
|
|
79
|
+
*/
|
|
80
|
+
59144: "linea",
|
|
81
|
+
/**
|
|
82
|
+
* Berachain
|
|
83
|
+
*/
|
|
84
|
+
80094: "berachain",
|
|
85
|
+
84532: "basesep",
|
|
86
|
+
/**
|
|
87
|
+
* scroll
|
|
88
|
+
*/
|
|
89
|
+
534352: "scr",
|
|
90
|
+
/**
|
|
91
|
+
* Katana
|
|
92
|
+
*/
|
|
93
|
+
747474: "katana",
|
|
94
|
+
11155111: "sep",
|
|
95
|
+
/**
|
|
96
|
+
* Aurora
|
|
97
|
+
*/
|
|
98
|
+
1313161554: "aurora",
|
|
99
|
+
};
|
|
4
100
|
export const HOST_MAP = {
|
|
5
101
|
/**
|
|
6
102
|
* eth
|
|
@@ -95,12 +191,20 @@ export const HOST_MAP = {
|
|
|
95
191
|
*/
|
|
96
192
|
"747474": "https://safe-transaction-katana.safe.global/api",
|
|
97
193
|
};
|
|
194
|
+
export const getTxServiceUrl = (chainId) => {
|
|
195
|
+
const shortName = networkMap[chainId];
|
|
196
|
+
if (shortName) {
|
|
197
|
+
return `${TRANSACTION_SERVICE_URL}/${shortName}/api`;
|
|
198
|
+
}
|
|
199
|
+
return HOST_MAP[chainId];
|
|
200
|
+
};
|
|
98
201
|
export default class RequestProvider {
|
|
99
202
|
constructor({ networkId, adapter, apiKey, }) {
|
|
100
|
-
|
|
203
|
+
const txServiceUrl = getTxServiceUrl(networkId);
|
|
204
|
+
if (!txServiceUrl) {
|
|
101
205
|
throw new Error("Wrong networkId");
|
|
102
206
|
}
|
|
103
|
-
this.host =
|
|
207
|
+
this.host = txServiceUrl;
|
|
104
208
|
this.request = axios.create({
|
|
105
209
|
baseURL: this.host,
|
|
106
210
|
adapter,
|
package/dist/index.js
CHANGED
|
@@ -3,10 +3,10 @@ import { Contract, ethers } from "ethers";
|
|
|
3
3
|
import { EthSafeTransaction } from "@safe-global/protocol-kit";
|
|
4
4
|
import { calculateSafeMessageHash } from "@safe-global/protocol-kit/dist/src/utils";
|
|
5
5
|
import SafeApiKit from "@safe-global/api-kit";
|
|
6
|
-
import { getTransactionServiceUrl } from "@safe-global/api-kit/dist/src/utils/config";
|
|
6
|
+
// import { getTransactionServiceUrl } from "@safe-global/api-kit/dist/src/utils/config";
|
|
7
7
|
import { getSafeSingletonDeployment } from "@safe-global/safe-deployments";
|
|
8
|
-
import RequestProvider, {
|
|
9
|
-
import {
|
|
8
|
+
import RequestProvider, { getTxServiceUrl } from "./api";
|
|
9
|
+
import { generatePreValidatedSignature, generateSignature, sameString, standardizeSafeTransactionData, } from "./utils";
|
|
10
10
|
class Safe {
|
|
11
11
|
constructor(safeAddress, version, provider, network = "1") {
|
|
12
12
|
this.owners = [];
|
|
@@ -225,9 +225,13 @@ class Safe {
|
|
|
225
225
|
throw new Error("Not enough Ether funds");
|
|
226
226
|
}
|
|
227
227
|
}
|
|
228
|
-
const gasLimit = await estimateGasForTransactionExecution(
|
|
228
|
+
// const gasLimit = await estimateGasForTransactionExecution(
|
|
229
|
+
// contract,
|
|
230
|
+
// signerAddress,
|
|
231
|
+
// safeTransaction
|
|
232
|
+
// );
|
|
229
233
|
const executionOptions = {
|
|
230
|
-
gasLimit,
|
|
234
|
+
gasLimit: 0,
|
|
231
235
|
gasPrice: options?.gasPrice,
|
|
232
236
|
from: signerAddress,
|
|
233
237
|
};
|
|
@@ -258,9 +262,7 @@ class Safe {
|
|
|
258
262
|
Safe.createSafeApiKit = (network) => {
|
|
259
263
|
return new SafeApiKit({
|
|
260
264
|
chainId: BigInt(network),
|
|
261
|
-
txServiceUrl:
|
|
262
|
-
getTransactionServiceUrl(BigInt(network)) ||
|
|
263
|
-
undefined,
|
|
265
|
+
txServiceUrl: getTxServiceUrl(network) || undefined,
|
|
264
266
|
apiKey: Safe.apiKey,
|
|
265
267
|
});
|
|
266
268
|
};
|
package/package.json
CHANGED
package/src/api.ts
CHANGED
|
@@ -47,6 +47,104 @@ export interface SafeTransactionItem {
|
|
|
47
47
|
signatures: string | null;
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
+
const TRANSACTION_SERVICE_URL = "https://api.safe.global/tx-service";
|
|
51
|
+
|
|
52
|
+
const networkMap = {
|
|
53
|
+
/**
|
|
54
|
+
* eth
|
|
55
|
+
*/
|
|
56
|
+
1: "eth",
|
|
57
|
+
/**
|
|
58
|
+
* Optimism
|
|
59
|
+
*/
|
|
60
|
+
10: "oeth",
|
|
61
|
+
/**
|
|
62
|
+
* bsc
|
|
63
|
+
*/
|
|
64
|
+
56: "bnb",
|
|
65
|
+
/**
|
|
66
|
+
* Gnosis Chain
|
|
67
|
+
*/
|
|
68
|
+
100: "gno",
|
|
69
|
+
130: "unichain",
|
|
70
|
+
/**
|
|
71
|
+
* polygon
|
|
72
|
+
*/
|
|
73
|
+
137: "pol",
|
|
74
|
+
/**
|
|
75
|
+
* Sonic
|
|
76
|
+
*/
|
|
77
|
+
146: "sonic",
|
|
78
|
+
/**
|
|
79
|
+
* X Layer
|
|
80
|
+
*/
|
|
81
|
+
196: "okb",
|
|
82
|
+
232: "lens",
|
|
83
|
+
/**
|
|
84
|
+
* zksync era
|
|
85
|
+
*/
|
|
86
|
+
324: "zksync",
|
|
87
|
+
/**
|
|
88
|
+
* World Chain
|
|
89
|
+
*/
|
|
90
|
+
480: "wc",
|
|
91
|
+
/**
|
|
92
|
+
* Polygon zkEVM
|
|
93
|
+
*/
|
|
94
|
+
1101: "zkevm",
|
|
95
|
+
/**
|
|
96
|
+
* mantle
|
|
97
|
+
*/
|
|
98
|
+
5000: "mantle",
|
|
99
|
+
/**
|
|
100
|
+
* Base
|
|
101
|
+
*/
|
|
102
|
+
8453: "base",
|
|
103
|
+
10200: "chi",
|
|
104
|
+
/**
|
|
105
|
+
* arbitrum
|
|
106
|
+
*/
|
|
107
|
+
42161: "arb1",
|
|
108
|
+
/**
|
|
109
|
+
* Celo
|
|
110
|
+
*/
|
|
111
|
+
42220: "celo",
|
|
112
|
+
/**
|
|
113
|
+
* Hemi
|
|
114
|
+
*/
|
|
115
|
+
43111: "hemi",
|
|
116
|
+
/**
|
|
117
|
+
* avalanche
|
|
118
|
+
*/
|
|
119
|
+
43114: "avax",
|
|
120
|
+
/**
|
|
121
|
+
* ink
|
|
122
|
+
*/
|
|
123
|
+
57073: "ink",
|
|
124
|
+
/**
|
|
125
|
+
* linea
|
|
126
|
+
*/
|
|
127
|
+
59144: "linea",
|
|
128
|
+
/**
|
|
129
|
+
* Berachain
|
|
130
|
+
*/
|
|
131
|
+
80094: "berachain",
|
|
132
|
+
84532: "basesep",
|
|
133
|
+
/**
|
|
134
|
+
* scroll
|
|
135
|
+
*/
|
|
136
|
+
534352: "scr",
|
|
137
|
+
/**
|
|
138
|
+
* Katana
|
|
139
|
+
*/
|
|
140
|
+
747474: "katana",
|
|
141
|
+
11155111: "sep",
|
|
142
|
+
/**
|
|
143
|
+
* Aurora
|
|
144
|
+
*/
|
|
145
|
+
1313161554: "aurora",
|
|
146
|
+
};
|
|
147
|
+
|
|
50
148
|
export const HOST_MAP = {
|
|
51
149
|
/**
|
|
52
150
|
* eth
|
|
@@ -142,6 +240,14 @@ export const HOST_MAP = {
|
|
|
142
240
|
"747474": "https://safe-transaction-katana.safe.global/api",
|
|
143
241
|
};
|
|
144
242
|
|
|
243
|
+
export const getTxServiceUrl = (chainId: string) => {
|
|
244
|
+
const shortName = networkMap[chainId];
|
|
245
|
+
if (shortName) {
|
|
246
|
+
return `${TRANSACTION_SERVICE_URL}/${shortName}/api`;
|
|
247
|
+
}
|
|
248
|
+
return HOST_MAP[chainId];
|
|
249
|
+
};
|
|
250
|
+
|
|
145
251
|
export default class RequestProvider {
|
|
146
252
|
host: string;
|
|
147
253
|
request: Axios;
|
|
@@ -155,11 +261,12 @@ export default class RequestProvider {
|
|
|
155
261
|
adapter?: AxiosAdapter;
|
|
156
262
|
apiKey: string;
|
|
157
263
|
}) {
|
|
158
|
-
|
|
264
|
+
const txServiceUrl = getTxServiceUrl(networkId);
|
|
265
|
+
if (!txServiceUrl) {
|
|
159
266
|
throw new Error("Wrong networkId");
|
|
160
267
|
}
|
|
161
268
|
|
|
162
|
-
this.host =
|
|
269
|
+
this.host = txServiceUrl;
|
|
163
270
|
|
|
164
271
|
this.request = axios.create({
|
|
165
272
|
baseURL: this.host,
|
package/src/index.ts
CHANGED
|
@@ -14,9 +14,9 @@ import { calculateSafeMessageHash } from "@safe-global/protocol-kit/dist/src/uti
|
|
|
14
14
|
import SafeApiKit, {
|
|
15
15
|
SafeMessage as ApiKitSafeMessage,
|
|
16
16
|
} from "@safe-global/api-kit";
|
|
17
|
-
import { getTransactionServiceUrl } from "@safe-global/api-kit/dist/src/utils/config";
|
|
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, { getTxServiceUrl, SafeInfo } from "./api";
|
|
20
20
|
import {
|
|
21
21
|
estimateGasForTransactionExecution,
|
|
22
22
|
generatePreValidatedSignature,
|
|
@@ -103,10 +103,7 @@ class Safe {
|
|
|
103
103
|
static createSafeApiKit = (network: string) => {
|
|
104
104
|
return new SafeApiKit({
|
|
105
105
|
chainId: BigInt(network),
|
|
106
|
-
txServiceUrl:
|
|
107
|
-
HOST_MAP[network] ||
|
|
108
|
-
getTransactionServiceUrl(BigInt(network)) ||
|
|
109
|
-
undefined,
|
|
106
|
+
txServiceUrl: getTxServiceUrl(network) || undefined,
|
|
110
107
|
apiKey: Safe.apiKey,
|
|
111
108
|
});
|
|
112
109
|
};
|
|
@@ -334,13 +331,13 @@ class Safe {
|
|
|
334
331
|
}
|
|
335
332
|
}
|
|
336
333
|
|
|
337
|
-
const gasLimit = await estimateGasForTransactionExecution(
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
);
|
|
334
|
+
// const gasLimit = await estimateGasForTransactionExecution(
|
|
335
|
+
// contract,
|
|
336
|
+
// signerAddress,
|
|
337
|
+
// safeTransaction
|
|
338
|
+
// );
|
|
342
339
|
const executionOptions: TransactionOptions = {
|
|
343
|
-
gasLimit,
|
|
340
|
+
gasLimit: 0,
|
|
344
341
|
gasPrice: options?.gasPrice,
|
|
345
342
|
from: signerAddress,
|
|
346
343
|
};
|