Skip to content
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
35 changes: 2 additions & 33 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,25 +101,10 @@ linters-settings:
# report about assignment of errors to blank identifier: `num, _ := strconv.Atoi(numStr)`;
# default is false: such cases aren't reported by default.
check-blank: false
govet:
# report about shadowed variables
#TODO# check-shadowing: true

# Obtain type information from installed (to $GOPATH/pkg) package files:
# golangci-lint will execute `go install -i` and `go test -i` for analyzed packages
# before analyzing them.
# Enable this option only if all conditions are met:
# 1. you use only "fast" linters (--fast e.g.): no program loading occurs
# 2. you use go >= 1.10
# 3. you do repeated runs (false for CI) or cache $GOPATH/pkg or `go env GOCACHE` dir in CI.
use-installed-packages: false
govet: {}
gocritic:
disabled-checks:
- ifElseChain
goimports:
local: "storj.io"
golint:
min-confidence: 0.8
gofmt:
simplify: true
gocyclo:
Expand All @@ -129,26 +114,10 @@ linters-settings:
goconst:
min-len: 3
min-occurrences: 3
misspell:
misspell: {}
lll:
line-length: 140
tab-width: 1
unused:
# treat code as a program (not a library) and report unused exported identifiers; default is false.
# XXX: if you enable this setting, unused will report a lot of false-positives in text editors:
# if it's called for subdir of a project it can't find funcs usages. All text editor integrations
# with golangci-lint call it on a directory with the changed file.
check-exported: false
unparam:
# call graph construction algorithm (cha, rta). In general, use cha for libraries,
# and rta for programs with main packages. Default is cha.
algo: cha

# Inspect exported functions, default is false. Set to true if no external program/library imports your code.
# XXX: if you enable this setting, unparam will report a lot of false-positives in text editors:
# if it's called for subdir of a project it can't find external interfaces. All text editor integrations
# with golangci-lint call it on a directory with the changed file.
check-exported: false
nakedret:
# make an issue if func has more lines of code than this setting and it has naked returns; default is 30
max-func-lines: 30
Expand Down
2 changes: 1 addition & 1 deletion cmd/crybapy/cmd_audit.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func doAudit(config *auditConfig) error {
fmt.Printf("Mismatched..................: %d\n", stats.Mismatched)
if stats.DoublePays > 0 {
fmt.Println(aurora.Red(fmt.Sprintf("Double Pays.................: %d", stats.DoublePays)))
fmt.Println(aurora.Red(fmt.Sprintf("Double Pay Amount (raw STORJ value): %s", stats.DoublePayStorj)))
fmt.Println(aurora.Red(fmt.Sprintf("Double Pay Amount (raw STORJ value): %s", stats.DoublePayStorj.String())))
bad = true
}

Expand Down
8 changes: 2 additions & 6 deletions cmd/crybapy/cmd_payer_balance.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"fmt"

"github.com/spf13/cobra"
)

Expand All @@ -27,7 +28,6 @@ func newPayerBalanceCommand(parentConfig *payerCommandConfig) *cobra.Command {
}

func doPayerBalance(config *payerBalanceConfig, spenderKeyPath string) error {

log, err := openConsoleLog()
if err != nil {
return err
Expand All @@ -40,11 +40,7 @@ func doPayerBalance(config *payerBalanceConfig, spenderKeyPath string) error {
if err != nil {
return err
}
dec, err := payer.GetTokenDecimals(config.Ctx)
if err != nil {
return err
}

fmt.Println(printToken(balance, dec, ""))
fmt.Println(printToken(balance, payer.Decimals(), ""))
return nil
}
4 changes: 2 additions & 2 deletions cmd/crybapy/cmd_payer_transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,14 @@ func doPayerTransfer(config *payerTransferConfig, spenderKeyPath string) error {
LastUpdated: time.Now(),
}, err
}),

PipelineLimit: pipeline.DefaultLimit,
TxDelay: pipeline.DefaultTxDelay,
Drain: false,
PromptConfirm: promptConfirm,
},
db,
payer)
payer,
)
if err != nil {
return err
}
Expand Down
27 changes: 22 additions & 5 deletions cmd/crybapy/cmd_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"storj.io/crypto-batch-payment/pkg/pipelinedb"

"github.com/shopspring/decimal"
"github.com/spf13/cobra"
"github.com/zeebo/errs"

Expand Down Expand Up @@ -118,6 +119,11 @@ func doRun(config *runConfig) error {
return err
}

maxFeeUSD, err := parseOptionalMaxFeeUSD(config.MaxFeeUSD)
if err != nil {
return err
}

