Skip to content

Commit 6e0840e

Browse files
committed
include option to fund using -eth or -a
1 parent e7825d2 commit 6e0840e

2 files changed

Lines changed: 46 additions & 14 deletions

File tree

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

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -233,15 +233,22 @@ var (
233233
`)
234234

235235
evmNodesFundExample = cli.Examples(`
236-
# Fund all nodes with at least 0.5 ETH on chain 1 in staging
237-
exemplar evm nodes fund --environment staging --selector 1 --amount 0.5 --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
238244
`)
239245
)
240246

241247
func (c Commands) newEvmNodesFund(domain domain.Domain) *cobra.Command {
242248
var (
243-
amountStr string
244-
use1559 bool
249+
ethAmount string
250+
weiAmount string
251+
use1559 bool
245252
)
246253

247254
cmd := cobra.Command{
@@ -252,6 +259,15 @@ func (c Commands) newEvmNodesFund(domain domain.Domain) *cobra.Command {
252259
RunE: func(cmd *cobra.Command, args []string) error {
253260
envKey, _ := cmd.Flags().GetString("environment")
254261
chainselector, _ := cmd.Flags().GetUint64("selector")
262+
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+
}
255271

256272
env, err := environment.Load(cmd.Context(), domain, envKey,
257273
environment.WithLogger(c.lggr),
@@ -264,13 +280,24 @@ func (c Commands) newEvmNodesFund(domain domain.Domain) *cobra.Command {
264280
return fmt.Errorf("chain not found for selector %d", chainselector)
265281
}
266282
chain := env.BlockChains.EVMChains()[cs.Selector]
267-
// Parse amount as ETH and convert to wei
268-
targetAmountEth, success := big.NewFloat(0).SetString(amountStr)
269-
if !success {
270-
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+
}
271300
}
272-
targetAmountWei := new(big.Float).Mul(targetAmountEth, big.NewFloat(params.Ether))
273-
targetAmount, _ := targetAmountWei.Int(nil)
274301
for _, node := range env.NodeIDs {
275302
chainConfigs, err := env.Offchain.ListNodeChainConfigs(cmd.Context(),
276303
&nodev1.ListNodeChainConfigsRequest{
@@ -314,7 +341,8 @@ func (c Commands) newEvmNodesFund(domain domain.Domain) *cobra.Command {
314341
},
315342
}
316343

317-
cmd.Flags().StringVarP(&amountStr, "amount", "a", "", "Target amount in ETH to ensure for each node (e.g., 10 for 10 ETH)")
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)")
318346
cmd.Flags().BoolVar(&use1559, "1559", false, "Use EIP-1559 transaction")
319347

320348
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)