Skip to content

Commit

Permalink
add extra gas tip parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
tranvictor committed Apr 25, 2024
1 parent 87d0ff5 commit 36980bf
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 49 deletions.
15 changes: 2 additions & 13 deletions cmd/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ var txContractCmd = &cobra.Command{
config.Value,
config.GasLimit+config.ExtraGasLimit,
config.GasPrice+config.ExtraGasPrice,
config.TipGas,
config.TipGas+config.ExtraTipGas,
data,
config.Network().GetChainID(),
)
Expand Down Expand Up @@ -385,21 +385,10 @@ var readContractCmd = &cobra.Command{
func init() {
contractCmd.AddCommand(composeDataContractCmd)

txContractCmd.PersistentFlags().Float64VarP(&config.GasPrice, "gasprice", "p", 0, "Gas price in gwei. If default value is used, we will use https://ethgasstation.info/ to get fast gas price. The gas price to be used in the tx is gas price + extra gas price")
txContractCmd.PersistentFlags().Float64VarP(&config.TipGas, "tipgas", "s", 0, "tip in gwei, will be use in dynamic fee tx, default value get from node.")
txContractCmd.PersistentFlags().Float64VarP(&config.ExtraGasPrice, "extraprice", "P", 0, "Extra gas price in gwei. The gas price to be used in the tx is gas price + extra gas price")
txContractCmd.PersistentFlags().Uint64VarP(&config.GasLimit, "gas", "g", 0, "Base gas limit for the tx. If default value is used, we will use ethereum nodes to estimate the gas limit. The gas limit to be used in the tx is gas limit + extra gas limit")
txContractCmd.PersistentFlags().Uint64VarP(&config.ExtraGasLimit, "extragas", "G", 250000, "Extra gas limit for the tx. The gas limit to be used in the tx is gas limit + extra gas limit")
txContractCmd.PersistentFlags().Uint64VarP(&config.Nonce, "nonce", "n", 0, "Nonce of the from account. If default value is used, we will use the next available nonce of from account")
txContractCmd.PersistentFlags().StringVarP(&config.From, "from", "f", "", "Account to use to send the transaction. It can be ethereum address or a hint string to look it up in the list of account. See jarvis acc for all of the registered accounts")
AddCommonFlagsToTransactionalCmds(txContractCmd)

Check failure on line 388 in cmd/contract.go

View workflow job for this annotation

GitHub Actions / build

undefined: AddCommonFlagsToTransactionalCmds
txContractCmd.PersistentFlags().StringVarP(&config.PrefillStr, "prefills", "I", "", "Prefill params string. Each param is separated by | char. If the param is \"?\", user input will be prompted.")
txContractCmd.PersistentFlags().Uint64VarP(&config.MethodIndex, "method-index", "M", 0, "Index of the method in alphabeth sorted method list of the contract. Index counts from 1.")
txContractCmd.PersistentFlags().BoolVarP(&config.DontBroadcast, "dry", "d", false, "Will not broadcast the tx, only show signed tx.")
txContractCmd.PersistentFlags().BoolVarP(&config.DontWaitToBeMined, "no-wait", "F", false, "Will not wait the tx to be mined.")
txContractCmd.PersistentFlags().BoolVarP(&config.ForceERC20ABI, "erc20-abi", "e", false, "Use ERC20 ABI where possible.")
txContractCmd.PersistentFlags().BoolVarP(&config.RetryBroadcast, "retry-broadcast", "r", false, "Retry broadcasting as soon as possible.")
txContractCmd.PersistentFlags().BoolVarP(&config.ForceLegacy, "legacy-tx", "L", false, "Force using legacy transaction")
txContractCmd.PersistentFlags().StringVarP(&config.CustomABI, "abi", "c", "", "Custom abi. It can be either an address, a path to an abi file or an url to an abi. If it is an address, the abi of that address from etherscan will be queried. This param only takes effect if erc20-abi param is not true.")
txContractCmd.Flags().StringVarP(&config.RawValue, "amount", "v", "0", "Amount of eth to send. It is in eth value, not wei.")
txContractCmd.MarkFlagRequired("from")
contractCmd.AddCommand(txContractCmd)
Expand Down
25 changes: 4 additions & 21 deletions cmd/msig.go
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ var newMsigCmd = &cobra.Command{
config.Value,
config.GasLimit+config.ExtraGasLimit,
config.GasPrice+config.ExtraGasPrice,
config.TipGas,
config.TipGas+config.ExtraTipGas,
bytecode,
config.Network().GetChainID(),
)
Expand Down Expand Up @@ -592,7 +592,7 @@ var initMsigCmd = &cobra.Command{
config.Value,
config.GasLimit+config.ExtraGasLimit,
config.GasPrice+config.ExtraGasPrice,
config.TipGas,
config.TipGas+config.ExtraTipGas,
txdata,
config.Network().GetChainID(),
)
Expand Down Expand Up @@ -659,31 +659,14 @@ func init() {
executeMsigCmd,
}
for _, c := range writeCmds {
c.PersistentFlags().Float64VarP(&config.GasPrice, "gasprice", "p", 0, "Gas price in gwei. If default value is used, we will use https://ethgasstation.info/ to get fast gas price. The gas price to be used in the tx is gas price + extra gas price")
c.PersistentFlags().Float64VarP(&config.TipGas, "tipgas", "s", 0, "tip in gwei, will be use in dynamic fee tx, default value get from node.")
c.PersistentFlags().Float64VarP(&config.ExtraGasPrice, "extraprice", "P", 0, "Extra gas price in gwei. The gas price to be used in the tx is gas price + extra gas price")
c.PersistentFlags().Uint64VarP(&config.GasLimit, "gas", "g", 0, "Base gas limit for the tx. If default value is used, we will use ethereum nodes to estimate the gas limit. The gas limit to be used in the tx is gas limit + extra gas limit")
c.PersistentFlags().Uint64VarP(&config.ExtraGasLimit, "extragas", "G", 250000, "Extra gas limit for the tx. The gas limit to be used in the tx is gas limit + extra gas limit")
c.PersistentFlags().Uint64VarP(&config.Nonce, "nonce", "n", 0, "Nonce of the from account. If default value is used, we will use the next available nonce of from account")
c.PersistentFlags().StringVarP(&config.From, "from", "f", "", "Account to use to send the transaction. It can be ethereum address or a hint string to look it up in the list of account. See jarvis acc for all of the registered accounts")
AddCommonFlagsToTransactionalCmds(c)

Check failure on line 662 in cmd/msig.go

View workflow job for this annotation

GitHub Actions / build

undefined: AddCommonFlagsToTransactionalCmds
c.Flags().StringVarP(&config.RawValue, "amount", "v", "0", "Amount of eth to send. It is in native token value, not wei.")
c.PersistentFlags().BoolVarP(&config.ForceERC20ABI, "erc20-abi", "e", false, "Use ERC20 ABI where possible.")
c.PersistentFlags().StringVarP(&config.CustomABI, "abi", "c", "", "Custom abi. It can be either an address, a path to an abi file or an url to an abi. If it is an address, the abi of that address from etherscan will be queried. This param only takes effect if erc20-abi param is not true.")
c.PersistentFlags().BoolVarP(&config.DontWaitToBeMined, "no-wait", "F", false, "Will not wait the tx to be mined.")
c.PersistentFlags().BoolVarP(&config.DontBroadcast, "dry", "d", false, "Will not broadcast the tx, only show signed tx.")
c.PersistentFlags().BoolVarP(&config.RetryBroadcast, "retry-broadcast", "r", false, "Retry broadcasting as soon as possible.")
c.PersistentFlags().BoolVarP(&config.ForceLegacy, "legacy-tx", "L", false, "Force using legacy transaction")
}

newMsigCmd.PersistentFlags().Float64VarP(&config.GasPrice, "gasprice", "p", 0, "Gas price in gwei. If default value is used, we will use https://ethgasstation.info/ to get fast gas price. The gas price to be used in the tx is gas price + extra gas price")
newMsigCmd.PersistentFlags().Float64VarP(&config.ExtraGasPrice, "extraprice", "P", 0, "Extra gas price in gwei. The gas price to be used in the tx is gas price + extra gas price")
newMsigCmd.PersistentFlags().Uint64VarP(&config.GasLimit, "gas", "g", 0, "Base gas limit for the tx. If default value is used, we will use ethereum nodes to estimate the gas limit. The gas limit to be used in the tx is gas limit + extra gas limit")
newMsigCmd.PersistentFlags().Uint64VarP(&config.ExtraGasLimit, "extragas", "G", 250000, "Extra gas limit for the tx. The gas limit to be used in the tx is gas limit + extra gas limit")
newMsigCmd.PersistentFlags().Uint64VarP(&config.Nonce, "nonce", "n", 0, "Nonce of the from account. If default value is used, we will use the next available nonce of from account")
newMsigCmd.PersistentFlags().StringVarP(&config.From, "from", "f", "", "Account to use to send the transaction. It can be ethereum address or a hint string to look it up in the list of account. See jarvis acc for all of the registered accounts")
AddCommonFlagsToTransactionalCmds(newMsigCmd)

Check failure on line 668 in cmd/msig.go

View workflow job for this annotation

GitHub Actions / build

undefined: AddCommonFlagsToTransactionalCmds
newMsigCmd.PersistentFlags().StringVarP(&config.PrefillStr, "prefills", "I", "", "Prefill params string. Each param is separated by | char. If the param is \"?\", user input will be prompted.")
newMsigCmd.PersistentFlags().BoolVarP(&config.DontBroadcast, "dry", "d", false, "Will not broadcast the tx, only show signed tx.")
newMsigCmd.PersistentFlags().BoolVarP(&config.DontWaitToBeMined, "no-wait", "F", false, "Will not wait the tx to be mined.")
newMsigCmd.MarkFlagRequired("from")

batchApproveMsigCmd.PersistentFlags().StringVarP(&config.PrefillStr, "prefills", "I", "", "Prefill params string. Each param is separated by | char. If the param is \"?\", user input will be prompted.")
Expand Down
24 changes: 10 additions & 14 deletions cmd/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func handleMsigSend(
big.NewInt(0),
config.GasLimit+config.ExtraGasLimit,
config.GasPrice+config.ExtraGasPrice,
config.TipGas,
config.TipGas+config.ExtraTipGas,
txdata,
config.Network().GetChainID(),
)
Expand Down Expand Up @@ -129,7 +129,7 @@ func handleSend(
amountWei,
config.GasLimit+config.ExtraGasLimit,
config.GasPrice+config.ExtraGasPrice,
config.TipGas,
config.TipGas+config.ExtraTipGas,
[]byte{},
config.Network().GetChainID(),
)
Expand All @@ -151,7 +151,7 @@ func handleSend(
big.NewInt(0),
config.GasLimit+config.ExtraGasLimit,
config.GasPrice+config.ExtraGasPrice,
config.TipGas,
config.TipGas+config.ExtraTipGas,
data,
config.Network().GetChainID(),
)
Expand Down Expand Up @@ -410,6 +410,12 @@ The token and accounts can be specified either by memorable name or
exact addresses start with 0x.`,
TraverseChildren: true,
Run: func(cmd *cobra.Command, args []string) {
// if extra gas is set to default value, we force it to 0 to ensure sending ETH
// will leave no dust
if config.ExtraGasLimit == 250000 {
config.ExtraGasLimit = 0
}

// process from to get address
acc, err := accounts.GetAccount(config.From)
if err != nil {
Expand Down Expand Up @@ -592,17 +598,7 @@ exact addresses start with 0x.`,
},
}

