99
1010 "github.com/ethereum/go-ethereum/common"
1111 "github.com/ethereum/go-ethereum/core/types"
12+ "github.com/ethereum/go-ethereum/params"
1213 chainsel "github.com/smartcontractkit/chain-selectors"
1314 nodev1 "github.com/smartcontractkit/chainlink-protos/job-distributor/v1/node"
1415 "github.com/spf13/cobra"
@@ -232,14 +233,21 @@ var (
232233` )
233234
234235 evmNodesFundExample = cli .Examples (`
235- # Fund all nodes with at least 0.5 ETH (in wei) on chain 1 in staging
236- exemplar evm nodes fund --environment staging --selector 1 --amount 500000000000000000 --1559
236+ # Fund all nodes with at least 0.5 ETH on chain 1 in staging (using --eth flag)
237+ exemplar evm nodes fund --environment staging --selector 1 --eth 0.5 --1559
238+
239+ # Fund all nodes with 100 ETH
240+ exemplar evm nodes fund --environment staging --selector 1 --eth 100
241+
242+ # Fund all nodes with specific wei amount (using --amount flag)
243+ exemplar evm nodes fund --environment staging --selector 1 --amount 10000000000000000000
237244` )
238245)
239246
240247func (c Commands ) newEvmNodesFund (domain domain.Domain ) * cobra.Command {
241248 var (
242- amountStr string
249+ ethAmount string
250+ weiAmount string
243251 use1559 bool
244252 )
245253
@@ -252,6 +260,15 @@ func (c Commands) newEvmNodesFund(domain domain.Domain) *cobra.Command {
252260 envKey , _ := cmd .Flags ().GetString ("environment" )
253261 chainselector , _ := cmd .Flags ().GetUint64 ("selector" )
254262
263+ // Check that exactly one of --eth or --amount is provided
264+ if ethAmount != "" && weiAmount != "" {
265+ return errors .New ("cannot use both --eth and --amount flags. Use --eth for ETH amounts (e.g., --eth 10) or --amount for wei amounts" )
266+ }
267+
268+ if ethAmount == "" && weiAmount == "" {
269+ return errors .New ("either --eth or --amount flag is required. Use --eth for ETH amounts (e.g., --eth 10) or --amount for wei amounts" )
270+ }
271+
255272 env , err := environment .Load (cmd .Context (), domain , envKey ,
256273 environment .WithLogger (c .lggr ),
257274 )
@@ -263,9 +280,23 @@ func (c Commands) newEvmNodesFund(domain domain.Domain) *cobra.Command {
263280 return fmt .Errorf ("chain not found for selector %d" , chainselector )
264281 }
265282 chain := env .BlockChains .EVMChains ()[cs .Selector ]
266- targetAmount , success := big .NewInt (0 ).SetString (amountStr , 10 )
267- if ! success {
268- return errors .New ("invalid amount" )
283+
284+ var targetAmount * big.Int
285+ if ethAmount != "" {
286+ // Parse amount as ETH and convert to wei
287+ targetAmountEth , success := big .NewFloat (0 ).SetString (ethAmount )
288+ if ! success {
289+ return errors .New ("invalid ETH amount" )
290+ }
291+ targetAmountWei := new (big.Float ).Mul (targetAmountEth , big .NewFloat (params .Ether ))
292+ targetAmount , _ = targetAmountWei .Int (nil )
293+ } else {
294+ // Parse amount as wei
295+ var success bool
296+ targetAmount , success = big .NewInt (0 ).SetString (weiAmount , 10 )
297+ if ! success {
298+ return errors .New ("invalid wei amount" )
299+ }
269300 }
270301 for _ , node := range env .NodeIDs {
271302 chainConfigs , err := env .Offchain .ListNodeChainConfigs (cmd .Context (),
@@ -293,11 +324,11 @@ func (c Commands) newEvmNodesFund(domain domain.Domain) *cobra.Command {
293324 if err != nil {
294325 return fmt .Errorf ("failed to get balance: %w" , err )
295326 }
296- cmd .Printf ("Current balance %d for %s on node %s" , b , chainConfig .AccountAddress , node )
327+ cmd .Printf ("Current balance %d for %s on node %s\n " , b , chainConfig .AccountAddress , node )
297328 // Let's fund the difference.
298329 if b .Cmp (targetAmount ) < 0 {
299330 amount := big .NewInt (0 ).Sub (targetAmount , b )
300- cmd .Printf ("Current balance insufficient, funding node %s's address %s with %d" , node , chainConfig .AccountAddress , amount )
331+ cmd .Printf ("Current balance insufficient, funding node %s's address %s with %d\n " , node , chainConfig .AccountAddress , amount )
301332 err = sendGas (cmd .Context (), c .lggr , chain , amount .String (), chainConfig .AccountAddress , use1559 )
302333 if err != nil {
303334 return fmt .Errorf ("failed to send gas: %w" , err )
@@ -310,7 +341,8 @@ func (c Commands) newEvmNodesFund(domain domain.Domain) *cobra.Command {
310341 },
311342 }
312343
313- cmd .Flags ().StringVarP (& amountStr , "amount" , "a" , "" , "Target amount of gas to ensure for each node" )
344+ cmd .Flags ().StringVar (& ethAmount , "eth" , "" , "Target amount in ETH to ensure for each node (e.g., 10 for 10 ETH)" )
345+ cmd .Flags ().StringVarP (& weiAmount , "amount" , "a" , "" , "Target amount in wei to ensure for each node (e.g., 10000000000000000000 for 10 ETH)" )
314346 cmd .Flags ().BoolVar (& use1559 , "1559" , false , "Use EIP-1559 transaction" )
315347
316348 return & cmd
0 commit comments