@rabby-wallet/gnosis-sdk 1.3.2 → 1.3.4

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/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,34 @@ 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
- static getPendingTransactions(safeAddress: string, network: string): Promise<{
27
+ static getPendingTransactions(safeAddress: string, network: string, nonce: number): Promise<{
22
28
  results: import("./api").SafeTransactionItem[];
23
29
  }>;
30
+ getPendingTransactions(): Promise<{
31
+ results: import("./api").SafeTransactionItem[];
32
+ }>;
33
+ static getSafeVersion({ address, provider, }: {
34
+ address: any;
35
+ provider: providers.Web3Provider;
36
+ }): Promise<string>;
24
37
  init(): Promise<void>;
25
38
  getOwners(): Promise<string[]>;
26
- getThreshold(): Promise<any>;
39
+ getThreshold(): Promise<number>;
27
40
  getNonce(): Promise<number>;
41
+ getBasicSafeInfo: () => Promise<{
42
+ address: string;
43
+ version: string;
44
+ threshold: number;
45
+ nonce: number;
46
+ owners: string[];
47
+ }>;
28
48
  buildTransaction(data: SafeTransactionDataPartial): Promise<SafeTransaction>;
29
49
  getTransactionHash(transaction: SafeTransaction): Promise<any>;
30
50
  signTransactionHash(hash: string): Promise<SafeSignature>;
@@ -36,3 +56,4 @@ declare class Safe {
36
56
  executeTransaction(safeTransaction: SafeTransaction, options?: TransactionOptions): Promise<TransactionResult>;
37
57
  }
38
58
  export default Safe;
59
+ 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,19 +37,49 @@ 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));
31
51
  }
32
- static async getPendingTransactions(safeAddress, network) {
52
+ static async getPendingTransactions(safeAddress, network, nonce) {
33
53
  const request = new RequestProvider(network, Safe.adapter);
34
- const nonce = (await request.getSafeInfo(toChecksumAddress(safeAddress)))
35
- .nonce;
36
54
  const transactions = await request.getPendingTransactions(safeAddress, nonce);
37
55
  return transactions;
38
56
  }
57
+ async getPendingTransactions() {
58
+ const nonce = await this.getNonce();
59
+ const transactions = await this.request.getPendingTransactions(this.safeAddress, nonce);
60
+ return transactions;
61
+ }
62
+ static async getSafeVersion({ address, provider, }) {
63
+ const contract = new Contract(address, [
64
+ {
65
+ constant: true,
66
+ inputs: [],
67
+ name: "VERSION",
68
+ outputs: [
69
+ {
70
+ internalType: "string",
71
+ name: "",
72
+ type: "string",
73
+ },
74
+ ],
75
+ payable: false,
76
+ stateMutability: "view",
77
+ type: "function",
78
+ },
79
+ ], provider);
80
+ const version = await contract.VERSION();
81
+ return version;
82
+ }
39
83
  async init() {
40
84
  const safeInfo = await Safe.getSafeInfo(this.safeAddress, this.network);
41
85
  this.safeInfo = safeInfo;
@@ -71,7 +115,7 @@ class Safe {
71
115
  const signerAddress = await signer.getAddress();
72
116
  const addressIsOwner = owners.find((owner) => signerAddress && sameString(owner, signerAddress));
73
117
  if (!addressIsOwner) {
74
- throw new Error('Transactions can only be signed by Safe owners');
118
+ throw new Error("Transactions can only be signed by Safe owners");
75
119
  }
76
120
  return generateSignature(this.provider, hash);
77
121
  }
@@ -109,7 +153,7 @@ class Safe {
109
153
  nonce: transaction.data.nonce,
110
154
  contractTransactionHash: hash,
111
155
  sender: toChecksumAddress(signerAddress),
112
- signature: transaction.encodedSignatures()
156
+ signature: transaction.encodedSignatures(),
113
157
  });
114
158
  }
115
159
  async confirmTransaction(safeTransaction) {
@@ -142,20 +186,20 @@ class Safe {
142
186
  const threshold = await this.getThreshold();
143
187
  if (threshold > safeTransaction.signatures.size) {
144
188
  const signaturesMissing = threshold - safeTransaction.signatures.size;
145
- throw new Error(`There ${signaturesMissing > 1 ? 'are' : 'is'} ${signaturesMissing} signature${signaturesMissing > 1 ? 's' : ''} missing`);
189
+ throw new Error(`There ${signaturesMissing > 1 ? "are" : "is"} ${signaturesMissing} signature${signaturesMissing > 1 ? "s" : ""} missing`);
146
190
  }
147
191
  const value = BigNumber.from(safeTransaction.data.value);
148
192
  if (!value.isZero()) {
149
193
  const balance = await this.getBalance();
150
194
  if (value.gt(BigNumber.from(balance))) {
151
- throw new Error('Not enough Ether funds');
195
+ throw new Error("Not enough Ether funds");
152
196
  }
153
197
  }
154
198
  const gasLimit = await estimateGasForTransactionExecution(contract, signerAddress, safeTransaction);
155
199
  const executionOptions = {
156
200
  gasLimit,
157
201
  gasPrice: options === null || options === void 0 ? void 0 : options.gasPrice,
158
- from: signerAddress
202
+ from: signerAddress,
159
203
  };
160
204
  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
205
  return txResponse;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rabby-wallet/gnosis-sdk",
3
- "version": "1.3.2",
3
+ "version": "1.3.4",
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/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,18 +54,26 @@ 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));
63
69
  }