sendCmd.PersistentFlags().Float64VarP(&config.GasPrice, "gasprice", "p", 0, "Gas price in gwei. If default value is used, we will use https://ethgasstation.info/ to get fast gas price. The gas price to be used in the tx is gas price + extra gas price")
sendCmd.PersistentFlags().Float64VarP(&config.TipGas, "tipgas", "s", 0, "tip in gwei, will be use in dynamic fee tx, default value get from node.")
sendCmd.PersistentFlags().Float64VarP(&config.ExtraGasPrice, "extraprice", "P", 0, "Extra gas price in gwei. The gas price to be used in the tx is gas price + extra gas price")
sendCmd.PersistentFlags().Uint64VarP(&config.GasLimit, "gas", "g", 0, "Base gas limit for the tx. If default value is used, we will use ethereum nodes to estimate the gas limit. The gas limit to be used in the tx is gas limit + extra gas limit")
// sendCmd.PersistentFlags().Uint64VarP(&ExtraGasLimit, "extragas", "G", 250000, "Extra gas limit for the tx. The gas limit to be used in the tx is gas limit + extra gas limit")
sendCmd.PersistentFlags().Uint64VarP(&config.Nonce, "nonce", "n", 0, "Nonce of the from account. If default value is used, we will use the next available nonce of from account")
sendCmd.PersistentFlags().StringVarP(&config.From, "from", "f", "", "Account to use to send the transaction. It can be ethereum address or a hint string to look it up in the list of account. See jarvis acc for all of the registered accounts")
sendCmd.PersistentFlags().BoolVarP(&config.DontBroadcast, "dry", "d", false, "Will not broadcast the tx, only show signed tx.")
sendCmd.PersistentFlags().BoolVarP(&config.DontWaitToBeMined, "no-wait", "F", false, "Will not wait the tx to be mined.")
sendCmd.PersistentFlags().BoolVarP(&config.RetryBroadcast, "retry-broadcast", "r", false, "Retry broadcasting as soon as possible.")
sendCmd.PersistentFlags().BoolVarP(&config.ForceLegacy, "legacy-tx", "L", false, "Force using legacy transaction")
AddCommonFlagsToTransactionalCmds(sendCmd)

Check failure on line 601 in cmd/send.go

View workflow job for this annotation

GitHub Actions / build

undefined: AddCommonFlagsToTransactionalCmds
sendCmd.Flags().StringVarP(&to, "to", "t", "", "Account to send eth to. It can be ethereum address or a hint string to look it up in the address database. See jarvis addr for all of the known addresses")
sendCmd.Flags().StringVarP(&value, "amount", "v", "0", "Amount of eth to send. It is in eth/token value, not wei/twei. If a float number is passed, it will be interpreted as ETH, otherwise, it must be in the form of `float|ALL address` or `float|ALL name`. In the later case, `name` will be used to look for the token address. Eg. 0.01, 0.01 knc, 0.01 0xdd974d5c2e2928dea5f71b9825b8b646686bd200, ALL KNC are valid values.")
sendCmd.MarkFlagRequired("to")
Expand Down
3 changes: 2 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ var NetworkString string

var (
GasPrice float64
TipGas float64
ExtraGasPrice float64
TipGas float64
ExtraTipGas float64
GasLimit uint64
ExtraGasLimit uint64
Nonce uint64
Expand Down

0 comments on commit 36980bf

Please sign in to comment.