Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: asset precision #14

Merged
merged 1 commit into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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)
Expand Down
31 changes: 16 additions & 15 deletions internal/server/config.go
Original file line number Diff line number Diff line change
@@ -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,
}
}
4 changes: 2 additions & 2 deletions internal/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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")
Expand Down
Loading