@rabby-wallet/gnosis-sdk 1.3.1 → 1.3.3

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.js CHANGED
@@ -5,7 +5,10 @@ const HOST_MAP = {
5
5
  '137': 'https://safe-transaction-polygon.safe.global/api/v1',
6
6
  '56': 'https://safe-transaction-bsc.safe.global/api/v1',
7
7
  '100': 'https://safe-transaction-gnosis-chain.safe.global/api/v1',
8
- '43114': 'https://safe-transaction-avalanche.safe.global/api/v1'
8
+ '43114': 'https://safe-transaction-avalanche.safe.global/api/v1',
9
+ '42161': 'https://safe-transaction-arbitrum.safe.global/api/v1',
10
+ '10': 'https://safe-transaction-optimism.safe.global/api/v1',
11
+ '1313161554': 'https://safe-transaction-aurora.safe.global/api/v1'
9
12
  };
10
13
  export default class RequestProvider {
11
14
  constructor(networkId, adapter) {
package/dist/index.d.ts CHANGED
@@ -1,11 +1,11 @@
1
- import { Contract } from 'ethers';
2
- import { BigNumber } from '@ethersproject/bignumber';
3
- import { providers } from 'ethers';
4
- import { SafeTransactionDataPartial, SafeSignature } from '@gnosis.pm/safe-core-sdk-types';
5
- import { TransactionResult, TransactionOptions } from '@gnosis.pm/safe-core-sdk/dist/src/utils/transactions/types';
6
- import SafeTransaction from '@gnosis.pm/safe-core-sdk/dist/src/utils/transactions/SafeTransaction';
7
- import RequestProvider, { SafeInfo } from './api';
8
- import { AxiosAdapter } from 'axios';
1
+ import { Contract } from "ethers";
2
+ import { BigNumber } from "@ethersproject/bignumber";
3
+ import { providers } from "ethers";
4
+ import { SafeTransactionDataPartial, SafeSignature } from "@gnosis.pm/safe-core-sdk-types";
5
+ import { TransactionResult, TransactionOptions } from "@gnosis.pm/safe-core-sdk/dist/src/utils/transactions/types";
6
+ import SafeTransaction from "@gnosis.pm/safe-core-sdk/dist/src/utils/transactions/SafeTransaction";
7
+ import RequestProvider, { SafeInfo } from "./api";
8
+ import { AxiosAdapter } from "axios";
9
9
  declare class Safe {
10
10
  contract: Contract;
11
11
  safeAddress: string;
@@ -17,14 +17,31 @@ declare class Safe {
17
17
  network: string;
18
18
  static adapter: AxiosAdapter;
19
19
  constructor(safeAddress: string, version: string, provider: providers.Web3Provider, network?: string);
20
+ /**
21
+ * @deprecated
22
+ * @param safeAddress
23
+ * @param network
24
+ * @returns
25
+ */
20
26
  static getSafeInfo(safeAddress: string, network: string): Promise<SafeInfo>;
21
27
  static getPendingTransactions(safeAddress: string, network: string): Promise<{
22
28
  results: import("./api").SafeTransactionItem[];
23
29
  }>;
30
+ static getSafeVersion({ address, provider, }: {
31
+ address: any;
32
+ provider: providers.Web3Provider;
33
+ }): Promise<string>;
24
34
  init(): Promise<void>;
25
35
  getOwners(): Promise<string[]>;
26
- getThreshold(): Promise<any>;
36
+ getThreshold(): Promise<number>;
27
37
  getNonce(): Promise<number>;
38
+ getBasicSafeInfo: () => Promise<{
39
+ address: string;
40
+ version: string;
41
+ threshold: number;
42
+ nonce: number;
43
+ owners: string[];
44
+ }>;
28
45
  buildTransaction(data: SafeTransactionDataPartial): Promise<SafeTransaction>;
29
46
  getTransactionHash(transaction: SafeTransaction): Promise<any>;
30
47
  signTransactionHash(hash: string): Promise<SafeSignature>;
@@ -36,3 +53,4 @@ declare class Safe {
36
53
  executeTransaction(safeTransaction: SafeTransaction, options?: TransactionOptions): Promise<TransactionResult>;
37
54
  }
38
55
  export default Safe;
56
+ export type BasicSafeInfo = Awaited<ReturnType<Safe["getBasicSafeInfo"]>>;
package/dist/index.js CHANGED
@@ -1,21 +1,35 @@
1
- import { Contract } from 'ethers';
2
- import { BigNumber } from '@ethersproject/bignumber';
3
- import BN from 'bignumber.js';
4
- import { getSafeSingletonDeployment } from '@gnosis.pm/safe-deployments';
5
- import { toChecksumAddress } from 'web3-utils';
6
- import SafeTransaction from '@gnosis.pm/safe-core-sdk/dist/src/utils/transactions/SafeTransaction';
7
- import RequestProvider from './api';
8
- import { standardizeSafeTransactionData, sameString, generateSignature, generatePreValidatedSignature, estimateGasForTransactionExecution } from './utils';
1
+ import { Contract } from "ethers";
2
+ import { BigNumber } from "@ethersproject/bignumber";
3
+ import BN from "bignumber.js";
4
+ import { getSafeSingletonDeployment } from "@safe-global/safe-deployments";
5
+ import { toChecksumAddress } from "web3-utils";
6
+ import SafeTransaction from "@gnosis.pm/safe-core-sdk/dist/src/utils/transactions/SafeTransaction";
7
+ import RequestProvider from "./api";
8
+ import { standardizeSafeTransactionData, sameString, generateSignature, generatePreValidatedSignature, estimateGasForTransactionExecution, } from "./utils";
9
9
  class Safe {
10
- constructor(safeAddress, version, provider, network = '1') {
10
+ constructor(safeAddress, version, provider, network = "1") {
11
11
  this.owners = [];
12
12
  this.safeInfo = null;
13
+ this.getBasicSafeInfo = async () => {
14
+ const [threshold, nonce, owners] = await Promise.all([
15
+ this.getThreshold(),
16
+ this.getNonce(),
17
+ this.getOwners(),
18
+ ]);
19
+ return {
20
+ address: this.safeAddress,
21
+ version: this.version,
22
+ threshold,
23
+ nonce,
24
+ owners,
25
+ };
26
+ };
13
27
  const contract = getSafeSingletonDeployment({
14
28
  version,
15
- network
29
+ network,
16
30
  });
17
31
  if (!contract) {
18
- throw new Error('Wrong version or network');
32
+ throw new Error("Wrong version or network");
19
33
  }
20
34
  this.provider = provider;
21
35
  this.contract = new Contract(safeAddress, contract.abi, this.provider);
@@ -23,8 +37,14 @@ class Safe {
23
37
  this.safeAddress = safeAddress;
24
38
  this.network = network;
25
39
  this.request = new RequestProvider(network, Safe.adapter);
26
- this.init();
27
- }
40
+ // this.init();
41
+ }
42
+ /**
43
+ * @deprecated
44
+ * @param safeAddress
45
+ * @param network
46
+ * @returns
47
+ */
28
48
  static getSafeInfo(safeAddress, network) {
29
49
  const request = new RequestProvider(network, Safe.adapter);
30
50
  return request.getSafeInfo(toChecksumAddress(safeAddress));
@@ -36,6 +56,27 @@ class Safe {
36
56
  const transactions = await request.getPendingTransactions(safeAddress, nonce);
37
57
  return transactions;
38
58
  }
59
+ static async getSafeVersion({ address, provider, }) {
60
+ const contract = new Contract(address, [
61
+ {
62
+ constant: true,
63
+ inputs: [],
64
+ name: "VERSION",
65
+ outputs: [
66
+ {
67
+ internalType: "string",
68
+ name: "",
69
+ type: "string",
70
+ },
71
+ ],
72
+ payable: false,
73
+ stateMutability: "view",
74
+ type: "function",
75
+ },
76
+ ], provider);
77
+ const version = await contract.VERSION();
78
+ return version;
79
+ }
39
80
  async init() {
40
81
  const safeInfo = await Safe.getSafeInfo(this.safeAddress, this.network);
41
82
  this.safeInfo = safeInfo;
@@ -71,7 +112,7 @@ class Safe {
71
112
  const signerAddress = await signer.getAddress();
72
113
  const addressIsOwner = owners.find((owner) => signerAddress && sameString(owner, signerAddress));
73
114
  if (!addressIsOwner) {
74
- throw new Error('Transactions can only be signed by Safe owners');
115
+ throw new Error("Transactions can only be signed by Safe owners");
75
116
  }
76
117
  return generateSignature(this.provider, hash);
77
118
  }
@@ -109,7 +150,7 @@ class Safe {
109
150
  nonce: transaction.data.nonce,
110
151
  contractTransactionHash: hash,
111
152
  sender: toChecksumAddress(signerAddress),
112
- signature: transaction.encodedSignatures()
153
+ signature: transaction.encodedSignatures(),
113
154
  });
114
155
  }
115
156
  async confirmTransaction(safeTransaction) {
@@ -142,20 +183,20 @@ class Safe {
142
183
  const threshold = await this.getThreshold();
143
184
  if (threshold > safeTransaction.signatures.size) {
144
185
  const signaturesMissing = threshold - safeTransaction.signatures.size;
145
- throw new Error(`There ${signaturesMissing > 1 ? 'are' : 'is'} ${signaturesMissing} signature${signaturesMissing > 1 ? 's' : ''} missing`);
186
+ throw new Error(`There ${signaturesMissing > 1 ? "are" : "is"} ${signaturesMissing} signature${signaturesMissing > 1 ? "s" : ""} missing`);
146
187
  }
147
188
  const value = BigNumber.from(safeTransaction.data.value);
148
189
  if (!value.isZero()) {
149
190
  const balance = await this.getBalance();
150
191
  if (value.gt(BigNumber.from(balance))) {
151
- throw new Error('Not enough Ether funds');
192
+ throw new Error("Not enough Ether funds");
152
193
  }
153
194
  }
154
195
  const gasLimit = await estimateGasForTransactionExecution(contract, signerAddress, safeTransaction);
155
196
  const executionOptions = {
156
197
  gasLimit,
157
198
  gasPrice: options === null || options === void 0 ? void 0 : options.gasPrice,
158
- from: signerAddress
199
+ from: signerAddress,
159
200
  };
160
201
  const txResponse = await contract.execTransaction(safeTransaction.data.to, safeTransaction.data.value, safeTransaction.data.data, safeTransaction.data.operation, safeTransaction.data.safeTxGas, safeTransaction.data.baseGas, safeTransaction.data.gasPrice, safeTransaction.data.gasToken, safeTransaction.data.refundReceiver, safeTransaction.encodedSignatures(), executionOptions);
161
202
  return txResponse;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rabby-wallet/gnosis-sdk",
3
- "version": "1.3.1",
3
+ "version": "1.3.3",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -16,12 +16,15 @@
16
16
  "@ethersproject/solidity": "^5.5.0",
17
17
  "@gnosis.pm/safe-core-sdk": "^1.0.0",
18
18
  "@gnosis.pm/safe-core-sdk-types": "^0.1.1",
19
- "@gnosis.pm/safe-deployments": "^1.15.0",
19
+ "@safe-global/safe-deployments": "^1.25.0",
20
20
  "axios": "^0.24.0",
21
21
  "bignumber.js": "^9.0.2",
22
22
  "ethereumjs-util": "^7.1.3",
23
23
  "ethers": "^5.5.1",
24
- "typescript": "^4.4.4",
24
+ "typescript": "^4.5.0",
25
25
  "web3-core": "^1.6.0"
26
+ },
27
+ "devDependencies": {
28
+ "@types/node": "^20.3.3"
26
29
  }
27
30
  }
package/src/api.ts CHANGED
@@ -50,7 +50,10 @@ const HOST_MAP = {
50
50
  '137': 'https://safe-transaction-polygon.safe.global/api/v1',
51
51
  '56': 'https://safe-transaction-bsc.safe.global/api/v1',
52
52
  '100': 'https://safe-transaction-gnosis-chain.safe.global/api/v1',
53
- '43114': 'https://safe-transaction-avalanche.safe.global/api/v1'
53
+ '43114': 'https://safe-transaction-avalanche.safe.global/api/v1',
54
+ '42161': 'https://safe-transaction-arbitrum.safe.global/api/v1',
55
+ '10': 'https://safe-transaction-optimism.safe.global/api/v1',
56
+ '1313161554': 'https://safe-transaction-aurora.safe.global/api/v1'
54
57
  };
55
58
 
56
59
  export default class RequestProvider {
package/src/index.ts CHANGED
@@ -1,27 +1,27 @@
1
- import { Contract } from 'ethers';
2
- import { BigNumber } from '@ethersproject/bignumber';
3
- import BN from 'bignumber.js';
4
- import { getSafeSingletonDeployment } from '@gnosis.pm/safe-deployments';
5
- import { providers } from 'ethers';
6
- import { toChecksumAddress } from 'web3-utils';
1
+ import { Contract, ethers } from "ethers";
2
+ import { BigNumber } from "@ethersproject/bignumber";
3
+ import BN from "bignumber.js";
4
+ import { getSafeSingletonDeployment } from "@safe-global/safe-deployments";
5
+ import { providers } from "ethers";
6
+ import { toChecksumAddress } from "web3-utils";
7
7
  import {
8
8
  SafeTransactionDataPartial,
9
- SafeSignature
10
- } from '@gnosis.pm/safe-core-sdk-types';
9
+ SafeSignature,
10
+ } from "@gnosis.pm/safe-core-sdk-types";
11
11
  import {
12
12
  TransactionResult,
13
- TransactionOptions
14
- } from '@gnosis.pm/safe-core-sdk/dist/src/utils/transactions/types';
15
- import SafeTransaction from '@gnosis.pm/safe-core-sdk/dist/src/utils/transactions/SafeTransaction';
16
- import RequestProvider, { SafeInfo } from './api';
13
+ TransactionOptions,
14
+ } from "@gnosis.pm/safe-core-sdk/dist/src/utils/transactions/types";
15
+ import SafeTransaction from "@gnosis.pm/safe-core-sdk/dist/src/utils/transactions/SafeTransaction";
16
+ import RequestProvider, { SafeInfo } from "./api";
17
17
  import {
18
18
  standardizeSafeTransactionData,
19
19
  sameString,
20
20
  generateSignature,
21
21
  generatePreValidatedSignature,
22
- estimateGasForTransactionExecution
23
- } from './utils';
24
- import { AxiosAdapter } from 'axios';
22
+ estimateGasForTransactionExecution,
23
+ } from "./utils";
24
+ import { AxiosAdapter } from "axios";
25
25
 
26
26
  class Safe {
27
27
  contract: Contract;
@@ -39,14 +39,14 @@ class Safe {
39
39
  safeAddress: string,
40
40
  version: string,
41
41
  provider: providers.Web3Provider,
42
- network = '1'
42
+ network = "1"
43
43
  ) {
44
44
  const contract = getSafeSingletonDeployment({
45
45
  version,
46
- network
46
+ network,
47
47
  });
48
48
  if (!contract) {
49
- throw new Error('Wrong version or network');
49
+ throw new Error("Wrong version or network");
50
50
  }
51
51
  this.provider = provider;
52
52
  this.contract = new Contract(safeAddress, contract.abi, this.provider);
@@ -54,9 +54,15 @@ class Safe {
54
54
  this.safeAddress = safeAddress;
55
55
  this.network = network;
56
56
  this.request = new RequestProvider(network, Safe.adapter);
57
- this.init();
57
+ // this.init();
58
58
  }
59
59
 
60
+ /**
61
+ * @deprecated
62
+ * @param safeAddress
63
+ * @param network
64
+ * @returns
65
+ */
60
66
  static getSafeInfo(safeAddress: string, network: string) {
61
67
  const request = new RequestProvider(network, Safe.adapter);
62
68
  return request.getSafeInfo(toChecksumAddress(safeAddress));
@@ -74,6 +80,40 @@ class Safe {
74
80
  return transactions;
75
81
  }
76
82
 
83
+ static async getSafeVersion({
84
+ address,
85
+ provider,
86
+ }: {
87
+ address;
88
+ provider: providers.Web3Provider;
89
+ }): Promise<string> {
90
+ const contract = new Contract(
91
+ address,
92
+ [
93
+ {
94
+ constant: true,
95
+ inputs: [],
96
+ name: "VERSION",
97
+ outputs: [
98
+ {
99
+ internalType: "string",
100
+ name: "",
101
+ type: "string",
102
+ },
103
+ ],
104
+ payable: false,
105
+ stateMutability: "view",
106
+ type: "function",
107
+ },
108
+ ],
109
+ provider
110
+ );
111
+
112
+ const version = await contract.VERSION();
113
+
114
+ return version;
115
+ }
116
+
77
117
  async init() {
78
118
  const safeInfo = await Safe.getSafeInfo(this.safeAddress, this.network);
79
119
  this.safeInfo = safeInfo;
@@ -92,7 +132,7 @@ class Safe {
92
132
  return owners;
93
133
  }
94
134
 
95
- async getThreshold() {
135
+ async getThreshold(): Promise<number> {
96
136
  const threshold = await this.contract.getThreshold();
97
137
  return threshold.toNumber();
98
138
  }
@@ -102,6 +142,21 @@ class Safe {
102
142
  return nonce.toNumber();
103
143
  }
104
144
 
145
+ getBasicSafeInfo = async () => {
146
+ const [threshold, nonce, owners] = await Promise.all([
147
+ this.getThreshold(),
148
+ this.getNonce(),
149
+ this.getOwners(),
150
+ ]);
151
+ return {
152
+ address: this.safeAddress,
153
+ version: this.version,
154
+ threshold,
155
+ nonce,
156
+ owners,
157
+ };
158
+ };
159
+
105
160
  async buildTransaction(data: SafeTransactionDataPartial) {
106
161
  const transaction = await standardizeSafeTransactionData(
107
162
  this.safeAddress,
@@ -136,7 +191,7 @@ class Safe {
136
191
  (owner: string) => signerAddress && sameString(owner, signerAddress)
137
192
  );
138
193
  if (!addressIsOwner) {
139
- throw new Error('Transactions can only be signed by Safe owners');
194
+ throw new Error("Transactions can only be signed by Safe owners");
140
195
  }
141
196
  return generateSignature(this.provider, hash);
142
197
  }
@@ -177,7 +232,7 @@ class Safe {
177
232
  nonce: transaction.data.nonce,
178
233
  contractTransactionHash: hash,
179
234
  sender: toChecksumAddress(signerAddress),
180
- signature: transaction.encodedSignatures()
235
+ signature: transaction.encodedSignatures(),
181
236
  });
182
237
  }
183
238
 
@@ -221,9 +276,9 @@ class Safe {
221
276
  const signaturesMissing = threshold - safeTransaction.signatures.size;
222
277
  throw new Error(
223
278
  `There ${
224
- signaturesMissing > 1 ? 'are' : 'is'
279
+ signaturesMissing > 1 ? "are" : "is"
225
280
  } ${signaturesMissing} signature${
226
- signaturesMissing > 1 ? 's' : ''
281
+ signaturesMissing > 1 ? "s" : ""
227
282
  } missing`
228
283
  );
229
284
  }
@@ -232,7 +287,7 @@ class Safe {
232
287
  if (!value.isZero()) {
233
288
  const balance = await this.getBalance();
234
289
  if (value.gt(BigNumber.from(balance))) {
235
- throw new Error('Not enough Ether funds');
290
+ throw new Error("Not enough Ether funds");
236
291
  }
237
292
  }
238
293
 
@@ -244,7 +299,7 @@ class Safe {
244
299
  const executionOptions: TransactionOptions = {
245
300
  gasLimit,
246
301
  gasPrice: options?.gasPrice,
247
- from: signerAddress
302
+ from: signerAddress,
248
303
  };
249
304
 
250
305
  const txResponse = await contract.execTransaction(
@@ -266,3 +321,5 @@ class Safe {
266
321
  }
267
322
 
268
323
  export default Safe;
324
+
325
+ export type BasicSafeInfo = Awaited<ReturnType<Safe["getBasicSafeInfo"]>>;