@skalenetwork/upgrade-tools 1.0.0-develop.0 → 1.0.0-develop.11
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/hardhat.config.js +1 -1
- package/dist/src/deploy.js +3 -1
- package/dist/src/gnosis-safe.d.ts +1 -1
- package/dist/src/gnosis-safe.js +8 -5
- package/dist/src/upgrade.d.ts +2 -1
- package/dist/src/upgrade.js +25 -2
- package/package.json +1 -1
package/dist/hardhat.config.js
CHANGED
package/dist/src/deploy.js
CHANGED
|
@@ -90,7 +90,9 @@ function getContractFactory(contract) {
|
|
|
90
90
|
Object.assign(libraryArtifacts, manifest.libraries);
|
|
91
91
|
}
|
|
92
92
|
finally {
|
|
93
|
-
|
|
93
|
+
if (manifest !== undefined) {
|
|
94
|
+
Object.assign(manifest, { libraries: libraryArtifacts });
|
|
95
|
+
}
|
|
94
96
|
yield fs_1.promises.writeFile(yield getManifestFile(), JSON.stringify(manifest, null, 4));
|
|
95
97
|
}
|
|
96
98
|
return yield getLinkedContractFactory(contract, libraries);
|
|
@@ -20,6 +20,6 @@ interface SafeMultisigTransaction {
|
|
|
20
20
|
}
|
|
21
21
|
export declare function getSafeTransactionUrl(chainId: number): string;
|
|
22
22
|
export declare function getSafeRelayUrl(chainId: number): string;
|
|
23
|
-
export declare function createMultiSendTransaction(ethers: Ethers, safeAddress: string, privateKey: string, transactions: string[],
|
|
23
|
+
export declare function createMultiSendTransaction(ethers: Ethers, safeAddress: string, privateKey: string, transactions: string[], nonce?: number): Promise<SafeMultisigTransaction>;
|
|
24
24
|
export declare function sendSafeTransaction(safe: string, chainId: number, safeTx: SafeMultisigTransaction): Promise<void>;
|
|
25
25
|
export {};
|
package/dist/src/gnosis-safe.js
CHANGED
|
@@ -111,7 +111,7 @@ function concatTransactions(transactions) {
|
|
|
111
111
|
}
|
|
112
112
|
}).join("");
|
|
113
113
|
}
|
|
114
|
-
function createMultiSendTransaction(ethers, safeAddress, privateKey, transactions,
|
|
114
|
+
function createMultiSendTransaction(ethers, safeAddress, privateKey, transactions, nonce) {
|
|
115
115
|
return __awaiter(this, void 0, void 0, function* () {
|
|
116
116
|
const chainId = (yield ethers.provider.getNetwork()).chainId;
|
|
117
117
|
const multiSendAddress = getMultiSendAddress(chainId);
|
|
@@ -119,11 +119,11 @@ function createMultiSendTransaction(ethers, safeAddress, privateKey, transaction
|
|
|
119
119
|
const multiSend = new ethers.Contract(multiSendAddress, new ethers.utils.Interface(multiSendAbi), ethers.provider);
|
|
120
120
|
const safeAbi = [{ "constant": true, "inputs": [{ "internalType": "address", "name": "to", "type": "address" }, { "internalType": "uint256", "name": "value", "type": "uint256" }, { "internalType": "bytes", "name": "data", "type": "bytes" }, { "internalType": "enum Enum.Operation", "name": "operation", "type": "uint8" }, { "internalType": "uint256", "name": "safeTxGas", "type": "uint256" }, { "internalType": "uint256", "name": "baseGas", "type": "uint256" }, { "internalType": "uint256", "name": "gasPrice", "type": "uint256" }, { "internalType": "address", "name": "gasToken", "type": "address" }, { "internalType": "address", "name": "refundReceiver", "type": "address" }, { "internalType": "uint256", "name": "_nonce", "type": "uint256" }], "name": "getTransactionHash", "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], "payable": false, "stateMutability": "view", "type": "function" }];
|
|
121
121
|
const safe = new ethers.Contract(safeAddress, new ethers.utils.Interface(safeAbi), ethers.provider);
|
|
122
|
-
let
|
|
123
|
-
if (
|
|
122
|
+
let nonceValue = 0;
|
|
123
|
+
if (nonce === undefined) {
|
|
124
124
|
try {
|
|
125
125
|
const nonceResponse = yield axios_1.default.get(`${getSafeTransactionUrl(chainId)}/api/v1/safes/${safeAddress}/`);
|
|
126
|
-
|
|
126
|
+
nonceValue = nonceResponse.data.nonce;
|
|
127
127
|
}
|
|
128
128
|
catch (e) {
|
|
129
129
|
if (!(e instanceof Error) || !e.toString().startsWith("Error: Can't get safe-transaction url")) {
|
|
@@ -131,6 +131,9 @@ function createMultiSendTransaction(ethers, safeAddress, privateKey, transaction
|
|
|
131
131
|
}
|
|
132
132
|
}
|
|
133
133
|
}
|
|
134
|
+
else {
|
|
135
|
+
nonceValue = nonce;
|
|
136
|
+
}
|
|
134
137
|
const tx = {
|
|
135
138
|
"safe": safeAddress,
|
|
136
139
|
"to": multiSend.address,
|
|
@@ -142,7 +145,7 @@ function createMultiSendTransaction(ethers, safeAddress, privateKey, transaction
|
|
|
142
145
|
"baseGas": 0,
|
|
143
146
|
"gasPrice": 0,
|
|
144
147
|
"refundReceiver": ethers.constants.AddressZero,
|
|
145
|
-
"nonce":
|
|
148
|
+
"nonce": nonceValue, // Nonce of the Safe, transaction cannot be executed until Safe's nonce is not equal to this nonce
|
|
146
149
|
};
|
|
147
150
|
const digestHex = yield safe.getTransactionHash(tx.to, tx.value, tx.data, tx.operation, tx.safeTxGas, tx.baseGas, tx.gasPrice, tx.gasToken, tx.refundReceiver, tx.nonce);
|
|
148
151
|
const privateKeyBuffer = ethUtil.toBuffer(privateKey);
|
package/dist/src/upgrade.d.ts
CHANGED
|
@@ -3,5 +3,6 @@ import { Contract } from "ethers";
|
|
|
3
3
|
import { OwnableUpgradeable } from "../typechain-types";
|
|
4
4
|
export declare function getContractFactoryAndUpdateManifest(contract: string): Promise<import("ethers").ContractFactory>;
|
|
5
5
|
declare type DeploymentAction<ContractManagerType extends Contract> = (safeTransactions: string[], abi: SkaleABIFile, contractManager: ContractManagerType) => Promise<void>;
|
|
6
|
-
|
|
6
|
+
declare type MultiTransactionAction<ContractManagerType extends Contract> = (abi: SkaleABIFile, contractManager: ContractManagerType) => Promise<string[][]>;
|
|
7
|
+
export declare function upgrade<ContractManagerType extends OwnableUpgradeable>(projectName: string, targetVersion: string, getDeployedVersion: (abi: SkaleABIFile) => Promise<string | undefined>, setVersion: (safeTransaction: string[], abi: SkaleABIFile, newVersion: string) => Promise<void>, safeMockAccessRequirements: string[], contractNamesToUpgrade: string[], deployNewContracts: DeploymentAction<ContractManagerType>, initialize: DeploymentAction<ContractManagerType>, afterUpgrade?: MultiTransactionAction<ContractManagerType>): Promise<void>;
|
|
7
8
|
export {};
|
package/dist/src/upgrade.js
CHANGED
|
@@ -62,7 +62,7 @@ function getContractFactoryAndUpdateManifest(contract) {
|
|
|
62
62
|
});
|
|
63
63
|
}
|
|
64
64
|
exports.getContractFactoryAndUpdateManifest = getContractFactoryAndUpdateManifest;
|
|
65
|
-
function upgrade(projectName, targetVersion, getDeployedVersion, setVersion, safeMockAccessRequirements, contractNamesToUpgrade, deployNewContracts, initialize) {
|
|
65
|
+
function upgrade(projectName, targetVersion, getDeployedVersion, setVersion, safeMockAccessRequirements, contractNamesToUpgrade, deployNewContracts, initialize, afterUpgrade) {
|
|
66
66
|
return __awaiter(this, void 0, void 0, function* () {
|
|
67
67
|
if (!process.env.ABI) {
|
|
68
68
|
console.log(chalk_1.default.red("Set path to file with ABI and addresses to ABI environment variables"));
|
|
@@ -171,10 +171,23 @@ function upgrade(projectName, targetVersion, getDeployedVersion, setVersion, saf
|
|
|
171
171
|
// Use random one because we most probable run tests
|
|
172
172
|
privateKey = hardhat_1.ethers.Wallet.createRandom().privateKey;
|
|
173
173
|
}
|
|
174
|
-
const safeTx = yield (0, gnosis_safe_1.createMultiSendTransaction)(hardhat_1.ethers, safe, privateKey, safeTransactions, safeMock !== undefined);
|
|
174
|
+
const safeTx = yield (0, gnosis_safe_1.createMultiSendTransaction)(hardhat_1.ethers, safe, privateKey, safeTransactions, safeMock !== undefined ? 0 : undefined);
|
|
175
|
+
let transactionsBatches;
|
|
176
|
+
if (afterUpgrade !== undefined) {
|
|
177
|
+
transactionsBatches = yield afterUpgrade(abi, contractManager);
|
|
178
|
+
for (const { index, batch } of transactionsBatches.map((batch, index) => ({ index, batch }))) {
|
|
179
|
+
yield fs_1.promises.writeFile(`data/after-transactions-${index}-${version}-${hardhat_1.network.name}.json`, JSON.stringify(batch, null, 4));
|
|
180
|
+
}
|
|
181
|
+
}
|
|
175
182
|
if (!safeMock) {
|
|
176
183
|
const chainId = (yield hardhat_1.ethers.provider.getNetwork()).chainId;
|
|
177
184
|
yield (0, gnosis_safe_1.sendSafeTransaction)(safe, chainId, safeTx);
|
|
185
|
+
if (transactionsBatches !== undefined) {
|
|
186
|
+
for (const { batch, index } of transactionsBatches.map((batch, index) => ({ batch, index }))) {
|
|
187
|
+
const multiSendTransaction = yield (0, gnosis_safe_1.createMultiSendTransaction)(hardhat_1.ethers, safe, privateKey, batch, safeTx.nonce + index + 1);
|
|
188
|
+
yield (0, gnosis_safe_1.sendSafeTransaction)(safe, chainId, multiSendTransaction);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
178
191
|
}
|
|
179
192
|
else {
|
|
180
193
|
console.log(chalk_1.default.blue("Send upgrade transactions to safe mock"));
|
|
@@ -184,6 +197,16 @@ function upgrade(projectName, targetVersion, getDeployedVersion, setVersion, saf
|
|
|
184
197
|
value: safeTx.value,
|
|
185
198
|
data: safeTx.data,
|
|
186
199
|
})).wait();
|
|
200
|
+
if (transactionsBatches !== undefined) {
|
|
201
|
+
for (const batch of transactionsBatches) {
|
|
202
|
+
const multiSendTransaction = yield (0, gnosis_safe_1.createMultiSendTransaction)(hardhat_1.ethers, safe, privateKey, batch, 0);
|
|
203
|
+
yield (yield deployer.sendTransaction({
|
|
204
|
+
to: safeMock.address,
|
|
205
|
+
value: multiSendTransaction.value,
|
|
206
|
+
data: multiSendTransaction.data,
|
|
207
|
+
})).wait();
|
|
208
|
+
}
|
|
209
|
+
}
|
|
187
210
|
console.log(chalk_1.default.blue("Transactions have been sent"));
|
|
188
211
|
}
|
|
189
212
|
finally {
|