@@ -3,10 +3,12 @@ import { subtask, task } from 'hardhat/config'
3
3
import { cliOpts } from '../../cli/defaults'
4
4
import { addCustomNetwork } from '@arbitrum/sdk/dist/lib/dataEntities/networks'
5
5
import fs from 'fs'
6
+ import { execSync } from 'child_process'
6
7
7
8
export const TASK_NITRO_FUND_ACCOUNTS = 'nitro:fund-accounts'
8
9
export const TASK_NITRO_SETUP_SDK = 'nitro:sdk-setup'
9
10
export const TASK_NITRO_SETUP_ADDRESS_BOOK = 'nitro:address-book-setup'
11
+ export const TASK_NITRO_FETCH_DEPLOYMENT_FILE = 'nitro:fetch-deployment-file'
10
12
11
13
task ( TASK_NITRO_FUND_ACCOUNTS , 'Funds protocol accounts on Arbitrum Nitro testnodes' )
12
14
. addOptionalParam ( 'graphConfig' , cliOpts . graphConfig . description )
@@ -77,7 +79,7 @@ task(TASK_NITRO_FUND_ACCOUNTS, 'Funds protocol accounts on Arbitrum Nitro testno
77
79
// Arbitrum SDK does not support Nitro testnodes out of the box
78
80
// This adds the testnodes to the SDK configuration
79
81
subtask ( TASK_NITRO_SETUP_SDK , 'Adds nitro testnodes to SDK config' )
80
- . addParam ( 'deploymentFile' , 'The testnode deployment file to use' )
82
+ . addParam ( 'deploymentFile' , 'The testnode deployment file to use' , 'localNetwork.json' )
81
83
. setAction ( async ( taskArgs ) => {
82
84
if ( ! fs . existsSync ( taskArgs . deploymentFile ) ) {
83
85
throw new Error ( `Deployment file not found: ${ taskArgs . deploymentFile } ` )
@@ -89,13 +91,33 @@ subtask(TASK_NITRO_SETUP_SDK, 'Adds nitro testnodes to SDK config')
89
91
} )
90
92
} )
91
93
94
+ subtask ( TASK_NITRO_FETCH_DEPLOYMENT_FILE , 'Fetches nitro deployment file from a local testnode' )
95
+ . addParam (
96
+ 'deploymentFile' ,
97
+ 'Path to the file where to deployment file will be saved' ,
98
+ 'localNetwork.json' ,
99
+ )
100
+ . setAction ( async ( taskArgs ) => {
101
+ console . log ( `Attempting to fetch deployment file from testnode...` )
102
+
103
+ const command =
104
+ 'docker exec $(docker ps -qf "name=sequencer") cat /deployment/localNetwork.json > localNetwork.json'
105
+ const stdOut = execSync ( command )
106
+ console . log ( stdOut . toString ( ) )
107
+
108
+ if ( ! fs . existsSync ( taskArgs . deploymentFile ) ) {
109
+ throw new Error ( `Unable to fetch deployment file: ${ taskArgs . deploymentFile } ` )
110
+ }
111
+ console . log ( `Deployment file saved to ${ taskArgs . deploymentFile } ` )
112
+ } )
113
+
92
114
// Read arbitrum contract addresses from deployment file and write them to the address book
93
115
task ( TASK_NITRO_SETUP_ADDRESS_BOOK , 'Write arbitrum addresses to address book' )
94
116
. addParam ( 'deploymentFile' , 'The testnode deployment file to use' )
95
117
. addParam ( 'arbitrumAddressBook' , 'Arbitrum address book file' )
96
- . setAction ( async ( taskArgs ) => {
118
+ . setAction ( async ( taskArgs , hre ) => {
97
119
if ( ! fs . existsSync ( taskArgs . deploymentFile ) ) {
98
- throw new Error ( `Deployment file not found: ${ taskArgs . deploymentFile } ` )
120
+ await hre . run ( TASK_NITRO_FETCH_DEPLOYMENT_FILE , taskArgs )
99
121
}
100
122
const deployment = JSON . parse ( fs . readFileSync ( taskArgs . deploymentFile , 'utf-8' ) )
101
123
0 commit comments