64
70
 
65
- static async getPendingTransactions(safeAddress: string, network: string) {
71
+ static async getPendingTransactions(
72
+ safeAddress: string,
73
+ network: string,
74
+ nonce: number
75
+ ) {
66
76
  const request = new RequestProvider(network, Safe.adapter);
67
- const nonce = (await request.getSafeInfo(toChecksumAddress(safeAddress)))
68
- .nonce;
69
77
  const transactions = await request.getPendingTransactions(
70
78
  safeAddress,
71
79
  nonce
@@ -74,6 +82,50 @@ class Safe {
74
82
  return transactions;
75
83
  }
76
84
 
85
+ async getPendingTransactions() {
86
+ const nonce = await this.getNonce();
87
+ const transactions = await this.request.getPendingTransactions(
88
+ this.safeAddress,
89
+ nonce
90
+ );
91
+
92
+ return transactions;
93
+ }
94
+
95
+ static async getSafeVersion({
96
+ address,
97
+ provider,
98
+ }: {
99
+ address;
100
+ provider: providers.Web3Provider;
101
+ }): Promise<string> {
102
+ const contract = new Contract(
103
+ address,
104
+ [
105
+ {
106
+ constant: true,
107
+ inputs: [],
108
+ name: "VERSION",
109
+ outputs: [
110
+ {
111
+ internalType: "string",
112
+ name: "",
113
+ type: "string",
114
+ },
115
+ ],
116
+ payable: false,
117
+ stateMutability: "view",
118
+ type: "function",
119
+ },
120
+ ],
121
+ provider
122
+ );
123
+
124
+ const version = await contract.VERSION();
125
+
126
+ return version;
127
+ }
128
+
77
129
  async init() {
78
130
  const safeInfo = await Safe.getSafeInfo(this.safeAddress, this.network);
79
131
  this.safeInfo = safeInfo;
@@ -92,7 +144,7 @@ class Safe {
92
144
  return owners;
93
145
  }
94
146
 
95
- async getThreshold() {
147
+ async getThreshold(): Promise<number> {
96
148
  const threshold = await this.contract.getThreshold();
97
149
  return threshold.toNumber();
98
150
  }
@@ -102,6 +154,21 @@ class Safe {
102
154
  return nonce.toNumber();
103
155
  }
104
156
 
157
+ getBasicSafeInfo = async () => {
158
+ const [threshold, nonce, owners] = await Promise.all([
159
+ this.getThreshold(),
160
+ this.getNonce(),
161
+ this.getOwners(),
162
+ ]);
163
+ return {
164
+ address: this.safeAddress,
165
+ version: this.version,
166
+ threshold,
167
+ nonce,
168
+ owners,
169
+ };
170
+ };
171
+
105
172
  async buildTransaction(data: SafeTransactionDataPartial) {
106
173
  const transaction = await standardizeSafeTransactionData(
107
174
  this.safeAddress,
@@ -136,7 +203,7 @@ class Safe {
136
203
  (owner: string) => signerAddress && sameString(owner, signerAddress)
137
204
  );
138
205
  if (!addressIsOwner) {
139
- throw new Error('Transactions can only be signed by Safe owners');
206
+ throw new Error("Transactions can only be signed by Safe owners");
140
207
  }
141
208
  return generateSignature(this.provider, hash);
142
209
  }
@@ -177,7 +244,7 @@ class Safe {
177
244
  nonce: transaction.data.nonce,
178
245
  contractTransactionHash: hash,
179
246
  sender: toChecksumAddress(signerAddress),
180
- signature: transaction.encodedSignatures()
247
+ signature: transaction.encodedSignatures(),
181
248
  });
182
249
  }
183
250
 
@@ -221,9 +288,9 @@ class Safe {
221
288
  const signaturesMissing = threshold - safeTransaction.signatures.size;
222
289
  throw new Error(
223
290
  `There ${
224
- signaturesMissing > 1 ? 'are' : 'is'
291
+ signaturesMissing > 1 ? "are" : "is"
225
292
  } ${signaturesMissing} signature${
226
- signaturesMissing > 1 ? 's' : ''
293
+ signaturesMissing > 1 ? "s" : ""
227
294
  } missing`
228
295
  );
229
296
  }
@@ -232,7 +299,7 @@ class Safe {
232
299
  if (!value.isZero()) {
233
300
  const balance = await this.getBalance();
234
301
  if (value.gt(BigNumber.from(balance))) {
235
- throw new Error('Not enough Ether funds');
302
+ throw new Error("Not enough Ether funds");
236
303
  }
237
304
  }
238
305
 
@@ -244,7 +311,7 @@ class Safe {
244
311
  const executionOptions: TransactionOptions = {
245
312
  gasLimit,
246
313
  gasPrice: options?.gasPrice,
247
- from: signerAddress
314
+ from: signerAddress,
248
315
  };
249
316
 
250
317
  const txResponse = await contract.execTransaction(
@@ -266,3 +333,5 @@ class Safe {
266
333
  }
267
334
 
268
335
  export default Safe;
336
+
337
+ export type BasicSafeInfo = Awaited<ReturnType<Safe["getBasicSafeInfo"]>>;