Skip to content

Commit e93afab

Browse files
lukema95lumtiskingpinXD
authored
feat: Add Whitelist ERC20 Cli. (#1425)
* feat: add whitelist erc20 cli * chore: modify comment * docs: add cli docs * fix lint * update cli docs * remove ValidateBasic in cli * update cli docs * remove irrelevant changes * remove irrelevant changes * Update changelog.md * rename cli * update cli docs * update cli docs * rename cli func * Update x/crosschain/client/cli/cli_whitelist_erc20.go Co-authored-by: Tanmay <[email protected]> * generate cli docs * fix the integer overflow warning from cosmos-sec * update changelog * make generate * make generate * update changelog * fix generated file error * fix generated file error --------- Co-authored-by: Lucas Bertrand <[email protected]> Co-authored-by: Tanmay <[email protected]>
1 parent 1df84cf commit e93afab

File tree

6 files changed

+124
-2
lines changed

6 files changed

+124
-2
lines changed

changelog.md

+4
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@
5151
* Made adjustments to the docker-compose for launching mainnet full nodes to include examples of using the docker images build from the docker image build pipeline.
5252
* [1736](https://github.com/zeta-chain/node/pull/1736) - chore: add Ethermint endpoints to OpenAPI
5353

54+
### Features
55+
56+
* [1425](https://github.com/zeta-chain/node/pull/1425) add `whitelist-erc20` command
57+
5458
### Chores
5559

5660
* [1729](https://github.com/zeta-chain/node/pull/1729) - add issue templates

docs/cli/zetacored/zetacored_tx_crosschain.md

+1
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,5 @@ zetacored tx crosschain [flags]
3737
* [zetacored tx crosschain refund-aborted](zetacored_tx_crosschain_refund-aborted.md) - Refund an aborted tx , the refund address is optional, if not provided, the refund will be sent to the sender/tx origin of the cctx.
3838
* [zetacored tx crosschain remove-from-out-tx-tracker](zetacored_tx_crosschain_remove-from-out-tx-tracker.md) - Remove a out-tx-tracker
3939
* [zetacored tx crosschain update-tss-address](zetacored_tx_crosschain_update-tss-address.md) - Create a new TSSVoter
40+
* [zetacored tx crosschain whitelist-erc20](zetacored_tx_crosschain_whitelist-erc20.md) - Add a new erc20 token to whitelist
4041

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# tx crosschain whitelist-erc20
2+
3+
Add a new erc20 token to whitelist
4+
5+
```
6+
zetacored tx crosschain whitelist-erc20 [erc20Address] [chainID] [name] [symbol] [decimals] [gasLimit] [flags]
7+
```
8+
9+
### Options
10+
11+
```
12+
-a, --account-number uint The account number of the signing account (offline mode only)
13+
--aux Generate aux signer data instead of sending a tx
14+
-b, --broadcast-mode string Transaction broadcasting mode (sync|async|block)
15+
--dry-run ignore the --gas flag and perform a simulation of a transaction, but don't broadcast it (when enabled, the local Keybase is not accessible)
16+
--fee-granter string Fee granter grants fees for the transaction
17+
--fee-payer string Fee payer pays fees for the transaction instead of deducting from the signer
18+
--fees string Fees to pay along with transaction; eg: 10uatom
19+
--from string Name or address of private key with which to sign
20+
--gas string gas limit to set per-transaction; set to "auto" to calculate sufficient gas automatically. Note: "auto" option doesn't always report accurate results. Set a valid coin value to adjust the result. Can be used instead of "fees". (default 200000)
21+
--gas-adjustment float adjustment factor to be multiplied against the estimate returned by the tx simulation; if the gas limit is set manually this flag is ignored (default 1)
22+
--gas-prices string Gas prices in decimal format to determine the transaction fee (e.g. 0.1uatom)
23+
--generate-only Build an unsigned transaction and write it to STDOUT (when enabled, the local Keybase only accessed when providing a key name)
24+
-h, --help help for whitelist-erc20
25+
--keyring-backend string Select keyring's backend (os|file|kwallet|pass|test|memory)
26+
--keyring-dir string The client Keyring directory; if omitted, the default 'home' directory will be used
27+
--ledger Use a connected Ledger device
28+
--node string [host]:[port] to tendermint rpc interface for this chain
29+
--note string Note to add a description to the transaction (previously --memo)
30+
--offline Offline mode (does not allow any online functionality)
31+
-o, --output string Output format (text|json)
32+
-s, --sequence uint The sequence number of the signing account (offline mode only)
33+
--sign-mode string Choose sign mode (direct|amino-json|direct-aux), this is an advanced feature
34+
--timeout-height uint Set a block timeout height to prevent the tx from being committed past a certain height
35+
--tip string Tip is the amount that is going to be transferred to the fee payer on the target chain. This flag is only valid when used with --aux, and is ignored if the target chain didn't enable the TipDecorator
36+
-y, --yes Skip tx broadcasting prompt confirmation
37+
```
38+
39+
### Options inherited from parent commands
40+
41+
```
42+
--chain-id string The network chain ID
43+
--home string directory for config and data
44+
--log_format string The logging format (json|plain)
45+
--log_level string The logging level (trace|debug|info|warn|error|fatal|panic)
46+
--trace print out full stack trace on errors
47+
```
48+
49+
### SEE ALSO
50+
51+
* [zetacored tx crosschain](zetacored_tx_crosschain.md) - crosschain transactions subcommands
52+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package cli
2+
3+
import (
4+
"fmt"
5+
"strconv"
6+
7+
"github.com/cosmos/cosmos-sdk/client"
8+
"github.com/cosmos/cosmos-sdk/client/flags"
9+
"github.com/cosmos/cosmos-sdk/client/tx"
10+
"github.com/spf13/cobra"
11+
"github.com/zeta-chain/zetacore/x/crosschain/types"
12+
)
13+
14+
func CmdWhitelistERC20() *cobra.Command {
15+
cmd := &cobra.Command{
16+
Use: "whitelist-erc20 [erc20Address] [chainID] [name] [symbol] [decimals] [gasLimit]",
17+
Short: "Add a new erc20 token to whitelist",
18+
Args: cobra.ExactArgs(6),
19+
RunE: func(cmd *cobra.Command, args []string) error {
20+
clientCtx, err := client.GetClientTxContext(cmd)
21+
if err != nil {
22+
return err
23+
}
24+
25+
erc20Address := args[0]
26+
chainID, err := strconv.ParseInt(args[1], 10, 64)
27+
if err != nil {
28+
return err
29+
}
30+
31+
name := args[2]
32+
symbol := args[3]
33+
decimals, err := strconv.ParseUint(args[4], 10, 32)
34+
if err != nil {
35+
return err
36+
}
37+
if decimals > 128 {
38+
return fmt.Errorf("decimals must be less than 128")
39+
}
40+
41+
gasLimit, err := strconv.ParseInt(args[5], 10, 64)
42+
if err != nil {
43+
return err
44+
}
45+
46+
msg := types.NewMsgWhitelistERC20(
47+
clientCtx.GetFromAddress().String(),
48+
erc20Address,
49+
chainID,
50+
name,
51+
symbol,
52+
// #nosec G701 always in range
53+
uint32(decimals),
54+
gasLimit,
55+
)
56+
57+
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
58+
},
59+
}
60+
61+
flags.AddTxFlagsToCmd(cmd)
62+
63+
return cmd
64+
}

x/crosschain/client/cli/tx.go

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ func GetTxCmd() *cobra.Command {
3030
CmdUpdateTss(),
3131
CmdMigrateTssFunds(),
3232
CmdAddToInTxTracker(),
33+
CmdWhitelistERC20(),
3334
CmdAbortStuckCCTX(),
3435
CmdRefundAborted(),
3536
)

x/crosschain/types/tx.pb.go

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)