@@ -18,6 +18,23 @@ import (
1818 "golang.org/x/term"
1919)
2020
21+ const (
22+ // registrationRequiredBalance is the minimum balance needed to register (1.6 PC in wei)
23+ registrationRequiredBalance = "1600000000000000000"
24+
25+ // registrationMinStake is the minimum self-delegation amount (1.5 PC in wei)
26+ registrationMinStake = "1500000000000000000"
27+
28+ // registrationFeeReserve is the amount reserved for transaction fees (0.1 PC in wei)
29+ registrationFeeReserve = "100000000000000000"
30+
31+ // defaultCommissionRate is the default validator commission rate (10%)
32+ defaultCommissionRate = "0.10"
33+
34+ // defaultMinSelfDelegation is the default minimum self-delegation value
35+ defaultMinSelfDelegation = "1"
36+ )
37+
2138var flagRegisterCheckOnly bool
2239
2340// handleRegisterValidator is a compatibility wrapper that pulls
@@ -27,7 +44,7 @@ func handleRegisterValidator(cfg config.Config) {
2744 // Get defaults from env or use hardcoded fallbacks
2845 defaultMoniker := getenvDefault ("MONIKER" , "push-validator" )
2946 defaultKeyName := getenvDefault ("KEY_NAME" , "validator-key" )
30- defaultAmount := getenvDefault ("STAKE_AMOUNT" , "1500000000000000000" )
47+ defaultAmount := getenvDefault ("STAKE_AMOUNT" , registrationMinStake )
3148
3249 moniker := defaultMoniker
3350 keyName := defaultKeyName
@@ -195,29 +212,29 @@ func handleRegisterValidator(cfg config.Config) {
195212 input = strings .TrimSpace (input )
196213
197214 if input == "" {
198- commissionRate = "0.10" // Default 10%
215+ commissionRate = defaultCommissionRate // Default 10%
199216 } else {
200217 // Parse and validate
201218 rate , err := strconv .ParseFloat (input , 64 )
202219 if err != nil || rate < 1 || rate > 100 {
203220 fmt .Println (p .Colors .Error ("⚠ Invalid commission rate. Using default 10%" ))
204- commissionRate = "0.10"
221+ commissionRate = defaultCommissionRate
205222 } else {
206223 // Convert percentage to decimal (e.g., 15 -> 0.15)
207224 commissionRate = fmt .Sprintf ("%.2f" , rate / 100 )
208225 }
209226 }
210227 fmt .Println ()
211228 } else {
212- commissionRate = getenvDefault ("COMMISSION_RATE" , "0.10" )
229+ commissionRate = getenvDefault ("COMMISSION_RATE" , defaultCommissionRate )
213230 }
214231
215232 // Interactive mode - let user choose stake amount
216233 // Pass empty string to trigger the interactive stake selection prompt
217234 runRegisterValidator (cfg , moniker , keyName , "" , commissionRate , importMnemonic )
218235 } else {
219236 // JSON mode or env vars set - use default/env amount
220- commissionRate := getenvDefault ("COMMISSION_RATE" , "0.10" )
237+ commissionRate := getenvDefault ("COMMISSION_RATE" , defaultCommissionRate )
221238 runRegisterValidator (cfg , moniker , keyName , defaultAmount , commissionRate , "" )
222239 }
223240}
@@ -313,7 +330,7 @@ func runRegisterValidator(cfg config.Config, moniker, keyName, amount, commissio
313330 if local == "" {
314331 local = "http://127.0.0.1:26657"
315332 }
316- remoteHTTP := "https://" + strings . TrimSuffix ( cfg .GenesisDomain , "/" ) + ":443"
333+ remoteHTTP := cfg .RemoteRPCURL ()
317334 cliLocal := node .New (local )
318335 cliRemote := node .New (remoteHTTP )
319336 ctx , cancel := context .WithTimeout (context .Background (), 3 * time .Second )
@@ -405,9 +422,6 @@ func runRegisterValidator(cfg config.Config, moniker, keyName, amount, commissio
405422 p .KeyValueLine ("Cosmos Address" , keyInfo .Address , "dim" )
406423 fmt .Println ()
407424 }
408- const requiredBalance = "1600000000000000000"
409- const minStake = "1500000000000000000" // 1.5 PC in wei
410- const feeReserve = "100000000000000000" // 0.1 PC in wei for gas fees
411425 maxRetries := 10
412426 var finalBalance string
413427
@@ -424,7 +438,7 @@ func runRegisterValidator(cfg config.Config, moniker, keyName, amount, commissio
424438 balInt := new (big.Int )
425439 balInt .SetString (bal , 10 )
426440 reqInt := new (big.Int )
427- reqInt .SetString (requiredBalance , 10 )
441+ reqInt .SetString (registrationRequiredBalance , 10 )
428442 if balInt .Cmp (reqInt ) >= 0 {
429443 fmt .Println (p .Colors .Success ("✅ Sufficient balance" ))
430444 finalBalance = bal
@@ -462,11 +476,11 @@ func runRegisterValidator(cfg config.Config, moniker, keyName, amount, commissio
462476 balInt := new (big.Int )
463477 balInt .SetString (finalBalance , 10 )
464478 feeInt := new (big.Int )
465- feeInt .SetString (feeReserve , 10 )
479+ feeInt .SetString (registrationFeeReserve , 10 )
466480 maxStakeable := new (big.Int ).Sub (balInt , feeInt )
467481
468482 minStakeInt := new (big.Int )
469- minStakeInt .SetString (minStake , 10 )
483+ minStakeInt .SetString (registrationMinStake , 10 )
470484
471485 // Display balance and staking range
472486 fmt .Println ()
@@ -526,12 +540,12 @@ func runRegisterValidator(cfg config.Config, moniker, keyName, amount, commissio
526540 break
527541 }
528542 } else if stake == "" {
529- stake = minStake
543+ stake = registrationMinStake
530544 }
531545 // Create fresh context for registration transaction (independent of earlier operations)
532546 regCtx , regCancel := context .WithTimeout (context .Background (), 90 * time .Second )
533547 defer regCancel ()
534- txHash , err := v .Register (regCtx , validator.RegisterArgs {Moniker : moniker , Amount : stake , KeyName : keyName , CommissionRate : commissionRate , MinSelfDelegation : "1" })
548+ txHash , err := v .Register (regCtx , validator.RegisterArgs {Moniker : moniker , Amount : stake , KeyName : keyName , CommissionRate : commissionRate , MinSelfDelegation : defaultMinSelfDelegation })
535549 if err != nil {
536550 errMsg := err .Error ()
537551 if flagOutput == "json" {
0 commit comments