Skip to content

Commit ff178be

Browse files
committed
chore: simplify batching and add gas fees to migration script
1 parent 82fcbe8 commit ff178be

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

scripts/migrate-cover-data.js

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,32 @@ const { addresses, Cover } = require('@nexusmutual/deployments');
44
// set/change env MAINNET_ACCOUNT_KEY and MAINNET_GAS_PRICE
55
// run command: HARDHAT_NETWORK=mainnet node scripts/migrate-cover-data.js
66

7+
const { MAX_FEE_GWEI = '10' } = process.env;
8+
79
async function main() {
8-
const cover = await ethers.getContractAt(Cover, addresses.Cover);
910
const signer = await ethers.getSigner();
11+
const cover = await ethers.getContractAt(Cover, addresses.Cover, signer);
1012

1113
const totalCovers = await cover.getCoverDataCount();
14+
const allCoverIds = new Array(totalCovers).fill(0).map((_, i) => i + 1);
15+
1216
const coversPerTx = 100;
1317
const gasLimit = 15000000;
18+
const maxFeePerGas = ethers.utils.parseUnits(MAX_FEE_GWEI, 'gwei');
19+
const maxPriorityFeePerGas = ethers.utils.parseUnits('0.5', 'gwei');
1420

15-
for (let startId = 1; startId < totalCovers; startId += coversPerTx) {
16-
const endId = Math.min(startId + coversPerTx - 1, totalCovers);
17-
const coverIds = [];
18-
for (let i = startId; i <= endId; i++) {
19-
coverIds.push(i);
20-
}
21-
21+
while (allCoverIds.length > 0) {
22+
const coverIds = allCoverIds.splice(0, coversPerTx);
2223
console.log(`Migrating cover ids: ${coverIds}`);
2324

24-
const tx = await cover.connect(signer).migrateCoverDataAndPoolAllocations(coverIds, { gasLimit });
25-
console.log(`tx hash: ${tx.hash}`);
25+
const overrides = { gasLimit, maxFeePerGas, maxPriorityFeePerGas };
26+
const tx = await cover.migrateCoverDataAndPoolAllocations(coverIds, overrides);
2627

27-
const txReceipt = await tx.wait();
28-
29-
console.log(`tx receipt: ${txReceipt}`);
28+
console.log(`Sent tx: ${tx.hash}`);
29+
await tx.wait();
3030
}
31+
32+
console.log('All covers migrated');
3133
}
3234

3335
main()

0 commit comments

Comments
 (0)