@rabby-wallet/gnosis-sdk 1.4.4 → 1.4.5-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 CHANGED
@@ -135,10 +135,15 @@ export declare const HOST_MAP: {
135
135
  */
136
136
  "747474": string;
137
137
  };
138
+ export declare const getTxServiceUrl: (chainId: string) => any;
138
139
  export default class RequestProvider {
139
140
  host: string;
140
141
  request: Axios;
141
- constructor(networkId: string, adapter?: AxiosAdapter);
142
+ constructor({ networkId, adapter, apiKey, }: {
143
+ networkId: string;
144
+ adapter?: AxiosAdapter;
145
+ apiKey: string;
146
+ });
142
147
  getPendingTransactions(safeAddress: string, nonce: number): Promise<{
143
148
  results: SafeTransactionItem[];
144
149
  }>;
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
@@ -93,17 +189,30 @@ export const HOST_MAP = {
93
189
  /**
94
190
  * Katana
95
191
  */
96
- "747474": "https://safe-transaction-katana.safe.global/api"
192
+ "747474": "https://safe-transaction-katana.safe.global/api",
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];
97
200
  };
98
201
  export default class RequestProvider {
99
- constructor(networkId, adapter) {
100
- if (!(networkId in HOST_MAP)) {
202
+ constructor({ networkId, adapter, apiKey, }) {
203
+ const txServiceUrl = getTxServiceUrl(networkId);
204
+ if (!txServiceUrl) {
101
205
  throw new Error("Wrong networkId");
102
206
  }
103
- this.host = HOST_MAP[networkId];
207
+ this.host = txServiceUrl;
104
208
  this.request = axios.create({
105
209
  baseURL: this.host,
106
210
  adapter,
211
+ headers: apiKey
212
+ ? {
213
+ Authorization: `Bearer ${apiKey}`,
214
+ }
215
+ : undefined,
107
216
  });
108
217
  this.request.interceptors.response.use((response) => {
109
218
  return response.data;
package/dist/index.d.ts CHANGED
@@ -16,6 +16,7 @@ declare class Safe {
16
16
  network: string;
17
17
  apiKit: SafeApiKit;
18
18
  static adapter: AxiosAdapter;
19
+ static apiKey: string;
19
20
  constructor(safeAddress: string, version: string, provider: providers.Web3Provider, network?: string);
20
21
  /**
21
22
  * @deprecated
package/dist/index.js CHANGED
@@ -3,9 +3,9 @@ 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 { TRANSACTION_SERVICE_URLS } 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, { HOST_MAP } from "./api";
8
+ import RequestProvider, { getTxServiceUrl } from "./api";
9
9
  import { estimateGasForTransactionExecution, generatePreValidatedSignature, generateSignature, sameString, standardizeSafeTransactionData, } from "./utils";
10
10
  class Safe {
11
11
  constructor(safeAddress, version, provider, network = "1") {
@@ -53,7 +53,11 @@ class Safe {
53
53
  this.version = version;
54
54
  this.safeAddress = safeAddress;
55
55
  this.network = network;
56
- this.request = new RequestProvider(network, Safe.adapter);
56
+ this.request = new RequestProvider({
57
+ networkId: network,
58
+ adapter: Safe.adapter,
59
+ apiKey: Safe.apiKey,
60
+ });
57
61
  this.apiKit = Safe.createSafeApiKit(network);
58
62
  // this.init();
59
63
  }
@@ -64,11 +68,19 @@ class Safe {
64
68
  * @returns
65
69
  */
66
70
  static getSafeInfo(safeAddress, network) {
67
- const request = new RequestProvider(network, Safe.adapter);
71
+ const request = new RequestProvider({
72
+ networkId: network,
73
+ adapter: Safe.adapter,
74
+ apiKey: Safe.apiKey,
75
+ });
68
76
  return request.getSafeInfo(ethers.utils.getAddress(safeAddress));
69
77
  }
70
78
  static async getPendingTransactions(safeAddress, network, nonce) {
71
- const request = new RequestProvider(network, Safe.adapter);
79
+ const request = new RequestProvider({
80
+ networkId: network,
81
+ adapter: Safe.adapter,
82
+ apiKey: Safe.apiKey,
83
+ });
72
84
  const transactions = await request.getPendingTransactions(safeAddress, nonce);
73
85
  return transactions;
74
86
  }
@@ -246,7 +258,8 @@ class Safe {
246
258
  Safe.createSafeApiKit = (network) => {
247
259
  return new SafeApiKit({
248
260
  chainId: BigInt(network),
249
- txServiceUrl: HOST_MAP[network] || TRANSACTION_SERVICE_URLS[network] || undefined,
261
+ txServiceUrl: getTxServiceUrl(network) || undefined,
262
+ apiKey: Safe.apiKey,
250
263
  });
251
264
  };
252
265
  export default Safe;
package/dist/utils.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { BigNumber } from "@ethersproject/bignumber";
2
- import { OperationType } from "@safe-global/types-kit";
2
+ import { OperationType, } from "@safe-global/types-kit";
3
3
  import { EthSafeSignature } from "@safe-global/protocol-kit";
4
4
  import { bufferToHex, ecrecover, pubToAddress } from "ethereumjs-util";
5
5
  import { ZERO_ADDRESS, SENTINEL_ADDRESS } from "./constants";
@@ -97,7 +97,11 @@ export async function standardizeSafeTransactionData(safeAddress, safeContract,
97
97
  refundReceiver: tx.refundReceiver || ZERO_ADDRESS,
98
98
  nonce: tx.nonce ?? (await safeContract.nonce()).toNumber(),
99
99
  };
100
- const request = new RequestProvider(network, Safe.adapter);
100
+ const request = new RequestProvider({
101
+ networkId: network,
102
+ adapter: Safe.adapter,
103
+ apiKey: Safe.apiKey,
104
+ });
101
105
  const safeTxGas = tx.safeTxGas ??
102
106
  (await request.getSafeTxGas(safeAddress, version, standardizedTxs));
103
107
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rabby-wallet/gnosis-sdk",
3
- "version": "1.4.4",
3
+ "version": "1.4.5-alpha.1",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -14,7 +14,7 @@
14
14
  "@ethersproject/contracts": "5.5.0",
15
15
  "@ethersproject/providers": "5.5.0",
16
16
  "@ethersproject/solidity": "5.5.0",
17
- "@safe-global/api-kit": "2.5.8",
17
+ "@safe-global/api-kit": "4.0.0",
18
18
  "@safe-global/protocol-kit": "5.2.1",
19
19
  "@safe-global/safe-deployments": "1.37.36",
20
20
  "@safe-global/types-kit": "1.0.2",
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
@@ -139,23 +237,46 @@ export const HOST_MAP = {
139
237
  /**
140
238
  * Katana
141
239
  */
142
- "747474": "https://safe-transaction-katana.safe.global/api"
240
+ "747474": "https://safe-transaction-katana.safe.global/api",
241
+ };
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];
143
249
  };
144
250
 
145
251
  export default class RequestProvider {
146
252
  host: string;
147
253
  request: Axios;
148
254
 
149
- constructor(networkId: string, adapter?: AxiosAdapter) {
150
- if (!(networkId in HOST_MAP)) {
255
+ constructor({
256
+ networkId,
257
+ adapter,
258
+ apiKey,
259
+ }: {
260
+ networkId: string;
261
+ adapter?: AxiosAdapter;
262
+ apiKey: string;
263
+ }) {
264
+ const txServiceUrl = getTxServiceUrl(networkId);
265
+ if (!txServiceUrl) {
151
266
  throw new Error("Wrong networkId");
152
267
  }
153
268
 
154
- this.host = HOST_MAP[networkId];
269
+ this.host = txServiceUrl;
155
270
 
156
271
  this.request = axios.create({
157
272
  baseURL: this.host,
158
273
  adapter,
274
+
275
+ headers: apiKey
276
+ ? {
277
+ Authorization: `Bearer ${apiKey}`,
278
+ }
279
+ : undefined,
159
280
  });
160
281
 
161
282
  this.request.interceptors.response.use((response) => {
@@ -168,7 +289,9 @@ export default class RequestProvider {
168
289
  nonce: number
169
290
  ): Promise<{ results: SafeTransactionItem[] }> {
170
291
  return this.request.get(
171
- `/v1/safes/${ethers.utils.getAddress(safeAddress)}/multisig-transactions/`,
292
+ `/v1/safes/${ethers.utils.getAddress(
293
+ safeAddress
294
+ )}/multisig-transactions/`,
172
295
  {
173
296
  params: {
174
297
  executed: false,
@@ -186,7 +309,9 @@ export default class RequestProvider {
186
309
  }
187
310
 
188
311
  getSafeInfo(safeAddress: string): Promise<SafeInfo> {
189
- return this.request.get(`/v1/safes/${ethers.utils.getAddress(safeAddress)}/`);
312
+ return this.request.get(
313
+ `/v1/safes/${ethers.utils.getAddress(safeAddress)}/`
314
+ );
190
315
  }
191
316
 
192
317
  confirmTransaction(safeTransactionHash: string, data): Promise<void> {
package/src/index.ts CHANGED
@@ -7,16 +7,16 @@ import {
7
7
  SafeSignature,
8
8
  SafeTransaction,
9
9
  SafeTransactionDataPartial,
10
+ EIP712TypedData as ApiKitEIP712TypedData,
10
11
  } from "@safe-global/types-kit";
11
12
  import { EthSafeMessage, EthSafeTransaction } from "@safe-global/protocol-kit";
12
13
  import { calculateSafeMessageHash } from "@safe-global/protocol-kit/dist/src/utils";
13
14
  import SafeApiKit, {
14
- EIP712TypedData as ApiKitEIP712TypedData,
15
15
  SafeMessage as ApiKitSafeMessage,
16
16
  } from "@safe-global/api-kit";
17
- import { TRANSACTION_SERVICE_URLS } 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, { HOST_MAP, SafeInfo } from "./api";
19
+ import RequestProvider, { getTxServiceUrl, SafeInfo } from "./api";
20
20
  import {
21
21
  estimateGasForTransactionExecution,
22
22
  generatePreValidatedSignature,
@@ -37,6 +37,7 @@ class Safe {
37
37
  apiKit: SafeApiKit;
38
38
 
39
39
  static adapter: AxiosAdapter;
40
+ static apiKey: string;
40
41
 
41
42
  constructor(
42
43
  safeAddress: string,
@@ -56,7 +57,11 @@ class Safe {
56
57
  this.version = version;
57
58
  this.safeAddress = safeAddress;
58
59
  this.network = network;
59
- this.request = new RequestProvider(network, Safe.adapter);
60
+ this.request = new RequestProvider({
61
+ networkId: network,
62
+ adapter: Safe.adapter,
63
+ apiKey: Safe.apiKey,
64
+ });
60
65
  this.apiKit = Safe.createSafeApiKit(network);
61
66
 
62
67
  // this.init();
@@ -69,7 +74,11 @@ class Safe {
69
74
  * @returns
70
75
  */
71
76
  static getSafeInfo(safeAddress: string, network: string) {
72
- const request = new RequestProvider(network, Safe.adapter);
77
+ const request = new RequestProvider({
78
+ networkId: network,
79
+ adapter: Safe.adapter,
80
+ apiKey: Safe.apiKey,
81
+ });
73
82
  return request.getSafeInfo(ethers.utils.getAddress(safeAddress));
74
83
  }
75
84
 
@@ -78,7 +87,11 @@ class Safe {
78
87
  network: string,
79
88
  nonce: number
80
89
  ) {
81
- const request = new RequestProvider(network, Safe.adapter);
90
+ const request = new RequestProvider({
91
+ networkId: network,
92
+ adapter: Safe.adapter,
93
+ apiKey: Safe.apiKey,
94
+ });
82
95
  const transactions = await request.getPendingTransactions(
83
96
  safeAddress,
84
97
  nonce
@@ -90,8 +103,8 @@ class Safe {
90
103
  static createSafeApiKit = (network: string) => {
91
104
  return new SafeApiKit({
92
105
  chainId: BigInt(network),
93
- txServiceUrl:
94
- HOST_MAP[network] || TRANSACTION_SERVICE_URLS[network] || undefined,
106
+ txServiceUrl: getTxServiceUrl(network) || undefined,
107
+ apiKey: Safe.apiKey,
95
108
  });
96
109
  };
97
110
 
package/src/utils.ts CHANGED
@@ -5,9 +5,9 @@ import {
5
5
  SafeSignature,
6
6
  SafeTransaction,
7
7
  SafeTransactionData,
8
- SafeTransactionDataPartial
9
- } from "@safe-global/types-kit"
10
- import { EthSafeSignature } from "@safe-global/protocol-kit"
8
+ SafeTransactionDataPartial,
9
+ } from "@safe-global/types-kit";
10
+ import { EthSafeSignature } from "@safe-global/protocol-kit";
11
11
  import { bufferToHex, ecrecover, pubToAddress } from "ethereumjs-util";
12
12
  import { ZERO_ADDRESS, SENTINEL_ADDRESS } from "./constants";
13
13
  import semverSatisfies from "semver/functions/satisfies";
@@ -132,7 +132,11 @@ export async function standardizeSafeTransactionData(
132
132
  refundReceiver: tx.refundReceiver || ZERO_ADDRESS,
133
133
  nonce: tx.nonce ?? (await safeContract.nonce()).toNumber(),
134
134
  };
135
- const request = new RequestProvider(network, Safe.adapter);
135
+ const request = new RequestProvider({
136
+ networkId: network,
137
+ adapter: Safe.adapter,
138
+ apiKey: Safe.apiKey,
139
+ });
136
140
  const safeTxGas =
137
141
  tx.safeTxGas ??
138
142
  (await request.getSafeTxGas(safeAddress, version, standardizedTxs));