@rabby-wallet/gnosis-sdk 1.3.10-alpha.0 → 1.4.0-alpha
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 +82 -4
- package/dist/api.js +32 -32
- package/dist/index.d.ts +10 -11
- package/dist/index.js +25 -33
- 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 +35 -36
- package/src/index.ts +35 -46
- 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;
|
|
@@ -41,6 +41,84 @@ export interface SafeTransactionItem {
|
|
|
41
41
|
confirmations: ConfirmationItem[];
|
|
42
42
|
signatures: string | null;
|
|
43
43
|
}
|
|
44
|
+
export declare const HOST_MAP: {
|
|
45
|
+
/**
|
|
46
|
+
* eth
|
|
47
|
+
*/
|
|
48
|
+
"1": string;
|
|
49
|
+
/**
|
|
50
|
+
* polygon
|
|
51
|
+
*/
|
|
52
|
+
"137": string;
|
|
53
|
+
/**
|
|
54
|
+
* bsc
|
|
55
|
+
*/
|
|
56
|
+
"56": string;
|
|
57
|
+
/**
|
|
58
|
+
* Gnosis Chain
|
|
59
|
+
*/
|
|
60
|
+
"100": string;
|
|
61
|
+
/**
|
|
62
|
+
* avalanche
|
|
63
|
+
*/
|
|
64
|
+
"43114": string;
|
|
65
|
+
/**
|
|
66
|
+
* arbitrum
|
|
67
|
+
*/
|
|
68
|
+
"42161": string;
|
|
69
|
+
/**
|
|
70
|
+
* Optimism
|
|
71
|
+
*/
|
|
72
|
+
"10": string;
|
|
73
|
+
/**
|
|
74
|
+
* Aurora
|
|
75
|
+
*/
|
|
76
|
+
"1313161554": string;
|
|
77
|
+
/**
|
|
78
|
+
* Base
|
|
79
|
+
*/
|
|
80
|
+
"8453": string;
|
|
81
|
+
/**
|
|
82
|
+
* Celo
|
|
83
|
+
*/
|
|
84
|
+
"42220": string;
|
|
85
|
+
/**
|
|
86
|
+
* Polygon zkEVM
|
|
87
|
+
*/
|
|
88
|
+
"1101": string;
|
|
89
|
+
/**
|
|
90
|
+
* zksync era
|
|
91
|
+
*/
|
|
92
|
+
"324": string;
|
|
93
|
+
/**
|
|
94
|
+
* scroll
|
|
95
|
+
*/
|
|
96
|
+
"534352": string;
|
|
97
|
+
/**
|
|
98
|
+
* linea
|
|
99
|
+
*/
|
|
100
|
+
"59144": string;
|
|
101
|
+
/**
|
|
102
|
+
* X Layer
|
|
103
|
+
*/
|
|
104
|
+
"196": string;
|
|
105
|
+
/**
|
|
106
|
+
* mantle
|
|
107
|
+
*/
|
|
108
|
+
"5000": string;
|
|
109
|
+
/**
|
|
110
|
+
* World Chain
|
|
111
|
+
*/
|
|
112
|
+
"480": string;
|
|
113
|
+
/**
|
|
114
|
+
* blast
|
|
115
|
+
*/
|
|
116
|
+
"81457": string;
|
|
117
|
+
/**
|
|
118
|
+
* Sonic
|
|
119
|
+
*/
|
|
120
|
+
"146": string;
|
|
121
|
+
};
|
|
44
122
|
export default class RequestProvider {
|
|
45
123
|
host: string;
|
|
46
124
|
request: Axios;
|
|
@@ -50,7 +128,7 @@ export default class RequestProvider {
|
|
|
50
128
|
}>;
|
|
51
129
|
postTransactions(safeAddres: string, data: any): Promise<void>;
|
|
52
130
|
getSafeInfo(safeAddress: string): Promise<SafeInfo>;
|
|
53
|
-
confirmTransaction(
|
|
54
|
-
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>;
|
|
55
133
|
}
|
|
56
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
|
-
|
|
4
|
-
const HOST_MAP = {
|
|
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",
|
|
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",
|
|
72
|
+
"480": "https://safe-transaction-worldchain.safe.global/api",
|
|
73
73
|
/**
|
|
74
74
|
* blast
|
|
75
75
|
*/
|
|
76
|
-
"81457": "https://safe-transaction-blast.safe.global",
|
|
76
|
+
"81457": "https://safe-transaction-blast.safe.global/api",
|
|
77
77
|
/**
|
|
78
78
|
* Sonic
|
|
79
79
|
*/
|
|
80
|
-
"146": "https://safe-transaction-sonic.safe.global",
|
|
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 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;
|
|
@@ -30,11 +27,12 @@ declare class Safe {
|
|
|
30
27
|
static getPendingTransactions(safeAddress: string, network: string, nonce: number): Promise<{
|
|
31
28
|
results: import("./api").SafeTransactionItem[];
|
|
32
29
|
}>;
|
|
30
|
+
static createSafeApiKit: (network: string) => SafeApiKit;
|
|
33
31
|
getPendingTransactions(): Promise<{
|
|
34
32
|
results: import("./api").SafeTransactionItem[];
|
|
35
33
|
}>;
|
|
36
34
|
static getSafeVersion({ address, provider, }: {
|
|
37
|
-
address:
|
|
35
|
+
address: string;
|
|
38
36
|
provider: providers.Web3Provider;
|
|
39
37
|
}): Promise<string>;
|
|
40
38
|
init(): Promise<void>;
|
|
@@ -48,7 +46,7 @@ declare class Safe {
|
|
|
48
46
|
nonce: number;
|
|
49
47
|
owners: string[];
|
|
50
48
|
}>;
|
|
51
|
-
buildTransaction(data: SafeTransactionDataPartial): Promise<
|
|
49
|
+
buildTransaction(data: SafeTransactionDataPartial): Promise<EthSafeTransaction>;
|
|
52
50
|
getTransactionHash(transaction: SafeTransaction): Promise<any>;
|
|
53
51
|
signTransactionHash(hash: string): Promise<SafeSignature>;
|
|
54
52
|
signTransaction(transaction: SafeTransaction): Promise<void>;
|
|
@@ -70,12 +68,13 @@ declare class Safe {
|
|
|
70
68
|
* - If the threshold > 1, remember to confirmMessage() after sendMessage()
|
|
71
69
|
* - If the threshold = 1, then the message is confirmed and valid immediately
|
|
72
70
|
*
|
|
73
|
-
* @param {
|
|
71
|
+
* @param {EthSafeMessage} safeMessage The message
|
|
74
72
|
* @returns {Promise<SafeClientResult>} The SafeClientResult
|
|
75
73
|
*/
|
|
76
74
|
addMessage({ safeMessage }: {
|
|
77
|
-
safeMessage:
|
|
78
|
-
}): Promise<
|
|
75
|
+
safeMessage: EthSafeMessage;
|
|
76
|
+
}): Promise<void>;
|
|
79
77
|
}
|
|
80
78
|
export default Safe;
|
|
81
79
|
export type BasicSafeInfo = Awaited<ReturnType<Safe["getBasicSafeInfo"]>>;
|
|
80
|
+
export { ApiKitSafeMessage as SafeMessage };
|
package/dist/index.js
CHANGED
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
import { BigNumber } from "@ethersproject/bignumber";
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import { hashSafeMessage } from "@safe-global/protocol-kit";
|
|
2
|
+
import { Contract, ethers } from "ethers";
|
|
3
|
+
import { EthSafeTransaction } from "@safe-global/protocol-kit";
|
|
5
4
|
import { calculateSafeMessageHash } from "@safe-global/protocol-kit/dist/src/utils";
|
|
5
|
+
import SafeApiKit from "@safe-global/api-kit";
|
|
6
|
+
import { TRANSACTION_SERVICE_URLS } from "@safe-global/api-kit/dist/src/utils/config";
|
|
6
7
|
import { getSafeSingletonDeployment } from "@safe-global/safe-deployments";
|
|
7
|
-
import {
|
|
8
|
-
import { createSafeClientResult } from "@safe-global/sdk-starter-kit/dist/src/utils";
|
|
9
|
-
import BN from "bignumber.js";
|
|
10
|
-
import { Contract } from "ethers";
|
|
11
|
-
import { toChecksumAddress } from "web3-utils";
|
|
12
|
-
import RequestProvider from "./api";
|
|
8
|
+
import RequestProvider, { HOST_MAP } from "./api";
|
|
13
9
|
import { estimateGasForTransactionExecution, generatePreValidatedSignature, generateSignature, sameString, standardizeSafeTransactionData, } from "./utils";
|
|
14
10
|
class Safe {
|
|
15
11
|
constructor(safeAddress, version, provider, network = "1") {
|
|
@@ -43,7 +39,7 @@ class Safe {
|
|
|
43
39
|
const safeAddress = this.safeAddress;
|
|
44
40
|
const safeVersion = this.version;
|
|
45
41
|
const chainId = BigInt(this.network);
|
|
46
|
-
return calculateSafeMessageHash(
|
|
42
|
+
return calculateSafeMessageHash(ethers.utils.getAddress(safeAddress), messageHash, safeVersion, chainId);
|
|
47
43
|
};
|
|
48
44
|
const contract = getSafeSingletonDeployment({
|
|
49
45
|
version,
|
|
@@ -58,9 +54,7 @@ class Safe {
|
|
|
58
54
|
this.safeAddress = safeAddress;
|
|
59
55
|
this.network = network;
|
|
60
56
|
this.request = new RequestProvider(network, Safe.adapter);
|
|
61
|
-
this.apiKit =
|
|
62
|
-
chainId: BigInt(network),
|
|
63
|
-
});
|
|
57
|
+
this.apiKit = Safe.createSafeApiKit(network);
|
|
64
58
|
// this.init();
|
|
65
59
|
}
|
|
66
60
|
/**
|
|
@@ -71,7 +65,7 @@ class Safe {
|
|
|
71
65
|
*/
|
|
72
66
|
static getSafeInfo(safeAddress, network) {
|
|
73
67
|
const request = new RequestProvider(network, Safe.adapter);
|
|
74
|
-
return request.getSafeInfo(
|
|
68
|
+
return request.getSafeInfo(ethers.utils.getAddress(safeAddress));
|
|
75
69
|
}
|
|
76
70
|
static async getPendingTransactions(safeAddress, network, nonce) {
|
|
77
71
|
const request = new RequestProvider(network, Safe.adapter);
|
|
@@ -127,7 +121,7 @@ class Safe {
|
|
|
127
121
|
}
|
|
128
122
|
async buildTransaction(data) {
|
|
129
123
|
const transaction = await standardizeSafeTransactionData(this.safeAddress, this.contract, this.provider, data, this.network, this.version);
|
|
130
|
-
return new
|
|
124
|
+
return new EthSafeTransaction(transaction);
|
|
131
125
|
}
|
|
132
126
|
async getTransactionHash(transaction) {
|
|
133
127
|
const transactionData = transaction.data;
|
|
@@ -162,11 +156,11 @@ class Safe {
|
|
|
162
156
|
async postTransaction(transaction, hash) {
|
|
163
157
|
const signer = this.provider.getSigner(0);
|
|
164
158
|
const signerAddress = await signer.getAddress();
|
|
165
|
-
const safeAddress =
|
|
159
|
+
const safeAddress = ethers.utils.getAddress(this.safeAddress);
|
|
166
160
|
await this.request.postTransactions(this.safeAddress, {
|
|
167
161
|
safe: safeAddress,
|
|
168
|
-
to:
|
|
169
|
-
value:
|
|
162
|
+
to: ethers.utils.getAddress(transaction.data.to),
|
|
163
|
+
value: transaction.data.value,
|
|
170
164
|
data: transaction.data.data,
|
|
171
165
|
operation: transaction.data.operation,
|
|
172
166
|
gasToken: transaction.data.gasToken,
|
|
@@ -176,7 +170,7 @@ class Safe {
|
|
|
176
170
|
refundReceiver: transaction.data.refundReceiver,
|
|
177
171
|
nonce: transaction.data.nonce,
|
|
178
172
|
contractTransactionHash: hash,
|
|
179
|
-
sender:
|
|
173
|
+
sender: ethers.utils.getAddress(signerAddress),
|
|
180
174
|
signature: transaction.encodedSignatures(),
|
|
181
175
|
});
|
|
182
176
|
}
|
|
@@ -186,7 +180,7 @@ class Safe {
|
|
|
186
180
|
safeTransaction.addSignature(signature);
|
|
187
181
|
const signer = await this.provider.getSigner(0);
|
|
188
182
|
const signerAddress = await signer.getAddress();
|
|
189
|
-
const sig = safeTransaction.signatures.get(signerAddress
|
|
183
|
+
const sig = safeTransaction.signatures.get(signerAddress?.toLowerCase());
|
|
190
184
|
if (sig) {
|
|
191
185
|
await this.request.confirmTransaction(hash, { signature: sig.data });
|
|
192
186
|
}
|
|
@@ -222,7 +216,7 @@ class Safe {
|
|
|
222
216
|
const gasLimit = await estimateGasForTransactionExecution(contract, signerAddress, safeTransaction);
|
|
223
217
|
const executionOptions = {
|
|
224
218
|
gasLimit,
|
|
225
|
-
gasPrice: options
|
|
219
|
+
gasPrice: options?.gasPrice,
|
|
226
220
|
from: signerAddress,
|
|
227
221
|
};
|
|
228
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);
|
|
@@ -233,15 +227,13 @@ class Safe {
|
|
|
233
227
|
* - If the threshold > 1, remember to confirmMessage() after sendMessage()
|
|
234
228
|
* - If the threshold = 1, then the message is confirmed and valid immediately
|
|
235
229
|
*
|
|
236
|
-
* @param {
|
|
230
|
+
* @param {EthSafeMessage} safeMessage The message
|
|
237
231
|
* @returns {Promise<SafeClientResult>} The SafeClientResult
|
|
238
232
|
*/
|
|
239
233
|
async addMessage({ safeMessage }) {
|
|
240
234
|
const safeAddress = this.safeAddress;
|
|
241
|
-
const threshold = await this.getThreshold();
|
|
242
|
-
const messageHash = await this.getSafeMessageHash(hashSafeMessage(safeMessage.data));
|
|
243
235
|
try {
|
|
244
|
-
|
|
236
|
+
return this.apiKit.addMessage(safeAddress, {
|
|
245
237
|
message: safeMessage.data,
|
|
246
238
|
signature: safeMessage.encodedSignatures(),
|
|
247
239
|
});
|
|
@@ -249,14 +241,14 @@ class Safe {
|
|
|
249
241
|
catch (error) {
|
|
250
242
|
throw new Error("Could not add a new off-chain message to the Safe account");
|
|
251
243
|
}
|
|
252
|
-
const message = await this.apiKit.getMessage(messageHash);
|
|
253
|
-
return createSafeClientResult({
|
|
254
|
-
safeAddress: this.safeAddress,
|
|
255
|
-
status: message.confirmations.length === threshold
|
|
256
|
-
? SafeClientTxStatus.MESSAGE_CONFIRMED
|
|
257
|
-
: SafeClientTxStatus.MESSAGE_PENDING_SIGNATURES,
|
|
258
|
-
messageHash,
|
|
259
|
-
});
|
|
260
244
|
}
|
|
261
245
|
}
|
|
246
|
+
Safe.createSafeApiKit = (network) => {
|
|
247
|
+
return new SafeApiKit({
|
|
248
|
+
chainId: BigInt(network),
|
|
249
|
+
txServiceUrl: TRANSACTION_SERVICE_URLS[network] ||
|
|
250
|
+
HOST_MAP[network] ||
|
|
251
|
+
undefined,
|
|
252
|
+
});
|
|
253
|
+
};
|
|
262
254
|
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",
|
|
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.0.2",
|
|
23
|
-
"@safe-global/types-kit": "1.0.0",
|
|
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;
|
|
@@ -47,84 +47,83 @@ export interface SafeTransactionItem {
|
|
|
47
47
|
signatures: string | null;
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
const HOST_MAP = {
|
|
50
|
+
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",
|
|
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",
|
|
118
|
+
"480": "https://safe-transaction-worldchain.safe.global/api",
|
|
120
119
|
/**
|
|
121
120
|
* blast
|
|
122
121
|
*/
|
|
123
|
-
"81457": "https://safe-transaction-blast.safe.global",
|
|
122
|
+
"81457": "https://safe-transaction-blast.safe.global/api",
|
|
124
123
|
/**
|
|
125
124
|
* Sonic
|
|
126
125
|
*/
|
|
127
|
-
"146": "https://safe-transaction-sonic.safe.global",
|
|
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,28 +1,22 @@
|
|
|
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,
|
|
15
|
+
SafeMessage as ApiKitSafeMessage,
|
|
13
16
|
} from "@safe-global/api-kit";
|
|
14
|
-
import {
|
|
15
|
-
import { calculateSafeMessageHash } from "@safe-global/protocol-kit/dist/src/utils";
|
|
16
|
-
import SafeMessage from "@safe-global/protocol-kit/dist/src/utils/messages/SafeMessage";
|
|
17
|
+
import { TRANSACTION_SERVICE_URLS } from "@safe-global/api-kit/dist/src/utils/config";
|
|
17
18
|
import { getSafeSingletonDeployment } from "@safe-global/safe-deployments";
|
|
18
|
-
import {
|
|
19
|
-
import { SafeClientTxStatus } from "@safe-global/sdk-starter-kit/dist/src/constants";
|
|
20
|
-
import { createSafeClientResult } from "@safe-global/sdk-starter-kit/dist/src/utils";
|
|
21
|
-
import { AxiosAdapter } from "axios";
|
|
22
|
-
import BN from "bignumber.js";
|
|
23
|
-
import { Contract, providers } from "ethers";
|
|
24
|
-
import { toChecksumAddress } from "web3-utils";
|
|
25
|
-
import RequestProvider, { SafeInfo } from "./api";
|
|
19
|
+
import RequestProvider, { HOST_MAP, SafeInfo } from "./api";
|
|
26
20
|
import {
|
|
27
21
|
estimateGasForTransactionExecution,
|
|
28
22
|
generatePreValidatedSignature,
|
|
@@ -63,9 +57,7 @@ class Safe {
|
|
|
63
57
|
this.safeAddress = safeAddress;
|
|
64
58
|
this.network = network;
|
|
65
59
|
this.request = new RequestProvider(network, Safe.adapter);
|
|
66
|
-
this.apiKit =
|
|
67
|
-
chainId: BigInt(network),
|
|
68
|
-
});
|
|
60
|
+
this.apiKit = Safe.createSafeApiKit(network);
|
|
69
61
|
|
|
70
62
|
// this.init();
|
|
71
63
|
}
|
|
@@ -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(
|
|
@@ -95,6 +87,16 @@ class Safe {
|
|
|
95
87
|
return transactions;
|
|
96
88
|
}
|
|
97
89
|
|
|
90
|
+
static createSafeApiKit = (network: string) => {
|
|
91
|
+
return new SafeApiKit({
|
|
92
|
+
chainId: BigInt(network),
|
|
93
|
+
txServiceUrl:
|
|
94
|
+
TRANSACTION_SERVICE_URLS[network] ||
|
|
95
|
+
HOST_MAP[network] ||
|
|
96
|
+
undefined,
|
|
97
|
+
});
|
|
98
|
+
};
|
|
99
|
+
|
|
98
100
|
async getPendingTransactions() {
|
|
99
101
|
const nonce = await this.getNonce();
|
|
100
102
|
const transactions = await this.request.getPendingTransactions(
|
|
@@ -109,7 +111,7 @@ class Safe {
|
|
|
109
111
|
address,
|
|
110
112
|
provider,
|
|
111
113
|
}: {
|
|
112
|
-
address;
|
|
114
|
+
address: string;
|
|
113
115
|
provider: providers.Web3Provider;
|
|
114
116
|
}): Promise<string> {
|
|
115
117
|
const contract = new Contract(
|
|
@@ -191,7 +193,7 @@ class Safe {
|
|
|
191
193
|
this.network,
|
|
192
194
|
this.version
|
|
193
195
|
);
|
|
194
|
-
return new
|
|
196
|
+
return new EthSafeTransaction(transaction);
|
|
195
197
|
}
|
|
196
198
|
|
|
197
199
|
async getTransactionHash(transaction: SafeTransaction) {
|
|
@@ -244,11 +246,11 @@ class Safe {
|
|
|
244
246
|
async postTransaction(transaction: SafeTransaction, hash: string) {
|
|
245
247
|
const signer = this.provider.getSigner(0);
|
|
246
248
|
const signerAddress = await signer.getAddress();
|
|
247
|
-
const safeAddress =
|
|
249
|
+
const safeAddress = ethers.utils.getAddress(this.safeAddress);
|
|
248
250
|
await this.request.postTransactions(this.safeAddress, {
|
|
249
251
|
safe: safeAddress,
|
|
250
|
-
to:
|
|
251
|
-
value:
|
|
252
|
+
to: ethers.utils.getAddress(transaction.data.to),
|
|
253
|
+
value: transaction.data.value,
|
|
252
254
|
data: transaction.data.data,
|
|
253
255
|
operation: transaction.data.operation,
|
|
254
256
|
gasToken: transaction.data.gasToken,
|
|
@@ -258,7 +260,7 @@ class Safe {
|
|
|
258
260
|
refundReceiver: transaction.data.refundReceiver,
|
|
259
261
|
nonce: transaction.data.nonce,
|
|
260
262
|
contractTransactionHash: hash,
|
|
261
|
-
sender:
|
|
263
|
+
sender: ethers.utils.getAddress(signerAddress),
|
|
262
264
|
signature: transaction.encodedSignatures(),
|
|
263
265
|
});
|
|
264
266
|
}
|
|
@@ -363,7 +365,7 @@ class Safe {
|
|
|
363
365
|
const chainId = BigInt(this.network);
|
|
364
366
|
|
|
365
367
|
return calculateSafeMessageHash(
|
|
366
|
-
|
|
368
|
+
ethers.utils.getAddress(safeAddress),
|
|
367
369
|
messageHash,
|
|
368
370
|
safeVersion,
|
|
369
371
|
chainId
|
|
@@ -375,18 +377,14 @@ class Safe {
|
|
|
375
377
|
* - If the threshold > 1, remember to confirmMessage() after sendMessage()
|
|
376
378
|
* - If the threshold = 1, then the message is confirmed and valid immediately
|
|
377
379
|
*
|
|
378
|
-
* @param {
|
|
380
|
+
* @param {EthSafeMessage} safeMessage The message
|
|
379
381
|
* @returns {Promise<SafeClientResult>} The SafeClientResult
|
|
380
382
|
*/
|
|
381
|
-
async addMessage({ safeMessage }: { safeMessage:
|
|
383
|
+
async addMessage({ safeMessage }: { safeMessage: EthSafeMessage }): Promise<void> {
|
|
382
384
|
const safeAddress = this.safeAddress;
|
|
383
|
-
const threshold = await this.getThreshold();
|
|
384
|
-
const messageHash = await this.getSafeMessageHash(
|
|
385
|
-
hashSafeMessage(safeMessage.data)
|
|
386
|
-
);
|
|
387
385
|
|
|
388
386
|
try {
|
|
389
|
-
|
|
387
|
+
return this.apiKit.addMessage(safeAddress, {
|
|
390
388
|
message: safeMessage.data as string | ApiKitEIP712TypedData,
|
|
391
389
|
signature: safeMessage.encodedSignatures(),
|
|
392
390
|
});
|
|
@@ -395,20 +393,11 @@ class Safe {
|
|
|
395
393
|
"Could not add a new off-chain message to the Safe account"
|
|
396
394
|
);
|
|
397
395
|
}
|
|
398
|
-
|
|
399
|
-
const message = await this.apiKit.getMessage(messageHash);
|
|
400
|
-
|
|
401
|
-
return createSafeClientResult({
|
|
402
|
-
safeAddress: this.safeAddress,
|
|
403
|
-
status:
|
|
404
|
-
message.confirmations.length === threshold
|
|
405
|
-
? SafeClientTxStatus.MESSAGE_CONFIRMED
|
|
406
|
-
: SafeClientTxStatus.MESSAGE_PENDING_SIGNATURES,
|
|
407
|
-
messageHash,
|
|
408
|
-
});
|
|
409
396
|
}
|
|
410
397
|
}
|
|
411
398
|
|
|
412
399
|
export default Safe;
|
|
413
400
|
|
|
414
401
|
export type BasicSafeInfo = Awaited<ReturnType<Safe["getBasicSafeInfo"]>>;
|
|
402
|
+
|
|
403
|
+
export { ApiKitSafeMessage as SafeMessage };
|
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(
|