Skip to content

Commit

Permalink
Add advanced gas flags, --get-premium, --gas-limit, --gas-fee-cap
Browse files Browse the repository at this point in the history
Also rename --gas-multiply to --gas-premium-multiply
  • Loading branch information
jimpick committed Jan 25, 2025
1 parent a9e5148 commit c367ae3
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 7 deletions.
5 changes: 4 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,11 @@ func Execute() {
func init() {
cobra.OnInitialize(initConfig)
rootCmd.PersistentFlags().StringVar(&cfgDir, "config-dir", "", "config directory")
rootCmd.PersistentFlags().Float64("gas-multiply", 1.0, "Multiply the default gas premium by this amount")
rootCmd.PersistentFlags().Float64("gas-premium-multiply", 1.0, "Multiply the default gas premium by this amount")
rootCmd.PersistentFlags().Uint64("nonce", 0, "Specify nonce (for replacing transactions)")
rootCmd.PersistentFlags().Int64("gas-premium", -1, "(advanced) Override gas premium / priority fee per gas")
rootCmd.PersistentFlags().Uint64("gas-limit", 0, "(advanced) Override gas limit from estimate")
rootCmd.PersistentFlags().Uint64("gas-fee-cap", 0, "(advanced) Override fee cap / max fee per gas")
}

// initConfig reads in config file and ENV variables if set.
Expand Down
34 changes: 30 additions & 4 deletions cmd/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ func commonGenericAccountSetup(cmd *cobra.Command, from string) (auth *bind.Tran

func setGasTipCapAndNonce(cmd *cobra.Command, auth *bind.TransactOpts) {
ctx := cmd.Context()
gasMultiply, err := cmd.Flags().GetFloat64("gas-multiply")
gasMultiply, err := cmd.Flags().GetFloat64("gas-premium-multiply")
if err != nil {
log.Fatal(err)
}
Expand All @@ -379,20 +379,46 @@ func setGasTipCapAndNonce(cmd *cobra.Command, auth *bind.TransactOpts) {
log.Fatal(err)
}

gasPremium, err := cmd.Flags().GetInt64("gas-premium")
if err != nil {
log.Fatal(err)
}

ethClient, err := PoolsSDK.Extern().ConnectEthClient()
if err != nil {
log.Fatal(err)
}
defer ethClient.Close()

tipCap, err := ethClient.SuggestGasTipCap(ctx)
if err != nil {
logFatal(err)
var tipCap *big.Int
if gasPremium >= 0 {
tipCap = big.NewInt(gasPremium)
} else {
tipCap, err = ethClient.SuggestGasTipCap(ctx)
if err != nil {
logFatal(err)
}
}
tipCapFloat, _ := tipCap.Float64()
scaledTipCap := tipCapFloat * gasMultiply
auth.GasTipCap = big.NewInt(int64(scaledTipCap))

gasLimit, err := cmd.Flags().GetUint64("gas-limit")
if err != nil {
log.Fatal(err)
}
if gasLimit > 0 {
auth.GasLimit = gasLimit
}

gasFeeCap, err := cmd.Flags().GetUint64("gas-fee-cap")
if err != nil {
log.Fatal(err)
}
if gasFeeCap > 0 {
auth.GasFeeCap = big.NewInt(int64(gasFeeCap))
}

if nonce > 0 {
auth.Nonce = big.NewInt(int64(nonce))
}
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ go 1.22

toolchain go1.22.0

replace github.com/glifio/go-pools => ../go-pools

require (
github.com/AlecAivazis/survey/v2 v2.3.7
github.com/briandowns/spinner v1.23.0
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,6 @@ github.com/gbrlsnchs/jwt/v3 v3.0.1 h1:lbUmgAKpxnClrKloyIwpxm4OuWeDl5wLk52G91ODPw
github.com/gbrlsnchs/jwt/v3 v3.0.1/go.mod h1:AncDcjXz18xetI3A6STfXq2w+LuTx8pQ8bGEwRN8zVM=
github.com/getsentry/sentry-go v0.18.0 h1:MtBW5H9QgdcJabtZcuJG80BMOwaBpkRDZkxRkNC1sN0=
github.com/getsentry/sentry-go v0.18.0/go.mod h1:Kgon4Mby+FJ7ZWHFUAZgVaIa8sxHtnRJRLTXZr51aKQ=
github.com/glifio/go-pools v1.1.3 h1:o8lop9cckaxZ3P8UeWlk/GmlJLWhcQkiDIX9aDM82cA=
github.com/glifio/go-pools v1.1.3/go.mod h1:G+JltF4457QvLCk8cIMLTHl6L7HgB515Bv8IRgFJJx8=
github.com/glifio/go-wallet-utils v0.0.0-20230719050429-ff6c4bc75533 h1:teuqQtVb7YMyqIOg+xUNO21qZAnm8ibhpKy4lIUBpag=
github.com/glifio/go-wallet-utils v0.0.0-20230719050429-ff6c4bc75533/go.mod h1:zJ9ksxDWIsuS80RtpjaM6swuKZ7OYdJH56I00EZRxD4=
github.com/go-check/check v0.0.0-20180628173108-788fd7840127/go.mod h1:9ES+weclKsC9YodN5RgxqK/VD9HM9JsCSh7rNhMZE98=
Expand Down

0 comments on commit c367ae3

Please # to comment.