diff --git a/cmd/server.go b/cmd/server.go index 38d5f6a..5492ea3 100644 --- a/cmd/server.go +++ b/cmd/server.go @@ -21,12 +21,13 @@ var ( queueCapFlag = flag.Int("queuecap", 100, "Maximum transactions waiting to be sent") versionFlag = flag.Bool("version", false, "Print version number") - assetFlag = flag.String("faucet.asset", "nria", "Asset and feeAsset used for transactions") - payoutFlag = flag.Int("faucet.amount", 1, "Number of Sequencer tokens to transfer per user request") - intervalFlag = flag.Int("faucet.minutes", 1440, "Number of minutes to wait between funding rounds") - netnameFlag = flag.String("faucet.name", "Astria Sequencer Network", "Network name to display on the frontend") - chainIdFlag = flag.String("sequencer.chainId", "astria-dusk-9", "Sequencer chain id to use for transactions") - prefixFlag = flag.String("bech32.prefix", "astria", "Bech32 prefix for the address") + assetFlag = flag.String("faucet.asset", "nria", "Asset and feeAsset used for transactions") + payoutFlag = flag.Int("faucet.amount", 1, "Number of Sequencer tokens to transfer per user request") + intervalFlag = flag.Int("faucet.minutes", 1440, "Number of minutes to wait between funding rounds") + netnameFlag = flag.String("faucet.name", "Astria Sequencer Network", "Network name to display on the frontend") + chainIdFlag = flag.String("sequencer.chainId", "astria-dusk-9", "Sequencer chain id to use for transactions") + prefixFlag = flag.String("bech32.prefix", "astria", "Bech32 prefix for the address") + precisionFlag = flag.Int("faucet.precision", 9, "Precision of the asset") privKeyFlag = flag.String("wallet.privkey", os.Getenv("PRIVATE_KEY"), "Private key hex to fund user requests with") providerFlag = flag.String("wallet.provider", os.Getenv("WEB3_PROVIDER"), "Endpoint for Ethereum JSON-RPC connection") @@ -50,7 +51,7 @@ func Execute() { if err != nil { panic(fmt.Errorf("cannot connect to web3 provider: %w", err)) } - config := server.NewConfig(*netnameFlag, *httpPortFlag, *intervalFlag, *payoutFlag, *proxyCntFlag, *queueCapFlag) + config := server.NewConfig(*netnameFlag, *httpPortFlag, *intervalFlag, *payoutFlag, *precisionFlag, *proxyCntFlag, *queueCapFlag) go server.NewServer(txBuilder, config).Run() c := make(chan os.Signal, 1) diff --git a/internal/server/config.go b/internal/server/config.go index 1326b0d..d09a2f0 100644 --- a/internal/server/config.go +++ b/internal/server/config.go @@ -1,27 +1,28 @@ package server import ( + "math" "math/big" ) type Config struct { - network string - httpPort int - interval int - payout *big.Int - payoutNano *big.Int - proxyCount int - queueCap int + network string + httpPort int + interval int + payout *big.Int + payoutAmount *big.Int + proxyCount int + queueCap int } -func NewConfig(network string, httpPort, interval, payout, proxyCount, queueCap int) *Config { +func NewConfig(network string, httpPort, interval, payout, precision, proxyCount, queueCap int) *Config { return &Config{ - network: network, - httpPort: httpPort, - interval: interval, - payout: big.NewInt(int64(payout)), - payoutNano: big.NewInt(int64(payout * 1e9)), - proxyCount: proxyCount, - queueCap: queueCap, + network: network, + httpPort: httpPort, + interval: interval, + payout: big.NewInt(int64(payout)), + payoutAmount: big.NewInt(int64(payout * int(math.Pow10(precision)))), + proxyCount: proxyCount, + queueCap: queueCap, } } diff --git a/internal/server/server.go b/internal/server/server.go index 0fd0daa..7dc3b8b 100644 --- a/internal/server/server.go +++ b/internal/server/server.go @@ -63,7 +63,7 @@ func (s *Server) consumeQueue() { defer s.mutex.Unlock() for len(s.queue) != 0 { address := <-s.queue - txHash, err := s.Transfer(context.Background(), address, s.cfg.payoutNano) + txHash, err := s.Transfer(context.Background(), address, s.cfg.payoutAmount) if err != nil { log.WithError(err).Error("Failed to handle transaction in the queue") } else { @@ -102,7 +102,7 @@ func (s *Server) handleClaim() http.HandlerFunc { ctx, cancel := context.WithTimeout(r.Context(), 5*time.Second) defer cancel() - txHash, err := s.Transfer(ctx, address, s.cfg.payoutNano) + txHash, err := s.Transfer(ctx, address, s.cfg.payoutAmount) s.mutex.Unlock() if err != nil { log.WithError(err).Error("Failed to send transaction")