22
33const path = require ( 'path' ) ;
44const fs = require ( 'fs' ) ;
5- const w3utils = require ( 'web3-utils' ) ;
6- const Web3 = require ( 'web3' ) ;
5+ const ethers = require ( 'ethers' ) ;
76const { red, gray, green, yellow } = require ( 'chalk' ) ;
87
98const {
@@ -68,16 +67,17 @@ const importFeePeriods = async ({
6867 privateKey = envPrivateKey ;
6968 }
7069
71- const web3 = new Web3 ( new Web3 . providers . HttpProvider ( providerUrl ) ) ;
72-
73- let account ;
70+ const provider = new ethers . providers . JsonRpcProvider ( providerUrl ) ;
71+ let wallet ;
7472 if ( useFork ) {
75- account = getUsers ( { network, user : 'owner' } ) . address ; // protocolDAO
73+ const account = getUsers ( { network, user : 'owner' } ) . address ; // protocolDAO
74+ wallet = provider . getSigner ( account ) ;
7675 } else {
77- web3 . eth . accounts . wallet . add ( privateKey ) ;
78- account = web3 . eth . accounts . wallet [ 0 ] . address ;
76+ wallet = new ethers . Wallet ( privateKey , provider ) ;
7977 }
80- console . log ( gray ( `Using account with public key ${ account } ` ) ) ;
78+
79+ if ( ! wallet . address ) wallet . address = wallet . _address ;
80+ console . log ( gray ( `Using account with public key ${ wallet . address } ` ) ) ;
8181
8282 const { address : targetContractAddress , source } = deployment . targets [ 'FeePool' ] ;
8383
@@ -93,11 +93,11 @@ const importFeePeriods = async ({
9393 if ( lastEntry . address !== targetContractAddress ) {
9494 sourceContractAddress = lastEntry . address ;
9595 } else if ( secondLastEntry . address !== targetContractAddress ) {
96- sourceContractAddress = targetContractAddress . address ;
96+ sourceContractAddress = secondLastEntry . address ;
9797 } else {
9898 throw Error ( 'Cannot determine which is the last version of FeePool for the network' ) ;
9999 }
100- } else if ( ! w3utils . isAddress ( sourceContractAddress ) ) {
100+ } else if ( ! ethers . utils . isAddress ( sourceContractAddress ) ) {
101101 throw Error (
102102 'Invalid address detected for source (please check your inputs): ' ,
103103 sourceContractAddress
@@ -115,14 +115,15 @@ const importFeePeriods = async ({
115115 console . log ( gray ( `Reading from old FeePool at: ${ sourceContractAddress } ` ) ) ;
116116 console . log ( gray ( `Importing into new FeePool at: ${ targetContractAddress } ` ) ) ;
117117 }
118- const sourceContract = new web3 . eth . Contract ( abi , sourceContractAddress ) ;
119- const targetContract = new web3 . eth . Contract ( abi , targetContractAddress ) ;
120118
121- const feePeriodLength = await sourceContract . methods . FEE_PERIOD_LENGTH ( ) . call ( ) ;
119+ const sourceContract = new ethers . Contract ( sourceContractAddress , abi , wallet ) ;
120+ const targetContract = new ethers . Contract ( targetContractAddress , abi , wallet ) ;
121+
122+ const feePeriodLength = await sourceContract . FEE_PERIOD_LENGTH ( ) ;
122123
123124 // Check sources
124125 for ( let i = 0 ; i <= feePeriodLength - 1 ; i ++ ) {
125- const period = await sourceContract . methods . recentFeePeriods ( i ) . call ( ) ;
126+ const period = await sourceContract . recentFeePeriods ( i ) ;
126127 if ( ! skipTimeCheck ) {
127128 if ( period . feePeriodId === '0' ) {
128129 throw Error (
@@ -138,21 +139,27 @@ const importFeePeriods = async ({
138139 }
139140
140141 // remove redundant index keys (returned from struct calls)
142+ const filteredPeriod = { } ;
141143 Object . keys ( period )
142- . filter ( key => / ^ [ 0 - 9 ] + $ / . test ( key ) )
143- . forEach ( key => delete period [ key ] ) ;
144- feePeriods . push ( period ) ;
144+ . filter ( key => / ^ [ 0 - 9 ] + $ / . test ( key ) === false )
145+ . forEach ( key => ( filteredPeriod [ key ] = period [ key ] ) ) ;
146+
147+ feePeriods . push ( filteredPeriod ) ;
145148 console . log (
146- gray ( `loaded feePeriod ${ i } from FeePool (startTime: ${ new Date ( period . startTime * 1000 ) } )` )
149+ gray (
150+ `loaded feePeriod ${ i } from FeePool (startTime: ${ new Date (
151+ filteredPeriod . startTime * 1000
152+ ) } )`
153+ )
147154 ) ;
148155 }
149156
150157 // Check target does not have existing periods
151158 if ( ! override ) {
152159 for ( let i = 0 ; i < feePeriodLength ; i ++ ) {
153- const period = await targetContract . methods . recentFeePeriods ( i ) . call ( ) ;
160+ const period = await targetContract . recentFeePeriods ( i ) ;
154161 // ignore any initial entry where feePeriodId is 1 as this is created by the FeePool constructor
155- if ( period . feePeriodId !== '1' && period . startTime !== '0' ) {
162+ if ( period . feePeriodId . toString ( ) !== '1' && period . startTime . toString ( ) !== '0' ) {
156163 throw Error (
157164 `The new target FeePool already has imported fee periods (one or more entries has ` +
158165 `startTime as 0. Please check to make sure you are using the latest FeePool ` +
@@ -204,11 +211,12 @@ const importFeePeriods = async ({
204211 feePeriod . rewardsClaimed ,
205212 ] ;
206213 console . log ( yellow ( `Attempting action FeePool.importFeePeriod(${ importArgs } )` ) ) ;
207- const { transactionHash } = await targetContract . methods . importFeePeriod ( ...importArgs ) . send ( {
208- from : account ,
209- gasLimit : Number ( gasLimit ) ,
210- gasPrice : w3utils . toWei ( gasPrice . toString ( ) , 'gwei' ) ,
214+ const tx = await targetContract . importFeePeriod ( ...importArgs , {
215+ gasLimit : ethers . BigNumber . from ( gasLimit ) ,
216+ gasPrice : ethers . utils . parseUnits ( gasPrice , 'gwei' ) ,
211217 } ) ;
218+ const { transactionHash } = await tx . wait ( ) ;
219+
212220 index ++ ;
213221
214222 console . log (
0 commit comments