Skip to content

Commit c3b46d0

Browse files
committed
Add ethBalMon setWatchList validate configuration function
1 parent 4bb993a commit c3b46d0

2 files changed

Lines changed: 33 additions & 1 deletion

File tree

deployment/vault/changeset/ethbalmon_setWatchList.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ type ethBalMonSetWatchList struct{}
2525
var EthBalMonSetWatchList cldf.ChangeSetV2[vaulttypes.EthBalMonSetWatchListInput] = ethBalMonSetWatchList{}
2626

2727
func (sw ethBalMonSetWatchList) VerifyPreconditions(env cldf.Environment, config vaulttypes.EthBalMonSetWatchListInput) error {
28-
return nil
28+
return ValidateEthBalMonSetWatchListConfig(env.GetContext(), env, config)
2929

3030
}
3131

deployment/vault/changeset/validation.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,3 +312,35 @@ func ValidateEthBalMonTransferOwnershipConfig(ctx context.Context, env cldf.Envi
312312

313313
return nil
314314
}
315+
316+
func ValidateEthBalMonSetWatchListConfig(ctx context.Context, env cldf.Environment, cfg types.EthBalMonSetWatchListInput) error {
317+
if len(cfg.Chains) == 0 {
318+
return fmt.Errorf("no chains provided")
319+
}
320+
321+
for chainSelector, chainConfig := range cfg.Chains {
322+
if _, ok := env.BlockChains.EVMChains()[chainSelector]; !ok {
323+
return fmt.Errorf("chain not found in environment: %d", chainSelector)
324+
}
325+
if len(chainConfig.Addresses) == 0 {
326+
return fmt.Errorf("chain %d: addresses must not be empty", chainSelector)
327+
}
328+
if len(chainConfig.MinBalancesWei) == 0 {
329+
return fmt.Errorf("chain %d: min_balance_wei must not be empty", chainSelector)
330+
}
331+
if len(chainConfig.TopUpAmountsWei) == 0 {
332+
return fmt.Errorf("chain %d: topup_amounts_wei must not be empty", chainSelector)
333+
}
334+
for i, addr := range chainConfig.Addresses {
335+
addrStr := addr.Hex()
336+
if !common.IsHexAddress(addrStr) {
337+
return fmt.Errorf("chain %d: address at index %d (%s) is invalid", chainSelector, i, addrStr)
338+
}
339+
if addrStr == "" || addrStr == "0x0000000000000000000000000000000000000000" {
340+
return fmt.Errorf("chain %d: address at index %d is zero address", chainSelector, i)
341+
}
342+
}
343+
}
344+
345+
return nil
346+
}

0 commit comments

Comments
 (0)