notice dev dev const fs = require ( 'fs' ) ; const hre = require ( 'hardhat' ) ; const { exit } = require ( 'process' ) ; const { ethers } = hre ; const network = process . env . HARDHAT_NETWORK ; const parameters = { accounts : { } , actions : { } , contracts : { } , } ; const now = new Date ( ) . toISOString ( ) ; const folderName = './deploy-history' ; const fileName = `${ folderName }/${ network }-${ now }.json` ; const latestFileName = `${ folderName }/${ network }-latest.json` ; fs . mkdir ( folderName , ( err ) => { if ( err && err . code !== 'EEXIST' ) throw err ; } ) ; const save = ( value , field , subfield = undefined ) => { if ( subfield ) { parameters [ field ] [ subfield ] = value ; } else { parameters [ field ] = value ; } fs . writeFileSync ( fileName , JSON . stringify ( parameters ) ) ; } ; ( async function ( ) { try { const deployParams = require ( './deployParams.json' ) ; const deployParamsForNetwork = deployParams [ network ] ; if ( ! deployParamsForNetwork ) { console . log ( 'Invalid network requested' , network ) ; save ( network , 'actions' , 'InvalidNetworkRequested' ) ; exit ( ) ; } console . log ( 'Deploying to: ' , network ) ; save ( network , 'actions' , 'DeployingContractsToNetwork' ) ; const [ adminWallet ] = await ethers . getSigners ( ) ; save ( adminWallet . address , 'accounts' , 'owner' ) ; const { sweepReceiver , sweeper } = deployParamsForNetwork ; if ( ! sweepReceiver || ! sweeper ) { console . log ( 'Missing deploy parameter' ) ; save ( 'Missing deploy parameter' , 'actions' , 'Error' ) ; exit ( ) ; } save ( sweepReceiver , 'accounts' , 'sweepReceiver' ) ; save ( sweeper , 'accounts' , 'sweeper' ) ; const SwapBriber = await ethers . getContractFactory ( 'SwapBriber' , adminWallet ) ; const swapBriber = await SwapBriber . deploy ( sweepReceiver , sweeper ) ; await swapBriber . deployed ( ) ; save ( swapBriber . address , 'contracts' , 'SwapBriber' ) ; console . log ( 'SwapBriber contract deployed to address: ' , swapBriber . address ) ; fs . writeFileSync ( latestFileName , JSON . stringify ( parameters ) ) ; } catch ( error ) { save ( error . toString ( ) , 'actions' , 'Error' ) ; console . log ( 'Deployment Error: ' , error . toString ( ) ) ; } } ) ( ) ;