@rabby-wallet/gnosis-sdk 1.2.1 → 1.3.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
@@ -1,4 +1,4 @@
1
- import { Axios } from "axios";
1
+ import { Axios, AxiosAdapter } from 'axios';
2
2
  export interface SafeInfo {
3
3
  address: string;
4
4
  fallbackHandler: string;
@@ -43,7 +43,7 @@ export interface SafeTransactionItem {
43
43
  export default class RequestProvider {
44
44
  host: string;
45
45
  request: Axios;
46
- constructor(networkId: string);
46
+ constructor(networkId: string, adapter?: AxiosAdapter);
47
47
  getPendingTransactions(safeAddress: string, nonce: number): Promise<{
48
48
  results: SafeTransactionItem[];
49
49
  }>;
package/dist/api.js CHANGED
@@ -1,19 +1,21 @@
1
- import axios from "axios";
2
- import { toChecksumAddress } from "web3-utils";
1
+ import axios from 'axios';
2
+ import { toChecksumAddress } from 'web3-utils';
3
3
  const HOST_MAP = {
4
- '1': "https://safe-transaction.gnosis.io/api/v1",
5
- '137': 'https://safe-transaction.polygon.gnosis.io/api/v1',
6
- '56': 'https://safe-transaction.bsc.gnosis.io/api/v1',
7
- '100': 'https://safe-transaction.xdai.gnosis.io/api/v1'
4
+ '1': 'https://safe-transaction-mainnet.safe.global/api/v1',
5
+ '137': 'https://safe-transaction-polygon.safe.global/api/v1',
6
+ '56': 'https://safe-transaction-bsc.safe.global/api/v1',
7
+ '100': 'https://safe-transaction-gnosis-chain.safe.global/api/v1',
8
+ '43114': 'https://safe-transaction-avalanche.safe.global/api/v1'
8
9
  };
9
10
  export default class RequestProvider {
10
- constructor(networkId) {
11
+ constructor(networkId, adapter) {
11
12
  if (!(networkId in HOST_MAP)) {
12
13
  throw new Error('Wrong networkId');
13
14
  }
14
15
  this.host = HOST_MAP[networkId];
15
16
  this.request = axios.create({
16
- baseURL: this.host
17
+ baseURL: this.host,
18
+ adapter
17
19
  });
18
20
  this.request.interceptors.response.use((response) => {
19
21
  return response.data;
@@ -23,8 +25,8 @@ export default class RequestProvider {
23
25
  return this.request.get(`/safes/${toChecksumAddress(safeAddress)}/multisig-transactions/`, {
24
26
  params: {
25
27
  executed: false,
26
- nonce__gte: nonce,
27
- },
28
+ nonce__gte: nonce
29
+ }
28
30
  });
29
31
  }
30
32
  postTransactions(safeAddres, data) {
package/dist/index.d.ts CHANGED
@@ -1,10 +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";
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';
8
9
  declare class Safe {
9
10
  contract: Contract;
10
11
  safeAddress: string;
@@ -14,6 +15,7 @@ declare class Safe {
14
15
  safeInfo: SafeInfo | null;
15
16
  request: RequestProvider;
16
17
  network: string;
18
+ static adapter: AxiosAdapter;
17
19
  constructor(safeAddress: string, version: string, provider: providers.Web3Provider, network?: string);
18
20
  static getSafeInfo(safeAddress: string, network: string): Promise<SafeInfo>;
19
21
  static getPendingTransactions(safeAddress: string, network: string): Promise<{
package/dist/index.js CHANGED
@@ -1,37 +1,38 @@
1
- import { Contract } from "ethers";
2
- import { BigNumber } from "@ethersproject/bignumber";
1
+ import { Contract } from 'ethers';
2
+ import { BigNumber } from '@ethersproject/bignumber';
3
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";
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';
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
13
  const contract = getSafeSingletonDeployment({
14
14
  version,
15
- network,
15
+ network
16
16
  });
17
17
  if (!contract) {
18
- throw new Error("Wrong version or network");
18
+ throw new Error('Wrong version or network');
19
19
  }
20
20
  this.provider = provider;
21
21
  this.contract = new Contract(safeAddress, contract.abi, this.provider);
22
22
  this.version = version;
23
23
  this.safeAddress = safeAddress;
24
24
  this.network = network;
25
- this.request = new RequestProvider(network);
25
+ this.request = new RequestProvider(network, Safe.adapter);
26
26
  this.init();
27
27
  }
28
28
  static getSafeInfo(safeAddress, network) {
29
- const request = new RequestProvider(network);
29
+ const request = new RequestProvider(network, Safe.adapter);
30
30
  return request.getSafeInfo(toChecksumAddress(safeAddress));
31
31
  }
32
32
  static async getPendingTransactions(safeAddress, network) {
33
- const request = new RequestProvider(network);
34
- const nonce = (await request.getSafeInfo(toChecksumAddress(safeAddress))).nonce;
33
+ const request = new RequestProvider(network, Safe.adapter);
34
+ const nonce = (await request.getSafeInfo(toChecksumAddress(safeAddress)))
35
+ .nonce;
35
36
  const transactions = await request.getPendingTransactions(safeAddress, nonce);
36
37
  return transactions;
37
38
  }
@@ -70,7 +71,7 @@ class Safe {
70
71
  const signerAddress = await signer.getAddress();
71
72
  const addressIsOwner = owners.find((owner) => signerAddress && sameString(owner, signerAddress));
72
73
  if (!addressIsOwner) {
73
- throw new Error("Transactions can only be signed by Safe owners");
74
+ throw new Error('Transactions can only be signed by Safe owners');
74
75
  }
75
76
  return generateSignature(this.provider, hash);
76
77
  }
@@ -108,7 +109,7 @@ class Safe {
108
109
  nonce: transaction.data.nonce,
109
110
  contractTransactionHash: hash,
110
111
  sender: toChecksumAddress(signerAddress),
111
- signature: transaction.encodedSignatures(),
112
+ signature: transaction.encodedSignatures()
112
113
  });
113
114
  }
114
115
  async confirmTransaction(safeTransaction) {
@@ -141,20 +142,20 @@ class Safe {
141
142
  const threshold = await this.getThreshold();
142
143
  if (threshold > safeTransaction.signatures.size) {
143
144
  const signaturesMissing = threshold - safeTransaction.signatures.size;
144
- throw new Error(`There ${signaturesMissing > 1 ? "are" : "is"} ${signaturesMissing} signature${signaturesMissing > 1 ? "s" : ""} missing`);
145
+ throw new Error(`There ${signaturesMissing > 1 ? 'are' : 'is'} ${signaturesMissing} signature${signaturesMissing > 1 ? 's' : ''} missing`);
145
146
  }
146
147
  const value = BigNumber.from(safeTransaction.data.value);
147
148
  if (!value.isZero()) {
148
149
  const balance = await this.getBalance();
149
150
  if (value.gt(BigNumber.from(balance))) {
150
- throw new Error("Not enough Ether funds");
151
+ throw new Error('Not enough Ether funds');
151
152
  }
152
153
  }
153
154
  const gasLimit = await estimateGasForTransactionExecution(contract, signerAddress, safeTransaction);
154
155
  const executionOptions = {
155
156
  gasLimit,
156
157
  gasPrice: options === null || options === void 0 ? void 0 : options.gasPrice,
157
- from: signerAddress,
158
+ from: signerAddress
158
159
  };
159
160
  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);
160
161
  return txResponse;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rabby-wallet/gnosis-sdk",
3
- "version": "1.2.1",
3
+ "version": "1.3.1",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
package/src/api.ts CHANGED
@@ -1,5 +1,5 @@
1
- import axios, { Axios } from "axios";
2
- import { toChecksumAddress } from "web3-utils";
1
+ import axios, { Axios, AxiosAdapter } from 'axios';
2
+ import { toChecksumAddress } from 'web3-utils';
3
3
 
4
4
  export interface SafeInfo {
5
5
  address: string;
@@ -46,26 +46,28 @@ export interface SafeTransactionItem {
46
46
  }
47
47
 
48
48
  const HOST_MAP = {
49
- '1': "https://safe-transaction.gnosis.io/api/v1",
50
- '137': 'https://safe-transaction.polygon.gnosis.io/api/v1',
51
- '56': 'https://safe-transaction.bsc.gnosis.io/api/v1',
52
- '100': 'https://safe-transaction.xdai.gnosis.io/api/v1'
53
- }
49
+ '1': 'https://safe-transaction-mainnet.safe.global/api/v1',
50
+ '137': 'https://safe-transaction-polygon.safe.global/api/v1',
51
+ '56': 'https://safe-transaction-bsc.safe.global/api/v1',
52
+ '100': 'https://safe-transaction-gnosis-chain.safe.global/api/v1',
53
+ '43114': 'https://safe-transaction-avalanche.safe.global/api/v1'
54
+ };
54
55
 
55
56
  export default class RequestProvider {
56
- host: string
57
- request: Axios
57
+ host: string;
58
+ request: Axios;
58
59
 
59
- constructor(networkId: string) {
60
+ constructor(networkId: string, adapter?: AxiosAdapter) {
60
61
  if (!(networkId in HOST_MAP)) {
61
- throw new Error('Wrong networkId')
62
+ throw new Error('Wrong networkId');
62
63
  }
63
64
 
64
- this.host = HOST_MAP[networkId]
65
+ this.host = HOST_MAP[networkId];
65
66
 
66
67
  this.request = axios.create({
67
- baseURL: this.host
68
- })
68
+ baseURL: this.host,
69
+ adapter
70
+ });
69
71
 
70
72
  this.request.interceptors.response.use((response) => {
71
73
  return response.data;
@@ -76,12 +78,15 @@ export default class RequestProvider {
76
78
  safeAddress: string,
77
79
  nonce: number
78
80
  ): Promise<{ results: SafeTransactionItem[] }> {
79
- return this.request.get(`/safes/${toChecksumAddress(safeAddress)}/multisig-transactions/`, {
80
- params: {
81
- executed: false,
82
- nonce__gte: nonce,
83
- },
84
- });
81
+ return this.request.get(
82
+ `/safes/${toChecksumAddress(safeAddress)}/multisig-transactions/`,
83
+ {
84
+ params: {
85
+ executed: false,
86
+ nonce__gte: nonce
87
+ }
88
+ }
89
+ );
85
90
  }
86
91
 
87
92
  postTransactions(safeAddres: string, data): Promise<void> {
@@ -96,6 +101,9 @@ export default class RequestProvider {
96
101
  }
97
102
 
98
103
  confirmTransaction(hash: string, data): Promise<void> {
99
- return this.request.post(`/multisig-transactions/${hash}/confirmations/`, data);
104
+ return this.request.post(
105
+ `/multisig-transactions/${hash}/confirmations/`,
106
+ data
107
+ );
100
108
  }
101
109
  }
package/src/index.ts CHANGED
@@ -1,26 +1,27 @@
1
- import { Contract } from "ethers";
2
- import { BigNumber } from "@ethersproject/bignumber";
1
+ import { Contract } from 'ethers';
2
+ import { BigNumber } from '@ethersproject/bignumber';
3
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";
4
+ import { getSafeSingletonDeployment } from '@gnosis.pm/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";
22
+ estimateGasForTransactionExecution
23
+ } from './utils';
24
+ import { AxiosAdapter } from 'axios';
24
25
 
25
26
  class Safe {
26
27
  contract: Contract;
@@ -32,36 +33,39 @@ class Safe {
32
33
  request: RequestProvider;
33
34
  network: string;
34
35
 
36
+ static adapter: AxiosAdapter;
37
+
35
38
  constructor(
36
39
  safeAddress: string,
37
40
  version: string,
38
41
  provider: providers.Web3Provider,
39
- network = "1"
42
+ network = '1'
40
43
  ) {
41
44
  const contract = getSafeSingletonDeployment({
42
45
  version,
43
- network,
46
+ network
44
47
  });
45
48
  if (!contract) {
46
- throw new Error("Wrong version or network");
49
+ throw new Error('Wrong version or network');
47
50
  }
48
51
  this.provider = provider;
49
52
  this.contract = new Contract(safeAddress, contract.abi, this.provider);
50
53
  this.version = version;
51
54
  this.safeAddress = safeAddress;
52
55
  this.network = network;
53
- this.request = new RequestProvider(network);
56
+ this.request = new RequestProvider(network, Safe.adapter);
54
57
  this.init();
55
58
  }
56
59
 
57
60
  static getSafeInfo(safeAddress: string, network: string) {
58
- const request = new RequestProvider(network);
61
+ const request = new RequestProvider(network, Safe.adapter);
59
62
  return request.getSafeInfo(toChecksumAddress(safeAddress));
60
63
  }
61
64
 
62
65
  static async getPendingTransactions(safeAddress: string, network: string) {
63
- const request = new RequestProvider(network);
64
- const nonce = (await request.getSafeInfo(toChecksumAddress(safeAddress))).nonce;
66
+ const request = new RequestProvider(network, Safe.adapter);
67
+ const nonce = (await request.getSafeInfo(toChecksumAddress(safeAddress)))
68
+ .nonce;
65
69
  const transactions = await request.getPendingTransactions(
66
70
  safeAddress,
67
71
  nonce
@@ -132,7 +136,7 @@ class Safe {
132
136
  (owner: string) => signerAddress && sameString(owner, signerAddress)
133
137
  );
134
138
  if (!addressIsOwner) {
135
- throw new Error("Transactions can only be signed by Safe owners");
139
+ throw new Error('Transactions can only be signed by Safe owners');
136
140
  }
137
141
  return generateSignature(this.provider, hash);
138
142
  }
@@ -173,7 +177,7 @@ class Safe {
173
177
  nonce: transaction.data.nonce,
174
178
  contractTransactionHash: hash,
175
179
  sender: toChecksumAddress(signerAddress),
176
- signature: transaction.encodedSignatures(),
180
+ signature: transaction.encodedSignatures()
177
181
  });
178
182
  }
179
183
 
@@ -217,9 +221,9 @@ class Safe {
217
221
  const signaturesMissing = threshold - safeTransaction.signatures.size;
218
222
  throw new Error(
219
223
  `There ${
220
- signaturesMissing > 1 ? "are" : "is"
224
+ signaturesMissing > 1 ? 'are' : 'is'
221
225
  } ${signaturesMissing} signature${
222
- signaturesMissing > 1 ? "s" : ""
226
+ signaturesMissing > 1 ? 's' : ''
223
227
  } missing`
224
228
  );
225
229
  }
@@ -228,7 +232,7 @@ class Safe {
228
232
  if (!value.isZero()) {
229
233
  const balance = await this.getBalance();
230
234
  if (value.gt(BigNumber.from(balance))) {
231
- throw new Error("Not enough Ether funds");
235
+ throw new Error('Not enough Ether funds');
232
236
  }
233
237
  }
234
238
 
@@ -240,7 +244,7 @@ class Safe {
240
244
  const executionOptions: TransactionOptions = {
241
245
  gasLimit,
242
246
  gasPrice: options?.gasPrice,
243
- from: signerAddress,
247
+ from: signerAddress
244
248
  };
245
249
 
246
250
  const txResponse = await contract.execTransaction(