dbPath := payouts.DBPathFromDir(runDir)
db, err := pipelinedb.OpenDB(context.Background(), dbPath, false)
if err != nil {
Expand All @@ -126,11 +132,12 @@ func doRun(config *runConfig) error {
defer func() { _ = db.Close() }()

payoutsConfig := payouts.Config{
Quoter: quoter,
PipelineLimit: config.PipelineLimit,
TxDelay: config.TxDelay,
Drain: config.Drain,
PromptConfirm: promptConfirm,
Quoter: quoter,
PipelineLimit: config.PipelineLimit,
TxDelay: config.TxDelay,
Drain: config.Drain,
PromptConfirm: promptConfirm,
MaxFeeTolerationUSD: maxFeeUSD,
}

err = payouts.Preview(config.Ctx, payoutsConfig, db, payer)
Expand All @@ -150,3 +157,13 @@ func doRun(config *runConfig) error {
fmt.Println("Payouts complete.")
return nil
}

func parseOptionalMaxFeeUSD(s string) (maxFeeUSD decimal.Decimal, err error) {
if s != "" {
maxFeeUSD, err = decimal.NewFromString(s)
if err != nil {
return decimal.Decimal{}, errs.New("invalid max fee value: %v", err)
}
}
return maxFeeUSD, nil
}
67 changes: 12 additions & 55 deletions cmd/crybapy/factory_payer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ package main

import (
"context"
"math/big"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/params"
"github.com/spf13/cobra"
"github.com/zeebo/errs"
"go.uber.org/zap"
Expand All @@ -23,21 +21,13 @@ type PayerConfig struct {
ContractAddress string
Owner string

MaxGas string
MaxFee string

GasTipCap string
MaxFeeUSD string

PaymasterAddress string
PaymasterPayload string
}

func RegisterFlags(cmd *cobra.Command, config *PayerConfig) {
cmd.Flags().StringVarP(
&config.GasTipCap,
"gas-tip-cap", "",
"1000000000",
"Gas tip cap, paid on top of the base gas.")
cmd.Flags().StringVarP(
&config.Owner,
"owner", "",
Expand All @@ -48,21 +38,16 @@ func RegisterFlags(cmd *cobra.Command, config *PayerConfig) {
"contract", "",
storjtoken.DefaultContractAddress.String(),
"Address of the STORJ contract on the network")
cmd.Flags().StringVarP(
&config.MaxGas,
"max-gas", "",
"70"+"000"+"000"+"000",
"Max gas price we're willing to consider in Wei (tip + base fee). Default: 70 GWei. Only applies to Eth type payment.")
cmd.Flags().StringVarP(
&config.PayerType,
"type", "",
payer.Eth.String(),
"Type of the payment (eth,zksync-era,zksync,zkwithdraw,sim,polygon)")
cmd.Flags().StringVarP(
&config.MaxFee,
"max-fee", "",
&config.MaxFeeUSD,
"max-fee-usd", "",
"",
"Max fee we're willing to consider. Only applies to zksync or zkwithdraw type payment.")
"Max fee (in USD) we're willing to consider.")
cmd.Flags().StringVarP(
&config.PaymasterAddress,
"paymaster-address", "",
Expand All @@ -82,16 +67,12 @@ func registerNodeAddress(cmd *cobra.Command, addr *string) {
"/home/storj/.ethereum/geth.ipc",
"Address of the ETH node to use")
}

func CreatePayer(ctx context.Context, log *zap.Logger, config PayerConfig, nodeAddress string, chain string, spenderKeyPath string) (paymentPayer payer.Payer, err error) {
spenderKey, spenderAddress, err := loadETHKey(spenderKeyPath, "spender")
if err != nil {
return nil, err
}
var maxGas big.Int
_, ok := maxGas.SetString(config.MaxGas, 10)
if !ok {
return nil, errs.New("invalid max gas setting")
}

owner := spenderAddress
if config.Owner != "" {
Expand All @@ -105,40 +86,17 @@ func CreatePayer(ctx context.Context, log *zap.Logger, config PayerConfig, nodeA
if err != nil {
return nil, err
}
chainID, err := convertInt(chain, 0, "chain-id")
chainIDInt, err := convertInt(chain, 0, "chain-id")
if err != nil {
return nil, err
}

var maxFee *big.Int
if config.MaxFee != "" {
var tmp big.Int
if _, ok := tmp.SetString(config.MaxFee, 10); !ok {
return nil, errs.New("invalid max fee setting")
}
maxFee = &tmp
}

var gasTipCap *big.Int
if config.GasTipCap != "" {
gasTipCap = new(big.Int)
_, ok = gasTipCap.SetString(config.GasTipCap, 10)
if !ok {
return nil, errs.New("invalid gas tip cap setting")
}
if gasTipCap.Cmp(big.NewInt(30*params.GWei)) > 0 {
return nil, errs.New("Gas tip cap is too high. Please use value less than 30 gwei")
}

if gasTipCap.Cmp(big.NewInt(int64(100))) < 0 {
return nil, errs.New("Gas tip cap is negligible. Please check if you really used wei unit (or set 0)")
}
}
chainID := int(chainIDInt.Int64())

pt, err := payer.TypeFromString(config.PayerType)
if err != nil {
return nil, errs.Wrap(err)
}

switch pt {
case payer.Eth, payer.Polygon:
var client *ethclient.Client
Expand All @@ -154,12 +112,12 @@ func CreatePayer(ctx context.Context, log *zap.Logger, config PayerConfig, nodeA
owner,
spenderKey,
chainID,
gasTipCap,
&maxGas,
eth.PayerOptions{},
)
if err != nil {
return nil, errs.Wrap(err)
}

case payer.ZkSyncEra:
var paymasterAddress *common.Address
var paymasterPayload []byte
Expand All @@ -172,10 +130,9 @@ func CreatePayer(ctx context.Context, log *zap.Logger, config PayerConfig, nodeA
common.HexToAddress(config.ContractAddress),
nodeAddress,
spenderKey,
int(chainID.Int64()),
chainID,
paymasterAddress,
paymasterPayload,
maxFee)
paymasterPayload)
if err != nil {
return nil, errs.Wrap(err)
}
Expand Down
Loading
Loading