@rabby-wallet/gnosis-sdk 1.3.10 → 1.4.0-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 +4 -4
- package/dist/api.js +31 -31
- package/dist/index.d.ts +9 -12
- package/dist/index.js +16 -34
- package/dist/type.d.ts +1 -2
- package/dist/utils.d.ts +3 -3
- package/dist/utils.js +11 -11
- package/package.json +8 -12
- package/src/api.ts +34 -35
- package/src/index.ts +24 -45
- package/src/type.ts +3 -5
- package/src/utils.ts +10 -10
- package/tsconfig.json +1 -1
package/dist/api.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SafeTransactionDataPartial } from "@
|
|
1
|
+
import { SafeTransactionDataPartial } from "@safe-global/types-kit";
|
|
2
2
|
import { Axios, AxiosAdapter } from "axios";
|
|
3
3
|
export interface SafeInfo {
|
|
4
4
|
address: string;
|
|
@@ -6,7 +6,7 @@ export interface SafeInfo {
|
|
|
6
6
|
guard: string;
|
|
7
7
|
masterCopy: string;
|
|
8
8
|
modules: string[];
|
|
9
|
-
nonce:
|
|
9
|
+
nonce: string;
|
|
10
10
|
owners: string[];
|
|
11
11
|
threshold: number;
|
|
12
12
|
version: string;
|
|
@@ -128,7 +128,7 @@ export default class RequestProvider {
|
|
|
128
128
|
}>;
|
|
129
129
|
postTransactions(safeAddres: string, data: any): Promise<void>;
|
|
130
130
|
getSafeInfo(safeAddress: string): Promise<SafeInfo>;
|
|
131
|
-
confirmTransaction(
|
|
132
|
-
getSafeTxGas(safeAddress: string, safeVersion: string, safeTxData: SafeTransactionDataPartial): Promise<
|
|
131
|
+
confirmTransaction(safeTransactionHash: string, data: any): Promise<void>;
|
|
132
|
+
getSafeTxGas(safeAddress: string, safeVersion: string, safeTxData: SafeTransactionDataPartial): Promise<string | undefined>;
|
|
133
133
|
}
|
|
134
134
|
export {};
|
package/dist/api.js
CHANGED
|
@@ -1,83 +1,83 @@
|
|
|
1
|
+
import { ethers } from "ethers";
|
|
1
2
|
import { isLegacyVersion } from "./utils";
|
|
2
3
|
import axios from "axios";
|
|
3
|
-
import { toChecksumAddress } from "web3-utils";
|
|
4
4
|
export const HOST_MAP = {
|
|
5
5
|
/**
|
|
6
6
|
* eth
|
|
7
7
|
*/
|
|
8
|
-
"1": "https://safe-
|
|
8
|
+
"1": "https://safe-txs-mainnet.rabby.io/api",
|
|
9
9
|
/**
|
|
10
10
|
* polygon
|
|
11
11
|
*/
|
|
12
|
-
"137": "https://safe-transaction-polygon.safe.global/api
|
|
12
|
+
"137": "https://safe-transaction-polygon.safe.global/api",
|
|
13
13
|
/**
|
|
14
14
|
* bsc
|
|
15
15
|
*/
|
|
16
|
-
"56": "https://safe-transaction-bsc.safe.global/api
|
|
16
|
+
"56": "https://safe-transaction-bsc.safe.global/api",
|
|
17
17
|
/**
|
|
18
18
|
* Gnosis Chain
|
|
19
19
|
*/
|
|
20
|
-
"100": "https://safe-transaction-gnosis-chain.safe.global/api
|
|
20
|
+
"100": "https://safe-transaction-gnosis-chain.safe.global/api",
|
|
21
21
|
/**
|
|
22
22
|
* avalanche
|
|
23
23
|
*/
|
|
24
|
-
"43114": "https://safe-transaction-avalanche.safe.global/api
|
|
24
|
+
"43114": "https://safe-transaction-avalanche.safe.global/api",
|
|
25
25
|
/**
|
|
26
26
|
* arbitrum
|
|
27
27
|
*/
|
|
28
|
-
"42161": "https://safe-transaction-arbitrum.safe.global/api
|
|
28
|
+
"42161": "https://safe-transaction-arbitrum.safe.global/api",
|
|
29
29
|
/**
|
|
30
30
|
* Optimism
|
|
31
31
|
*/
|
|
32
|
-
"10": "https://safe-transaction-optimism.safe.global/api
|
|
32
|
+
"10": "https://safe-transaction-optimism.safe.global/api",
|
|
33
33
|
/**
|
|
34
34
|
* Aurora
|
|
35
35
|
*/
|
|
36
|
-
"1313161554": "https://safe-transaction-aurora.safe.global/api
|
|
36
|
+
"1313161554": "https://safe-transaction-aurora.safe.global/api",
|
|
37
37
|
/**
|
|
38
38
|
* Base
|
|
39
39
|
*/
|
|
40
|
-
"8453": "https://safe-transaction-base.safe.global/api
|
|
40
|
+
"8453": "https://safe-transaction-base.safe.global/api",
|
|
41
41
|
/**
|
|
42
42
|
* Celo
|
|
43
43
|
*/
|
|
44
|
-
"42220": "https://safe-transaction-celo.safe.global/api
|
|
44
|
+
"42220": "https://safe-transaction-celo.safe.global/api",
|
|
45
45
|
/**
|
|
46
46
|
* Polygon zkEVM
|
|
47
47
|
*/
|
|
48
|
-
"1101": "https://safe-transaction-zkevm.safe.global/api
|
|
48
|
+
"1101": "https://safe-transaction-zkevm.safe.global/api",
|
|
49
49
|
/**
|
|
50
50
|
* zksync era
|
|
51
51
|
*/
|
|
52
|
-
"324": "https://safe-transaction-zksync.safe.global/api
|
|
52
|
+
"324": "https://safe-transaction-zksync.safe.global/api",
|
|
53
53
|
/**
|
|
54
54
|
* scroll
|
|
55
55
|
*/
|
|
56
|
-
"534352": "https://safe-transaction-scroll.safe.global/api
|
|
56
|
+
"534352": "https://safe-transaction-scroll.safe.global/api",
|
|
57
57
|
/**
|
|
58
58
|
* linea
|
|
59
59
|
*/
|
|
60
|
-
"59144": "https://safe-transaction-linea.safe.global/api
|
|
60
|
+
"59144": "https://safe-transaction-linea.safe.global/api",
|
|
61
61
|
/**
|
|
62
62
|
* X Layer
|
|
63
63
|
*/
|
|
64
|
-
"196": "https://safe-transaction-xlayer.safe.global/api
|
|
64
|
+
"196": "https://safe-transaction-xlayer.safe.global/api",
|
|
65
65
|
/**
|
|
66
66
|
* mantle
|
|
67
67
|
*/
|
|
68
|
-
"5000": "https://safe-transaction-mantle.safe.global/api
|
|
68
|
+
"5000": "https://safe-transaction-mantle.safe.global/api",
|
|
69
69
|
/**
|
|
70
70
|
* World Chain
|
|
71
71
|
*/
|
|
72
|
-
"480": "https://safe-transaction-worldchain.safe.global/api
|
|
72
|
+
"480": "https://safe-transaction-worldchain.safe.global/api",
|
|
73
73
|
/**
|
|
74
74
|
* blast
|
|
75
75
|
*/
|
|
76
|
-
"81457": "https://safe-transaction-blast.safe.global/api
|
|
76
|
+
"81457": "https://safe-transaction-blast.safe.global/api",
|
|
77
77
|
/**
|
|
78
78
|
* Sonic
|
|
79
79
|
*/
|
|
80
|
-
"146": "https://safe-transaction-sonic.safe.global/api
|
|
80
|
+
"146": "https://safe-transaction-sonic.safe.global/api",
|
|
81
81
|
};
|
|
82
82
|
export default class RequestProvider {
|
|
83
83
|
constructor(networkId, adapter) {
|
|
@@ -94,7 +94,7 @@ export default class RequestProvider {
|
|
|
94
94
|
});
|
|
95
95
|
}
|
|
96
96
|
getPendingTransactions(safeAddress, nonce) {
|
|
97
|
-
return this.request.get(`/safes/${
|
|
97
|
+
return this.request.get(`/v1/safes/${ethers.utils.getAddress(safeAddress)}/multisig-transactions/`, {
|
|
98
98
|
params: {
|
|
99
99
|
executed: false,
|
|
100
100
|
nonce__gte: nonce,
|
|
@@ -102,29 +102,29 @@ export default class RequestProvider {
|
|
|
102
102
|
});
|
|
103
103
|
}
|
|
104
104
|
postTransactions(safeAddres, data) {
|
|
105
|
-
return this.request.post(`/safes/${
|
|
105
|
+
return this.request.post(`/v1/safes/${ethers.utils.getAddress(safeAddres)}/multisig-transactions/`, data);
|
|
106
106
|
}
|
|
107
107
|
getSafeInfo(safeAddress) {
|
|
108
|
-
return this.request.get(`/safes/${
|
|
108
|
+
return this.request.get(`/v1/safes/${ethers.utils.getAddress(safeAddress)}/`);
|
|
109
109
|
}
|
|
110
|
-
confirmTransaction(
|
|
111
|
-
return this.request.post(`/multisig-transactions/${
|
|
110
|
+
confirmTransaction(safeTransactionHash, data) {
|
|
111
|
+
return this.request.post(`/v1/multisig-transactions/${safeTransactionHash}/confirmations/`, data);
|
|
112
112
|
}
|
|
113
113
|
// https://github.com/safe-global/safe-wallet-web/blob/dev/src/services/tx/tx-sender/recommendedNonce.ts#L24
|
|
114
114
|
async getSafeTxGas(safeAddress, safeVersion, safeTxData) {
|
|
115
115
|
const isSafeTxGasRequired = isLegacyVersion(safeVersion);
|
|
116
116
|
// For 1.3.0+ Safes safeTxGas is not required
|
|
117
117
|
if (!isSafeTxGasRequired)
|
|
118
|
-
return 0;
|
|
119
|
-
const address =
|
|
118
|
+
return "0";
|
|
119
|
+
const address = ethers.utils.getAddress(safeAddress);
|
|
120
120
|
try {
|
|
121
|
-
const estimation = await this.request.post(`/safes/${address}/multisig-transactions/estimations/`, {
|
|
122
|
-
to:
|
|
123
|
-
value:
|
|
121
|
+
const estimation = await this.request.post(`/v1/safes/${address}/multisig-transactions/estimations/`, {
|
|
122
|
+
to: ethers.utils.getAddress(safeTxData.to),
|
|
123
|
+
value: safeTxData.value || "0",
|
|
124
124
|
data: safeTxData.data,
|
|
125
125
|
operation: safeTxData.operation,
|
|
126
126
|
});
|
|
127
|
-
return
|
|
127
|
+
return estimation.safeTxGas;
|
|
128
128
|
}
|
|
129
129
|
catch (e) {
|
|
130
130
|
console.error(e);
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
import { BigNumber } from "@ethersproject/bignumber";
|
|
2
|
-
import { SafeSignature, SafeTransactionDataPartial } from "@gnosis.pm/safe-core-sdk-types";
|
|
3
|
-
import SafeTransaction from "@gnosis.pm/safe-core-sdk/dist/src/utils/transactions/SafeTransaction";
|
|
4
|
-
import { TransactionOptions, TransactionResult } from "@gnosis.pm/safe-core-sdk/dist/src/utils/transactions/types";
|
|
5
|
-
import SafeApiKit, { SafeMessage as ApiKitSafeMessage } from "@safe-global/api-kit";
|
|
6
|
-
import SafeMessage from "@safe-global/protocol-kit/dist/src/utils/messages/SafeMessage";
|
|
7
|
-
import { SafeClientResult } from "@safe-global/sdk-starter-kit";
|
|
8
2
|
import { AxiosAdapter } from "axios";
|
|
9
3
|
import { Contract, providers } from "ethers";
|
|
4
|
+
import { TransactionOptions, TransactionResult, SafeSignature, SafeTransaction, SafeTransactionDataPartial } from "@safe-global/types-kit";
|
|
5
|
+
import { EthSafeMessage, EthSafeTransaction } from "@safe-global/protocol-kit";
|
|
6
|
+
import SafeApiKit, { SafeMessage as ApiKitSafeMessage } from "@safe-global/api-kit";
|
|
10
7
|
import RequestProvider, { SafeInfo } from "./api";
|
|
11
8
|
declare class Safe {
|
|
12
9
|
contract: Contract;
|
|
@@ -35,7 +32,7 @@ declare class Safe {
|
|
|
35
32
|
results: import("./api").SafeTransactionItem[];
|
|
36
33
|
}>;
|
|
37
34
|
static getSafeVersion({ address, provider, }: {
|
|
38
|
-
address:
|
|
35
|
+
address: string;
|
|
39
36
|
provider: providers.Web3Provider;
|
|
40
37
|
}): Promise<string>;
|
|
41
38
|
init(): Promise<void>;
|
|
@@ -49,7 +46,7 @@ declare class Safe {
|
|
|
49
46
|
nonce: number;
|
|
50
47
|
owners: string[];
|
|
51
48
|
}>;
|
|
52
|
-
buildTransaction(data: SafeTransactionDataPartial): Promise<
|
|
49
|
+
buildTransaction(data: SafeTransactionDataPartial): Promise<EthSafeTransaction>;
|
|
53
50
|
getTransactionHash(transaction: SafeTransaction): Promise<any>;
|
|
54
51
|
signTransactionHash(hash: string): Promise<SafeSignature>;
|
|
55
52
|
signTransaction(transaction: SafeTransaction): Promise<void>;
|
|
@@ -71,12 +68,12 @@ declare class Safe {
|
|
|
71
68
|
* - If the threshold > 1, remember to confirmMessage() after sendMessage()
|
|
72
69
|
* - If the threshold = 1, then the message is confirmed and valid immediately
|
|
73
70
|
*
|
|
74
|
-
* @param {
|
|
71
|
+
* @param {EthSafeMessage} safeMessage The message
|
|
75
72
|
* @returns {Promise<SafeClientResult>} The SafeClientResult
|
|
76
73
|
*/
|
|
77
|
-
addMessage({ safeMessage }: {
|
|
78
|
-
safeMessage:
|
|
79
|
-
}): Promise<
|
|
74
|
+
addMessage({ safeMessage, }: {
|
|
75
|
+
safeMessage: EthSafeMessage;
|
|
76
|
+
}): Promise<void>;
|
|
80
77
|
}
|
|
81
78
|
export default Safe;
|
|
82
79
|
export type BasicSafeInfo = Awaited<ReturnType<Safe["getBasicSafeInfo"]>>;
|
package/dist/index.js
CHANGED
|
@@ -1,15 +1,10 @@
|
|
|
1
1
|
import { BigNumber } from "@ethersproject/bignumber";
|
|
2
|
-
import
|
|
2
|
+
import { Contract, ethers } from "ethers";
|
|
3
|
+
import { EthSafeTransaction } from "@safe-global/protocol-kit";
|
|
4
|
+
import { calculateSafeMessageHash } from "@safe-global/protocol-kit/dist/src/utils";
|
|
3
5
|
import SafeApiKit from "@safe-global/api-kit";
|
|
4
6
|
import { TRANSACTION_SERVICE_URLS } from "@safe-global/api-kit/dist/src/utils/config";
|
|
5
|
-
import { hashSafeMessage } from "@safe-global/protocol-kit";
|
|
6
|
-
import { calculateSafeMessageHash } from "@safe-global/protocol-kit/dist/src/utils";
|
|
7
7
|
import { getSafeSingletonDeployment } from "@safe-global/safe-deployments";
|
|
8
|
-
import { SafeClientTxStatus } from "@safe-global/sdk-starter-kit/dist/src/constants";
|
|
9
|
-
import { createSafeClientResult } from "@safe-global/sdk-starter-kit/dist/src/utils";
|
|
10
|
-
import BN from "bignumber.js";
|
|
11
|
-
import { Contract } from "ethers";
|
|
12
|
-
import { toChecksumAddress } from "web3-utils";
|
|
13
8
|
import RequestProvider, { HOST_MAP } from "./api";
|
|
14
9
|
import { estimateGasForTransactionExecution, generatePreValidatedSignature, generateSignature, sameString, standardizeSafeTransactionData, } from "./utils";
|
|
15
10
|
class Safe {
|
|
@@ -44,7 +39,7 @@ class Safe {
|
|
|
44
39
|
const safeAddress = this.safeAddress;
|
|
45
40
|
const safeVersion = this.version;
|
|
46
41
|
const chainId = BigInt(this.network);
|
|
47
|
-
return calculateSafeMessageHash(
|
|
42
|
+
return calculateSafeMessageHash(ethers.utils.getAddress(safeAddress), messageHash, safeVersion, chainId);
|
|
48
43
|
};
|
|
49
44
|
const contract = getSafeSingletonDeployment({
|
|
50
45
|
version,
|
|
@@ -70,7 +65,7 @@ class Safe {
|
|
|
70
65
|
*/
|
|
71
66
|
static getSafeInfo(safeAddress, network) {
|
|
72
67
|
const request = new RequestProvider(network, Safe.adapter);
|
|
73
|
-
return request.getSafeInfo(
|
|
68
|
+
return request.getSafeInfo(ethers.utils.getAddress(safeAddress));
|
|
74
69
|
}
|
|
75
70
|
static async getPendingTransactions(safeAddress, network, nonce) {
|
|
76
71
|
const request = new RequestProvider(network, Safe.adapter);
|
|
@@ -126,7 +121,7 @@ class Safe {
|
|
|
126
121
|
}
|
|
127
122
|
async buildTransaction(data) {
|
|
128
123
|
const transaction = await standardizeSafeTransactionData(this.safeAddress, this.contract, this.provider, data, this.network, this.version);
|
|
129
|
-
return new
|
|
124
|
+
return new EthSafeTransaction(transaction);
|
|
130
125
|
}
|
|
131
126
|
async getTransactionHash(transaction) {
|
|
132
127
|
const transactionData = transaction.data;
|
|
@@ -161,11 +156,11 @@ class Safe {
|
|
|
161
156
|
async postTransaction(transaction, hash) {
|
|
162
157
|
const signer = this.provider.getSigner(0);
|
|
163
158
|
const signerAddress = await signer.getAddress();
|
|
164
|
-
const safeAddress =
|
|
159
|
+
const safeAddress = ethers.utils.getAddress(this.safeAddress);
|
|
165
160
|
await this.request.postTransactions(this.safeAddress, {
|
|
166
161
|
safe: safeAddress,
|
|
167
|
-
to:
|
|
168
|
-
value:
|
|
162
|
+
to: ethers.utils.getAddress(transaction.data.to),
|
|
163
|
+
value: transaction.data.value,
|
|
169
164
|
data: transaction.data.data,
|
|
170
165
|
operation: transaction.data.operation,
|
|
171
166
|
gasToken: transaction.data.gasToken,
|
|
@@ -175,7 +170,7 @@ class Safe {
|
|
|
175
170
|
refundReceiver: transaction.data.refundReceiver,
|
|
176
171
|
nonce: transaction.data.nonce,
|
|
177
172
|
contractTransactionHash: hash,
|
|
178
|
-
sender:
|
|
173
|
+
sender: ethers.utils.getAddress(signerAddress),
|
|
179
174
|
signature: transaction.encodedSignatures(),
|
|
180
175
|
});
|
|
181
176
|
}
|
|
@@ -185,7 +180,7 @@ class Safe {
|
|
|
185
180
|
safeTransaction.addSignature(signature);
|
|
186
181
|
const signer = await this.provider.getSigner(0);
|
|
187
182
|
const signerAddress = await signer.getAddress();
|
|
188
|
-
const sig = safeTransaction.signatures.get(signerAddress
|
|
183
|
+
const sig = safeTransaction.signatures.get(signerAddress?.toLowerCase());
|
|
189
184
|
if (sig) {
|
|
190
185
|
await this.request.confirmTransaction(hash, { signature: sig.data });
|
|
191
186
|
}
|
|
@@ -221,7 +216,7 @@ class Safe {
|
|
|
221
216
|
const gasLimit = await estimateGasForTransactionExecution(contract, signerAddress, safeTransaction);
|
|
222
217
|
const executionOptions = {
|
|
223
218
|
gasLimit,
|
|
224
|
-
gasPrice: options
|
|
219
|
+
gasPrice: options?.gasPrice,
|
|
225
220
|
from: signerAddress,
|
|
226
221
|
};
|
|
227
222
|
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);
|
|
@@ -232,15 +227,13 @@ class Safe {
|
|
|
232
227
|
* - If the threshold > 1, remember to confirmMessage() after sendMessage()
|
|
233
228
|
* - If the threshold = 1, then the message is confirmed and valid immediately
|
|
234
229
|
*
|
|
235
|
-
* @param {
|
|
230
|
+
* @param {EthSafeMessage} safeMessage The message
|
|
236
231
|
* @returns {Promise<SafeClientResult>} The SafeClientResult
|
|
237
232
|
*/
|
|
238
|
-
async addMessage({ safeMessage }) {
|
|
233
|
+
async addMessage({ safeMessage, }) {
|
|
239
234
|
const safeAddress = this.safeAddress;
|
|
240
|
-
const threshold = await this.getThreshold();
|
|
241
|
-
const messageHash = await this.getSafeMessageHash(hashSafeMessage(safeMessage.data));
|
|
242
235
|
try {
|
|
243
|
-
|
|
236
|
+
return this.apiKit.addMessage(safeAddress, {
|
|
244
237
|
message: safeMessage.data,
|
|
245
238
|
signature: safeMessage.encodedSignatures(),
|
|
246
239
|
});
|
|
@@ -248,23 +241,12 @@ class Safe {
|
|
|
248
241
|
catch (error) {
|
|
249
242
|
throw new Error("Could not add a new off-chain message to the Safe account");
|
|
250
243
|
}
|
|
251
|
-
const message = await this.apiKit.getMessage(messageHash);
|
|
252
|
-
return createSafeClientResult({
|
|
253
|
-
safeAddress: this.safeAddress,
|
|
254
|
-
status: message.confirmations.length === threshold
|
|
255
|
-
? SafeClientTxStatus.MESSAGE_CONFIRMED
|
|
256
|
-
: SafeClientTxStatus.MESSAGE_PENDING_SIGNATURES,
|
|
257
|
-
messageHash,
|
|
258
|
-
});
|
|
259
244
|
}
|
|
260
245
|
}
|
|
261
246
|
Safe.createSafeApiKit = (network) => {
|
|
262
|
-
var _a;
|
|
263
247
|
return new SafeApiKit({
|
|
264
248
|
chainId: BigInt(network),
|
|
265
|
-
txServiceUrl: TRANSACTION_SERVICE_URLS[network] ||
|
|
266
|
-
((_a = HOST_MAP[network]) === null || _a === void 0 ? void 0 : _a.replace(/\/v1$/, "")) ||
|
|
267
|
-
undefined,
|
|
249
|
+
txServiceUrl: HOST_MAP[network] || TRANSACTION_SERVICE_URLS[network] || undefined,
|
|
268
250
|
});
|
|
269
251
|
};
|
|
270
252
|
export default Safe;
|
package/dist/type.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { BigNumber } from "@ethersproject/bignumber";
|
|
2
|
-
import { SafeTransaction, SafeTransactionData } from "@
|
|
3
|
-
import { TransactionOptions, TransactionResult } from "@gnosis.pm/safe-core-sdk/dist/src/utils/transactions/types";
|
|
2
|
+
import { TransactionOptions, TransactionResult, SafeTransaction, SafeTransactionData } from "@safe-global/types-kit";
|
|
4
3
|
export interface GnosisSafeContract {
|
|
5
4
|
getVersion(): Promise<string>;
|
|
6
5
|
getAddress(): string;
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Contract, providers } from "ethers";
|
|
2
|
-
import { OperationType,
|
|
3
|
-
import
|
|
2
|
+
import { OperationType, SafeSignature, SafeTransaction, SafeTransactionData, SafeTransactionDataPartial } from "@safe-global/types-kit";
|
|
3
|
+
import { EthSafeSignature } from "@safe-global/protocol-kit";
|
|
4
4
|
export declare function sameString(str1: string, str2: string): boolean;
|
|
5
5
|
export declare function isRestrictedAddress(address: string): boolean;
|
|
6
6
|
export declare const isLegacyVersion: (safeVersion: string) => boolean;
|
|
@@ -9,5 +9,5 @@ export declare function standardizeSafeTransactionData(safeAddress: string, safe
|
|
|
9
9
|
export declare function generatePreValidatedSignature(ownerAddress: string): SafeSignature;
|
|
10
10
|
export declare function isTxHashSignedWithPrefix(txHash: string, signature: string, ownerAddress: string): boolean;
|
|
11
11
|
export declare function adjustVInSignature(signature: string, hasPrefix: boolean): string;
|
|
12
|
-
export declare function generateSignature(provider: providers.Web3Provider, hash: string): Promise<
|
|
12
|
+
export declare function generateSignature(provider: providers.Web3Provider, hash: string): Promise<EthSafeSignature>;
|
|
13
13
|
export declare function estimateGasForTransactionExecution(safeContract: Contract, from: string, tx: SafeTransaction): Promise<number>;
|
package/dist/utils.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { BigNumber } from "@ethersproject/bignumber";
|
|
2
|
-
import { OperationType
|
|
2
|
+
import { OperationType } from "@safe-global/types-kit";
|
|
3
|
+
import { EthSafeSignature } from "@safe-global/protocol-kit";
|
|
3
4
|
import { bufferToHex, ecrecover, pubToAddress } from "ethereumjs-util";
|
|
4
5
|
import { ZERO_ADDRESS, SENTINEL_ADDRESS } from "./constants";
|
|
5
|
-
import EthSignSignature from "@gnosis.pm/safe-core-sdk/dist/src/utils/signatures/SafeSignature";
|
|
6
6
|
import semverSatisfies from "semver/functions/satisfies";
|
|
7
7
|
import RequestProvider from "./api";
|
|
8
8
|
import Safe from "./index";
|
|
@@ -86,23 +86,23 @@ export async function estimateTxGas(safeAddress, safeContract, provider, to, val
|
|
|
86
86
|
}
|
|
87
87
|
}
|
|
88
88
|
export async function standardizeSafeTransactionData(safeAddress, safeContract, provider, tx, network, version) {
|
|
89
|
-
var _a, _b, _c, _d, _e;
|
|
90
89
|
const standardizedTxs = {
|
|
91
90
|
to: tx.to,
|
|
92
91
|
value: tx.value,
|
|
93
92
|
data: tx.data,
|
|
94
|
-
operation:
|
|
95
|
-
baseGas:
|
|
96
|
-
gasPrice:
|
|
93
|
+
operation: tx.operation ?? OperationType.Call,
|
|
94
|
+
baseGas: tx.baseGas ?? "0",
|
|
95
|
+
gasPrice: tx.gasPrice ?? "0",
|
|
97
96
|
gasToken: tx.gasToken || ZERO_ADDRESS,
|
|
98
97
|
refundReceiver: tx.refundReceiver || ZERO_ADDRESS,
|
|
99
|
-
nonce:
|
|
98
|
+
nonce: tx.nonce ?? (await safeContract.nonce()).toNumber(),
|
|
100
99
|
};
|
|
101
100
|
const request = new RequestProvider(network, Safe.adapter);
|
|
102
|
-
const safeTxGas =
|
|
101
|
+
const safeTxGas = tx.safeTxGas ??
|
|
102
|
+
(await request.getSafeTxGas(safeAddress, version, standardizedTxs));
|
|
103
103
|
return {
|
|
104
104
|
...standardizedTxs,
|
|
105
|
-
safeTxGas: safeTxGas || 0,
|
|
105
|
+
safeTxGas: safeTxGas || "0",
|
|
106
106
|
};
|
|
107
107
|
}
|
|
108
108
|
export function generatePreValidatedSignature(ownerAddress) {
|
|
@@ -110,7 +110,7 @@ export function generatePreValidatedSignature(ownerAddress) {
|
|
|
110
110
|
ownerAddress.slice(2) +
|
|
111
111
|
"0000000000000000000000000000000000000000000000000000000000000000" +
|
|
112
112
|
"01";
|
|
113
|
-
return new
|
|
113
|
+
return new EthSafeSignature(ownerAddress, signature);
|
|
114
114
|
}
|
|
115
115
|
export function isTxHashSignedWithPrefix(txHash, signature, ownerAddress) {
|
|
116
116
|
let hasPrefix;
|
|
@@ -151,7 +151,7 @@ export async function generateSignature(provider, hash) {
|
|
|
151
151
|
let signature = await provider.send("personal_sign", [hash, signerAddress]);
|
|
152
152
|
const hasPrefix = isTxHashSignedWithPrefix(hash, signature, signerAddress);
|
|
153
153
|
signature = adjustVInSignature(signature, hasPrefix);
|
|
154
|
-
return new
|
|
154
|
+
return new EthSafeSignature(signerAddress, signature);
|
|
155
155
|
}
|
|
156
156
|
export async function estimateGasForTransactionExecution(safeContract, from, tx) {
|
|
157
157
|
try {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rabby-wallet/gnosis-sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0-alpha-1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -14,22 +14,18 @@
|
|
|
14
14
|
"@ethersproject/contracts": "5.5.0",
|
|
15
15
|
"@ethersproject/providers": "5.5.0",
|
|
16
16
|
"@ethersproject/solidity": "5.5.0",
|
|
17
|
-
"@
|
|
18
|
-
"@
|
|
19
|
-
"@safe-global/
|
|
20
|
-
"@safe-global/
|
|
21
|
-
"@safe-global/safe-deployments": "1.37.22",
|
|
22
|
-
"@safe-global/sdk-starter-kit": "1.1.1",
|
|
23
|
-
"@safe-global/types-kit": "1.0.1",
|
|
17
|
+
"@safe-global/api-kit": "2.5.8",
|
|
18
|
+
"@safe-global/protocol-kit": "5.2.1",
|
|
19
|
+
"@safe-global/safe-deployments": "1.37.28",
|
|
20
|
+
"@safe-global/types-kit": "1.0.2",
|
|
24
21
|
"axios": "0.24.0",
|
|
25
|
-
"bignumber.js": "9.0.2",
|
|
26
22
|
"ethereumjs-util": "7.1.3",
|
|
27
23
|
"ethers": "5.5.1",
|
|
28
|
-
"semver": "7.5.4"
|
|
29
|
-
"web3-core": "1.6.0"
|
|
24
|
+
"semver": "7.5.4"
|
|
30
25
|
},
|
|
31
26
|
"devDependencies": {
|
|
32
27
|
"@types/node": "20.3.3",
|
|
33
28
|
"typescript": "5.3.3"
|
|
34
|
-
}
|
|
29
|
+
},
|
|
30
|
+
"packageManager": "yarn@1.22.22"
|
|
35
31
|
}
|
package/src/api.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { SafeTransactionDataPartial } from "@
|
|
1
|
+
import { SafeTransactionDataPartial } from "@safe-global/types-kit";
|
|
2
|
+
import { ethers } from "ethers";
|
|
2
3
|
import { isLegacyVersion } from "./utils";
|
|
3
4
|
import axios, { Axios, AxiosAdapter } from "axios";
|
|
4
|
-
import { toChecksumAddress } from "web3-utils";
|
|
5
5
|
|
|
6
6
|
export interface SafeInfo {
|
|
7
7
|
address: string;
|
|
@@ -9,7 +9,7 @@ export interface SafeInfo {
|
|
|
9
9
|
guard: string;
|
|
10
10
|
masterCopy: string;
|
|
11
11
|
modules: string[];
|
|
12
|
-
nonce:
|
|
12
|
+
nonce: string;
|
|
13
13
|
owners: string[];
|
|
14
14
|
threshold: number;
|
|
15
15
|
version: string;
|
|
@@ -51,80 +51,79 @@ export const HOST_MAP = {
|
|
|
51
51
|
/**
|
|
52
52
|
* eth
|
|
53
53
|
*/
|
|
54
|
-
"1": "https://safe-
|
|
54
|
+
"1": "https://safe-txs-mainnet.rabby.io/api",
|
|
55
55
|
/**
|
|
56
56
|
* polygon
|
|
57
57
|
*/
|
|
58
|
-
"137": "https://safe-transaction-polygon.safe.global/api
|
|
58
|
+
"137": "https://safe-transaction-polygon.safe.global/api",
|
|
59
59
|
/**
|
|
60
60
|
* bsc
|
|
61
61
|
*/
|
|
62
|
-
"56": "https://safe-transaction-bsc.safe.global/api
|
|
62
|
+
"56": "https://safe-transaction-bsc.safe.global/api",
|
|
63
63
|
/**
|
|
64
64
|
* Gnosis Chain
|
|
65
65
|
*/
|
|
66
|
-
"100": "https://safe-transaction-gnosis-chain.safe.global/api
|
|
66
|
+
"100": "https://safe-transaction-gnosis-chain.safe.global/api",
|
|
67
67
|
/**
|
|
68
68
|
* avalanche
|
|
69
69
|
*/
|
|
70
|
-
"43114": "https://safe-transaction-avalanche.safe.global/api
|
|
70
|
+
"43114": "https://safe-transaction-avalanche.safe.global/api",
|
|
71
71
|
/**
|
|
72
72
|
* arbitrum
|
|
73
73
|
*/
|
|
74
|
-
"42161": "https://safe-transaction-arbitrum.safe.global/api
|
|
74
|
+
"42161": "https://safe-transaction-arbitrum.safe.global/api",
|
|
75
75
|
/**
|
|
76
76
|
* Optimism
|
|
77
77
|
*/
|
|
78
|
-
"10": "https://safe-transaction-optimism.safe.global/api
|
|
78
|
+
"10": "https://safe-transaction-optimism.safe.global/api",
|
|
79
79
|
/**
|
|
80
80
|
* Aurora
|
|
81
81
|
*/
|
|
82
|
-
"1313161554": "https://safe-transaction-aurora.safe.global/api
|
|
82
|
+
"1313161554": "https://safe-transaction-aurora.safe.global/api",
|
|
83
83
|
/**
|
|
84
84
|
* Base
|
|
85
85
|
*/
|
|
86
|
-
"8453": "https://safe-transaction-base.safe.global/api
|
|
86
|
+
"8453": "https://safe-transaction-base.safe.global/api",
|
|
87
87
|
/**
|
|
88
88
|
* Celo
|
|
89
89
|
*/
|
|
90
|
-
"42220": "https://safe-transaction-celo.safe.global/api
|
|
90
|
+
"42220": "https://safe-transaction-celo.safe.global/api",
|
|
91
91
|
/**
|
|
92
92
|
* Polygon zkEVM
|
|
93
93
|
*/
|
|
94
|
-
"1101": "https://safe-transaction-zkevm.safe.global/api
|
|
94
|
+
"1101": "https://safe-transaction-zkevm.safe.global/api",
|
|
95
95
|
/**
|
|
96
96
|
* zksync era
|
|
97
97
|
*/
|
|
98
|
-
"324": "https://safe-transaction-zksync.safe.global/api
|
|
98
|
+
"324": "https://safe-transaction-zksync.safe.global/api",
|
|
99
99
|
/**
|
|
100
100
|
* scroll
|
|
101
101
|
*/
|
|
102
|
-
"534352": "https://safe-transaction-scroll.safe.global/api
|
|
102
|
+
"534352": "https://safe-transaction-scroll.safe.global/api",
|
|
103
103
|
/**
|
|
104
104
|
* linea
|
|
105
105
|
*/
|
|
106
|
-
"59144": "https://safe-transaction-linea.safe.global/api
|
|
106
|
+
"59144": "https://safe-transaction-linea.safe.global/api",
|
|
107
107
|
/**
|
|
108
108
|
* X Layer
|
|
109
109
|
*/
|
|
110
|
-
"196": "https://safe-transaction-xlayer.safe.global/api
|
|
111
|
-
|
|
110
|
+
"196": "https://safe-transaction-xlayer.safe.global/api",
|
|
112
111
|
/**
|
|
113
112
|
* mantle
|
|
114
113
|
*/
|
|
115
|
-
"5000": "https://safe-transaction-mantle.safe.global/api
|
|
114
|
+
"5000": "https://safe-transaction-mantle.safe.global/api",
|
|
116
115
|
/**
|
|
117
116
|
* World Chain
|
|
118
117
|
*/
|
|
119
|
-
"480": "https://safe-transaction-worldchain.safe.global/api
|
|
118
|
+
"480": "https://safe-transaction-worldchain.safe.global/api",
|
|
120
119
|
/**
|
|
121
120
|
* blast
|
|
122
121
|
*/
|
|
123
|
-
"81457": "https://safe-transaction-blast.safe.global/api
|
|
122
|
+
"81457": "https://safe-transaction-blast.safe.global/api",
|
|
124
123
|
/**
|
|
125
124
|
* Sonic
|
|
126
125
|
*/
|
|
127
|
-
"146": "https://safe-transaction-sonic.safe.global/api
|
|
126
|
+
"146": "https://safe-transaction-sonic.safe.global/api",
|
|
128
127
|
};
|
|
129
128
|
|
|
130
129
|
export default class RequestProvider {
|
|
@@ -153,7 +152,7 @@ export default class RequestProvider {
|
|
|
153
152
|
nonce: number
|
|
154
153
|
): Promise<{ results: SafeTransactionItem[] }> {
|
|
155
154
|
return this.request.get(
|
|
156
|
-
`/safes/${
|
|
155
|
+
`/v1/safes/${ethers.utils.getAddress(safeAddress)}/multisig-transactions/`,
|
|
157
156
|
{
|
|
158
157
|
params: {
|
|
159
158
|
executed: false,
|
|
@@ -165,18 +164,18 @@ export default class RequestProvider {
|
|
|
165
164
|
|
|
166
165
|
postTransactions(safeAddres: string, data): Promise<void> {
|
|
167
166
|
return this.request.post(
|
|
168
|
-
`/safes/${
|
|
167
|
+
`/v1/safes/${ethers.utils.getAddress(safeAddres)}/multisig-transactions/`,
|
|
169
168
|
data
|
|
170
169
|
);
|
|
171
170
|
}
|
|
172
171
|
|
|
173
172
|
getSafeInfo(safeAddress: string): Promise<SafeInfo> {
|
|
174
|
-
return this.request.get(`/safes/${
|
|
173
|
+
return this.request.get(`/v1/safes/${ethers.utils.getAddress(safeAddress)}/`);
|
|
175
174
|
}
|
|
176
175
|
|
|
177
|
-
confirmTransaction(
|
|
176
|
+
confirmTransaction(safeTransactionHash: string, data): Promise<void> {
|
|
178
177
|
return this.request.post(
|
|
179
|
-
`/multisig-transactions/${
|
|
178
|
+
`/v1/multisig-transactions/${safeTransactionHash}/confirmations/`,
|
|
180
179
|
data
|
|
181
180
|
);
|
|
182
181
|
}
|
|
@@ -186,25 +185,25 @@ export default class RequestProvider {
|
|
|
186
185
|
safeAddress: string,
|
|
187
186
|
safeVersion: string,
|
|
188
187
|
safeTxData: SafeTransactionDataPartial
|
|
189
|
-
): Promise<
|
|
188
|
+
): Promise<string | undefined> {
|
|
190
189
|
const isSafeTxGasRequired = isLegacyVersion(safeVersion);
|
|
191
190
|
|
|
192
191
|
// For 1.3.0+ Safes safeTxGas is not required
|
|
193
|
-
if (!isSafeTxGasRequired) return 0;
|
|
192
|
+
if (!isSafeTxGasRequired) return "0";
|
|
194
193
|
|
|
195
|
-
const address =
|
|
194
|
+
const address = ethers.utils.getAddress(safeAddress);
|
|
196
195
|
|
|
197
196
|
try {
|
|
198
197
|
const estimation: { safeTxGas: string } = await this.request.post(
|
|
199
|
-
`/safes/${address}/multisig-transactions/estimations/`,
|
|
198
|
+
`/v1/safes/${address}/multisig-transactions/estimations/`,
|
|
200
199
|
{
|
|
201
|
-
to:
|
|
202
|
-
value:
|
|
200
|
+
to: ethers.utils.getAddress(safeTxData.to),
|
|
201
|
+
value: safeTxData.value || "0",
|
|
203
202
|
data: safeTxData.data,
|
|
204
203
|
operation: safeTxData.operation,
|
|
205
204
|
}
|
|
206
205
|
);
|
|
207
|
-
return
|
|
206
|
+
return estimation.safeTxGas;
|
|
208
207
|
} catch (e) {
|
|
209
208
|
console.error(e);
|
|
210
209
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,29 +1,21 @@
|
|
|
1
1
|
import { BigNumber } from "@ethersproject/bignumber";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
SafeTransactionDataPartial,
|
|
5
|
-
} from "@gnosis.pm/safe-core-sdk-types";
|
|
6
|
-
import SafeTransaction from "@gnosis.pm/safe-core-sdk/dist/src/utils/transactions/SafeTransaction";
|
|
2
|
+
import { AxiosAdapter } from "axios";
|
|
3
|
+
import { Contract, ethers, providers } from "ethers";
|
|
7
4
|
import {
|
|
8
5
|
TransactionOptions,
|
|
9
6
|
TransactionResult,
|
|
10
|
-
|
|
7
|
+
SafeSignature,
|
|
8
|
+
SafeTransaction,
|
|
9
|
+
SafeTransactionDataPartial,
|
|
10
|
+
} from "@safe-global/types-kit";
|
|
11
|
+
import { EthSafeMessage, EthSafeTransaction } from "@safe-global/protocol-kit";
|
|
12
|
+
import { calculateSafeMessageHash } from "@safe-global/protocol-kit/dist/src/utils";
|
|
11
13
|
import SafeApiKit, {
|
|
12
14
|
EIP712TypedData as ApiKitEIP712TypedData,
|
|
13
15
|
SafeMessage as ApiKitSafeMessage,
|
|
14
16
|
} from "@safe-global/api-kit";
|
|
15
17
|
import { TRANSACTION_SERVICE_URLS } from "@safe-global/api-kit/dist/src/utils/config";
|
|
16
|
-
import { hashSafeMessage } from "@safe-global/protocol-kit";
|
|
17
|
-
import { calculateSafeMessageHash } from "@safe-global/protocol-kit/dist/src/utils";
|
|
18
|
-
import SafeMessage from "@safe-global/protocol-kit/dist/src/utils/messages/SafeMessage";
|
|
19
18
|
import { getSafeSingletonDeployment } from "@safe-global/safe-deployments";
|
|
20
|
-
import { SafeClientResult } from "@safe-global/sdk-starter-kit";
|
|
21
|
-
import { SafeClientTxStatus } from "@safe-global/sdk-starter-kit/dist/src/constants";
|
|
22
|
-
import { createSafeClientResult } from "@safe-global/sdk-starter-kit/dist/src/utils";
|
|
23
|
-
import { AxiosAdapter } from "axios";
|
|
24
|
-
import BN from "bignumber.js";
|
|
25
|
-
import { Contract, providers } from "ethers";
|
|
26
|
-
import { toChecksumAddress } from "web3-utils";
|
|
27
19
|
import RequestProvider, { HOST_MAP, SafeInfo } from "./api";
|
|
28
20
|
import {
|
|
29
21
|
estimateGasForTransactionExecution,
|
|
@@ -78,7 +70,7 @@ class Safe {
|
|
|
78
70
|
*/
|
|
79
71
|
static getSafeInfo(safeAddress: string, network: string) {
|
|
80
72
|
const request = new RequestProvider(network, Safe.adapter);
|
|
81
|
-
return request.getSafeInfo(
|
|
73
|
+
return request.getSafeInfo(ethers.utils.getAddress(safeAddress));
|
|
82
74
|
}
|
|
83
75
|
|
|
84
76
|
static async getPendingTransactions(
|
|
@@ -99,9 +91,7 @@ class Safe {
|
|
|
99
91
|
return new SafeApiKit({
|
|
100
92
|
chainId: BigInt(network),
|
|
101
93
|
txServiceUrl:
|
|
102
|
-
TRANSACTION_SERVICE_URLS[network] ||
|
|
103
|
-
HOST_MAP[network]?.replace(/\/v1$/, "") ||
|
|
104
|
-
undefined,
|
|
94
|
+
HOST_MAP[network] || TRANSACTION_SERVICE_URLS[network] || undefined,
|
|
105
95
|
});
|
|
106
96
|
};
|
|
107
97
|
|
|
@@ -119,7 +109,7 @@ class Safe {
|
|
|
119
109
|
address,
|
|
120
110
|
provider,
|
|
121
111
|
}: {
|
|
122
|
-
address;
|
|
112
|
+
address: string;
|
|
123
113
|
provider: providers.Web3Provider;
|
|
124
114
|
}): Promise<string> {
|
|
125
115
|
const contract = new Contract(
|
|
@@ -201,7 +191,7 @@ class Safe {
|
|
|
201
191
|
this.network,
|
|
202
192
|
this.version
|
|
203
193
|
);
|
|
204
|
-
return new
|
|
194
|
+
return new EthSafeTransaction(transaction);
|
|
205
195
|
}
|
|
206
196
|
|
|
207
197
|
async getTransactionHash(transaction: SafeTransaction) {
|
|
@@ -254,11 +244,11 @@ class Safe {
|
|
|
254
244
|
async postTransaction(transaction: SafeTransaction, hash: string) {
|
|
255
245
|
const signer = this.provider.getSigner(0);
|
|
256
246
|
const signerAddress = await signer.getAddress();
|
|
257
|
-
const safeAddress =
|
|
247
|
+
const safeAddress = ethers.utils.getAddress(this.safeAddress);
|
|
258
248
|
await this.request.postTransactions(this.safeAddress, {
|
|
259
249
|
safe: safeAddress,
|
|
260
|
-
to:
|
|
261
|
-
value:
|
|
250
|
+
to: ethers.utils.getAddress(transaction.data.to),
|
|
251
|
+
value: transaction.data.value,
|
|
262
252
|
data: transaction.data.data,
|
|
263
253
|
operation: transaction.data.operation,
|
|
264
254
|
gasToken: transaction.data.gasToken,
|
|
@@ -268,7 +258,7 @@ class Safe {
|
|
|
268
258
|
refundReceiver: transaction.data.refundReceiver,
|
|
269
259
|
nonce: transaction.data.nonce,
|
|
270
260
|
contractTransactionHash: hash,
|
|
271
|
-
sender:
|
|
261
|
+
sender: ethers.utils.getAddress(signerAddress),
|
|
272
262
|
signature: transaction.encodedSignatures(),
|
|
273
263
|
});
|
|
274
264
|
}
|
|
@@ -373,7 +363,7 @@ class Safe {
|
|
|
373
363
|
const chainId = BigInt(this.network);
|
|
374
364
|
|
|
375
365
|
return calculateSafeMessageHash(
|
|
376
|
-
|
|
366
|
+
ethers.utils.getAddress(safeAddress),
|
|
377
367
|
messageHash,
|
|
378
368
|
safeVersion,
|
|
379
369
|
chainId
|
|
@@ -385,18 +375,18 @@ class Safe {
|
|
|
385
375
|
* - If the threshold > 1, remember to confirmMessage() after sendMessage()
|
|
386
376
|
* - If the threshold = 1, then the message is confirmed and valid immediately
|
|
387
377
|
*
|
|
388
|
-
* @param {
|
|
378
|
+
* @param {EthSafeMessage} safeMessage The message
|
|
389
379
|
* @returns {Promise<SafeClientResult>} The SafeClientResult
|
|
390
380
|
*/
|
|
391
|
-
async addMessage({
|
|
381
|
+
async addMessage({
|
|
382
|
+
safeMessage,
|
|
383
|
+
}: {
|
|
384
|
+
safeMessage: EthSafeMessage;
|
|
385
|
+
}): Promise<void> {
|
|
392
386
|
const safeAddress = this.safeAddress;
|
|
393
|
-
const threshold = await this.getThreshold();
|
|
394
|
-
const messageHash = await this.getSafeMessageHash(
|
|
395
|
-
hashSafeMessage(safeMessage.data)
|
|
396
|
-
);
|
|
397
387
|
|
|
398
388
|
try {
|
|
399
|
-
|
|
389
|
+
return this.apiKit.addMessage(safeAddress, {
|
|
400
390
|
message: safeMessage.data as string | ApiKitEIP712TypedData,
|
|
401
391
|
signature: safeMessage.encodedSignatures(),
|
|
402
392
|
});
|
|
@@ -405,17 +395,6 @@ class Safe {
|
|
|
405
395
|
"Could not add a new off-chain message to the Safe account"
|
|
406
396
|
);
|
|
407
397
|
}
|
|
408
|
-
|
|
409
|
-
const message = await this.apiKit.getMessage(messageHash);
|
|
410
|
-
|
|
411
|
-
return createSafeClientResult({
|
|
412
|
-
safeAddress: this.safeAddress,
|
|
413
|
-
status:
|
|
414
|
-
message.confirmations.length === threshold
|
|
415
|
-
? SafeClientTxStatus.MESSAGE_CONFIRMED
|
|
416
|
-
: SafeClientTxStatus.MESSAGE_PENDING_SIGNATURES,
|
|
417
|
-
messageHash,
|
|
418
|
-
});
|
|
419
398
|
}
|
|
420
399
|
}
|
|
421
400
|
|
package/src/type.ts
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import { BigNumber } from "@ethersproject/bignumber";
|
|
2
|
-
import {
|
|
3
|
-
SafeTransaction,
|
|
4
|
-
SafeTransactionData,
|
|
5
|
-
} from "@gnosis.pm/safe-core-sdk-types";
|
|
6
2
|
import {
|
|
7
3
|
TransactionOptions,
|
|
8
4
|
TransactionResult,
|
|
9
|
-
|
|
5
|
+
SafeTransaction,
|
|
6
|
+
SafeTransactionData
|
|
7
|
+
} from "@safe-global/types-kit"
|
|
10
8
|
|
|
11
9
|
export interface GnosisSafeContract {
|
|
12
10
|
getVersion(): Promise<string>;
|
package/src/utils.ts
CHANGED
|
@@ -2,14 +2,14 @@ import { BigNumber } from "@ethersproject/bignumber";
|
|
|
2
2
|
import { Contract, providers } from "ethers";
|
|
3
3
|
import {
|
|
4
4
|
OperationType,
|
|
5
|
-
SafeTransactionData,
|
|
6
|
-
SafeTransactionDataPartial,
|
|
7
5
|
SafeSignature,
|
|
8
6
|
SafeTransaction,
|
|
9
|
-
|
|
7
|
+
SafeTransactionData,
|
|
8
|
+
SafeTransactionDataPartial
|
|
9
|
+
} from "@safe-global/types-kit"
|
|
10
|
+
import { EthSafeSignature } from "@safe-global/protocol-kit"
|
|
10
11
|
import { bufferToHex, ecrecover, pubToAddress } from "ethereumjs-util";
|
|
11
12
|
import { ZERO_ADDRESS, SENTINEL_ADDRESS } from "./constants";
|
|
12
|
-
import EthSignSignature from "@gnosis.pm/safe-core-sdk/dist/src/utils/signatures/SafeSignature";
|
|
13
13
|
import semverSatisfies from "semver/functions/satisfies";
|
|
14
14
|
import RequestProvider from "./api";
|
|
15
15
|
import Safe from "./index";
|
|
@@ -126,8 +126,8 @@ export async function standardizeSafeTransactionData(
|
|
|
126
126
|
value: tx.value,
|
|
127
127
|
data: tx.data,
|
|
128
128
|
operation: tx.operation ?? OperationType.Call,
|
|
129
|
-
baseGas: tx.baseGas ?? 0,
|
|
130
|
-
gasPrice: tx.gasPrice ?? 0,
|
|
129
|
+
baseGas: tx.baseGas ?? "0",
|
|
130
|
+
gasPrice: tx.gasPrice ?? "0",
|
|
131
131
|
gasToken: tx.gasToken || ZERO_ADDRESS,
|
|
132
132
|
refundReceiver: tx.refundReceiver || ZERO_ADDRESS,
|
|
133
133
|
nonce: tx.nonce ?? (await safeContract.nonce()).toNumber(),
|
|
@@ -138,7 +138,7 @@ export async function standardizeSafeTransactionData(
|
|
|
138
138
|
(await request.getSafeTxGas(safeAddress, version, standardizedTxs));
|
|
139
139
|
return {
|
|
140
140
|
...standardizedTxs,
|
|
141
|
-
safeTxGas: safeTxGas || 0,
|
|
141
|
+
safeTxGas: safeTxGas || "0",
|
|
142
142
|
};
|
|
143
143
|
}
|
|
144
144
|
|
|
@@ -151,7 +151,7 @@ export function generatePreValidatedSignature(
|
|
|
151
151
|
"0000000000000000000000000000000000000000000000000000000000000000" +
|
|
152
152
|
"01";
|
|
153
153
|
|
|
154
|
-
return new
|
|
154
|
+
return new EthSafeSignature(ownerAddress, signature);
|
|
155
155
|
}
|
|
156
156
|
|
|
157
157
|
export function isTxHashSignedWithPrefix(
|
|
@@ -200,13 +200,13 @@ export function adjustVInSignature(signature: string, hasPrefix: boolean) {
|
|
|
200
200
|
export async function generateSignature(
|
|
201
201
|
provider: providers.Web3Provider,
|
|
202
202
|
hash: string
|
|
203
|
-
): Promise<
|
|
203
|
+
): Promise<EthSafeSignature> {
|
|
204
204
|
const signer = await provider.getSigner(0);
|
|
205
205
|
const signerAddress = await signer.getAddress();
|
|
206
206
|
let signature = await provider.send("personal_sign", [hash, signerAddress]);
|
|
207
207
|
const hasPrefix = isTxHashSignedWithPrefix(hash, signature, signerAddress);
|
|
208
208
|
signature = adjustVInSignature(signature, hasPrefix);
|
|
209
|
-
return new
|
|
209
|
+
return new EthSafeSignature(signerAddress, signature);
|
|
210
210
|
}
|
|
211
211
|
|
|
212
212
|
export async function estimateGasForTransactionExecution(
|