@rabby-wallet/gnosis-sdk 1.2.1 → 1.3.0
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 +2 -2
- package/dist/api.js +8 -7
- package/dist/index.d.ts +9 -7
- package/dist/index.js +20 -19
- package/package.json +1 -1
- package/src/api.ts +25 -18
- package/src/index.ts +30 -26
package/dist/api.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Axios } from
|
|
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,20 @@
|
|
|
1
|
-
import axios from
|
|
2
|
-
import { toChecksumAddress } from
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import { toChecksumAddress } from 'web3-utils';
|
|
3
3
|
const HOST_MAP = {
|
|
4
|
-
'1':
|
|
4
|
+
'1': 'https://safe-transaction.gnosis.io/api/v1',
|
|
5
5
|
'137': 'https://safe-transaction.polygon.gnosis.io/api/v1',
|
|
6
6
|
'56': 'https://safe-transaction.bsc.gnosis.io/api/v1',
|
|
7
7
|
'100': 'https://safe-transaction.xdai.gnosis.io/api/v1'
|
|
8
8
|
};
|
|
9
9
|
export default class RequestProvider {
|
|
10
|
-
constructor(networkId) {
|
|
10
|
+
constructor(networkId, adapter) {
|
|
11
11
|
if (!(networkId in HOST_MAP)) {
|
|
12
12
|
throw new Error('Wrong networkId');
|
|
13
13
|
}
|
|
14
14
|
this.host = HOST_MAP[networkId];
|
|
15
15
|
this.request = axios.create({
|
|
16
|
-
baseURL: this.host
|
|
16
|
+
baseURL: this.host,
|
|
17
|
+
adapter
|
|
17
18
|
});
|
|
18
19
|
this.request.interceptors.response.use((response) => {
|
|
19
20
|
return response.data;
|
|
@@ -23,8 +24,8 @@ export default class RequestProvider {
|
|
|
23
24
|
return this.request.get(`/safes/${toChecksumAddress(safeAddress)}/multisig-transactions/`, {
|
|
24
25
|
params: {
|
|
25
26
|
executed: false,
|
|
26
|
-
nonce__gte: nonce
|
|
27
|
-
}
|
|
27
|
+
nonce__gte: nonce
|
|
28
|
+
}
|
|
28
29
|
});
|
|
29
30
|
}
|
|
30
31
|
postTransactions(safeAddres, data) {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { Contract } from
|
|
2
|
-
import { BigNumber } from
|
|
3
|
-
import { providers } from
|
|
4
|
-
import { SafeTransactionDataPartial, SafeSignature } from
|
|
5
|
-
import { TransactionResult, TransactionOptions } from
|
|
6
|
-
import SafeTransaction from
|
|
7
|
-
import RequestProvider, { SafeInfo } from
|
|
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
|
|
2
|
-
import { BigNumber } from
|
|
1
|
+
import { Contract } from 'ethers';
|
|
2
|
+
import { BigNumber } from '@ethersproject/bignumber';
|
|
3
3
|
import BN from 'bignumber.js';
|
|
4
|
-
import { getSafeSingletonDeployment } from
|
|
5
|
-
import { toChecksumAddress } from
|
|
6
|
-
import SafeTransaction from
|
|
7
|
-
import RequestProvider from
|
|
8
|
-
import { standardizeSafeTransactionData, sameString, generateSignature, generatePreValidatedSignature, estimateGasForTransactionExecution
|
|
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 =
|
|
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(
|
|
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)))
|
|
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(
|
|
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 ?
|
|
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(
|
|
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
package/src/api.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import axios, { Axios } from
|
|
2
|
-
import { toChecksumAddress } from
|
|
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,27 @@ export interface SafeTransactionItem {
|
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
const HOST_MAP = {
|
|
49
|
-
'1':
|
|
49
|
+
'1': 'https://safe-transaction.gnosis.io/api/v1',
|
|
50
50
|
'137': 'https://safe-transaction.polygon.gnosis.io/api/v1',
|
|
51
51
|
'56': 'https://safe-transaction.bsc.gnosis.io/api/v1',
|
|
52
52
|
'100': 'https://safe-transaction.xdai.gnosis.io/api/v1'
|
|
53
|
-
}
|
|
53
|
+
};
|
|
54
54
|
|
|
55
55
|
export default class RequestProvider {
|
|
56
|
-
host: string
|
|
57
|
-
request: Axios
|
|
56
|
+
host: string;
|
|
57
|
+
request: Axios;
|
|
58
58
|
|
|
59
|
-
constructor(networkId: string) {
|
|
59
|
+
constructor(networkId: string, adapter?: AxiosAdapter) {
|
|
60
60
|
if (!(networkId in HOST_MAP)) {
|
|
61
|
-
throw new Error('Wrong networkId')
|
|
61
|
+
throw new Error('Wrong networkId');
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
this.host = HOST_MAP[networkId]
|
|
64
|
+
this.host = HOST_MAP[networkId];
|
|
65
65
|
|
|
66
66
|
this.request = axios.create({
|
|
67
|
-
baseURL: this.host
|
|
68
|
-
|
|
67
|
+
baseURL: this.host,
|
|
68
|
+
adapter
|
|
69
|
+
});
|
|
69
70
|
|
|
70
71
|
this.request.interceptors.response.use((response) => {
|
|
71
72
|
return response.data;
|
|
@@ -76,12 +77,15 @@ export default class RequestProvider {
|
|
|
76
77
|
safeAddress: string,
|
|
77
78
|
nonce: number
|
|
78
79
|
): Promise<{ results: SafeTransactionItem[] }> {
|
|
79
|
-
return this.request.get(
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
80
|
+
return this.request.get(
|
|
81
|
+
`/safes/${toChecksumAddress(safeAddress)}/multisig-transactions/`,
|
|
82
|
+
{
|
|
83
|
+
params: {
|
|
84
|
+
executed: false,
|
|
85
|
+
nonce__gte: nonce
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
);
|
|
85
89
|
}
|
|
86
90
|
|
|
87
91
|
postTransactions(safeAddres: string, data): Promise<void> {
|
|
@@ -96,6 +100,9 @@ export default class RequestProvider {
|
|
|
96
100
|
}
|
|
97
101
|
|
|
98
102
|
confirmTransaction(hash: string, data): Promise<void> {
|
|
99
|
-
return this.request.post(
|
|
103
|
+
return this.request.post(
|
|
104
|
+
`/multisig-transactions/${hash}/confirmations/`,
|
|
105
|
+
data
|
|
106
|
+
);
|
|
100
107
|
}
|
|
101
108
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,26 +1,27 @@
|
|
|
1
|
-
import { Contract } from
|
|
2
|
-
import { BigNumber } from
|
|
1
|
+
import { Contract } from 'ethers';
|
|
2
|
+
import { BigNumber } from '@ethersproject/bignumber';
|
|
3
3
|
import BN from 'bignumber.js';
|
|
4
|
-
import { getSafeSingletonDeployment } from
|
|
5
|
-
import { providers } from
|
|
6
|
-
import { toChecksumAddress } from
|
|
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
|
|
9
|
+
SafeSignature
|
|
10
|
+
} from '@gnosis.pm/safe-core-sdk-types';
|
|
11
11
|
import {
|
|
12
12
|
TransactionResult,
|
|
13
|
-
TransactionOptions
|
|
14
|
-
} from
|
|
15
|
-
import SafeTransaction from
|
|
16
|
-
import RequestProvider, { SafeInfo } from
|
|
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
|
|
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 =
|
|
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(
|
|
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)))
|
|
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(
|
|
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 ?
|
|
224
|
+
signaturesMissing > 1 ? 'are' : 'is'
|
|
221
225
|
} ${signaturesMissing} signature${
|
|
222
|
-
signaturesMissing > 1 ?
|
|
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(
|
|
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(
|