@@ -4,30 +4,32 @@ const { addresses, Cover } = require('@nexusmutual/deployments');
4
4
// set/change env MAINNET_ACCOUNT_KEY and MAINNET_GAS_PRICE
5
5
// run command: HARDHAT_NETWORK=mainnet node scripts/migrate-cover-data.js
6
6
7
+ const { MAX_FEE_GWEI = '10' } = process . env ;
8
+
7
9
async function main ( ) {
8
- const cover = await ethers . getContractAt ( Cover , addresses . Cover ) ;
9
10
const signer = await ethers . getSigner ( ) ;
11
+ const cover = await ethers . getContractAt ( Cover , addresses . Cover , signer ) ;
10
12
11
13
const totalCovers = await cover . getCoverDataCount ( ) ;
14
+ const allCoverIds = new Array ( totalCovers ) . fill ( 0 ) . map ( ( _ , i ) => i + 1 ) ;
15
+
12
16
const coversPerTx = 100 ;
13
17
const gasLimit = 15000000 ;
18
+ const maxFeePerGas = ethers . utils . parseUnits ( MAX_FEE_GWEI , 'gwei' ) ;
19
+ const maxPriorityFeePerGas = ethers . utils . parseUnits ( '0.5' , 'gwei' ) ;
14
20
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 ) ;
22
23
console . log ( `Migrating cover ids: ${ coverIds } ` ) ;
23
24
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 ) ;
26
27
27
- const txReceipt = await tx . wait ( ) ;
28
-
29
- console . log ( `tx receipt: ${ txReceipt } ` ) ;
28
+ console . log ( `Sent tx: ${ tx . hash } ` ) ;
29
+ await tx . wait ( ) ;
30
30
}
31
+
32
+ console . log ( 'All covers migrated' ) ;
31
33
}
32
34
33
35
main ( )
0 commit comments