Skip to content

Commit 95f96d9

Browse files
authored
Update fund nodes cmd (#595)
- Adds new line formatting on output: <img width="2226" height="271" alt="Screenshot 2025-11-24 at 7 53 14 PM" src="https://github.com/user-attachments/assets/51339b17-5987-451d-aaba-88e3f6cf6444" /> - Adds option to use eth as the amount param. This is easier for humans to discern and prevents funding errors.
1 parent d1febae commit 95f96d9

3 files changed

Lines changed: 53 additions & 12 deletions

File tree

.changeset/tricky-sheep-sleep.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"chainlink-deployments-framework": patch
3+
---
4+
5+
Added -eth flag to the evm nodes fund command. Example: users can now use "-eth 10" to fund nodes up to 10 eth. Also added a new line separator to the current balance log to improve readability.

engine/cld/legacy/cli/commands/evm.go

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
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

240247
func (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

engine/cld/legacy/cli/commands/evm_test.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,17 @@ func TestNewEvmNodesFund_Metadata(t *testing.T) {
122122
require.Contains(t, cmd.Short, "Ensure all nodes have a certain amount of gas")
123123
require.Contains(t, cmd.Long, "Ensure all OCR2 nodes have a target amount of gas in their account on an EVM chain.")
124124
require.Contains(t, cmd.Example, "--amount")
125+
require.Contains(t, cmd.Example, "--eth")
125126

126-
// Local flags
127+
// Local flags - both --eth and --amount should exist
128+
require.NotNil(t, cmd.Flags().Lookup("eth"), "eth flag should exist")
127129
require.NotNil(t, cmd.Flags().Lookup("amount"), "amount flag should exist")
128130
require.NotNil(t, cmd.Flags().Lookup("1559"), "1559 flag should exist")
129131

130-
// The local 'amount' flag should be required
131-
_, err := cmd.Flags().GetString("amount")
132+
// Both flags should be retrievable
133+
_, err := cmd.Flags().GetString("eth")
134+
require.NoError(t, err)
135+
_, err = cmd.Flags().GetString("amount")
132136
require.NoError(t, err)
133137
// Persistent flags live on the parent
134138
parent := &cobra.Command{}

0 commit comments

Comments
 (0)