Skip to content

Commit

Permalink
Add gov proposal types for registering pointers (#1496)
Browse files Browse the repository at this point in the history
  • Loading branch information
codchen authored Apr 1, 2024
1 parent eb2080b commit 4c225f4
Show file tree
Hide file tree
Showing 13 changed files with 1,676 additions and 2 deletions.
3 changes: 2 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,8 @@ func New(
AddRoute(dexmoduletypes.RouterKey, dexmodule.NewProposalHandler(app.DexKeeper)).
AddRoute(minttypes.RouterKey, mint.NewProposalHandler(app.MintKeeper)).
AddRoute(tokenfactorytypes.RouterKey, tokenfactorymodule.NewProposalHandler(app.TokenFactoryKeeper)).
AddRoute(acltypes.ModuleName, aclmodule.NewProposalHandler(app.AccessControlKeeper))
AddRoute(acltypes.ModuleName, aclmodule.NewProposalHandler(app.AccessControlKeeper)).
AddRoute(evmtypes.RouterKey, evm.NewProposalHandler(app.EvmKeeper))
if len(enabledProposals) != 0 {
govRouter.AddRoute(wasm.RouterKey, wasm.NewWasmProposalHandler(app.WasmKeeper, enabledProposals))
}
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ require (
github.com/fzipp/gocyclo v0.5.1 // indirect
github.com/gballet/go-libpcsclite v0.0.0-20190607065134-2772fd86a8ff // indirect
github.com/gballet/go-verkle v0.1.1-0.20231031103413-a67434b50f46 // indirect
github.com/ghodss/yaml v1.0.0 // indirect
github.com/go-critic/go-critic v0.6.3 // indirect
github.com/go-kit/kit v0.12.0 // indirect
github.com/go-kit/log v0.2.1 // indirect
Expand Down Expand Up @@ -172,6 +173,7 @@ require (
github.com/gostaticanalysis/nilerr v0.1.1 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 // indirect
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.1 // indirect
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c // indirect
github.com/hashicorp/errwrap v1.0.0 // indirect
github.com/hashicorp/go-bexpr v0.1.10 // indirect
Expand Down
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,7 @@ github.com/gballet/go-verkle v0.1.1-0.20231031103413-a67434b50f46 h1:BAIP2Gihuqh
github.com/gballet/go-verkle v0.1.1-0.20231031103413-a67434b50f46/go.mod h1:QNpY22eby74jVhqH4WhDLDwxc/vqsern6pW+u2kbkpc=
github.com/getkin/kin-openapi v0.53.0/go.mod h1:7Yn5whZr5kJi6t+kShccXS8ae1APpYTW6yheSwk8Yi4=
github.com/ghemawat/stream v0.0.0-20171120220530-696b145b53b9/go.mod h1:106OIgooyS7OzLDOpUGgm9fA3bQENb/cFSyyBmMoJDs=
github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/gin-contrib/sse v0.0.0-20190301062529-5545eab6dad3/go.mod h1:VJ0WA2NBN22VlZ2dKZQPAPnyWw5XTlK1KymzLKsr59s=
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
Expand Down Expand Up @@ -765,6 +766,8 @@ github.com/grpc-ecosystem/grpc-gateway v1.9.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t
github.com/grpc-ecosystem/grpc-gateway v1.12.1/go.mod h1:8XEsbTttt/W+VvjtQhLACqCisSPWTxCZ7sBRjU6iH9c=
github.com/grpc-ecosystem/grpc-gateway v1.16.0 h1:gmcG1KaJ57LophUzW0Hy8NmPhnMZb4M0+kPpLofRdBo=
github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.1 h1:/c3QmbOGMGTOumP2iT/rCwB7b0QDGLKzqOmktBjT+Is=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.1/go.mod h1:5SN9VR2LTsRFsrEC6FHgRbTWrTHu6tqPeKxEQv15giM=
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c h1:6rhixN/i8ZofjG1Y75iExal34USq5p+wiN1tpie8IrU=
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c/go.mod h1:NMPJylDgVpX0MLRlPy15sqSwOFv/U1GZ2m21JhFfek0=
github.com/guptarohit/asciigraph v0.5.5/go.mod h1:dYl5wwK4gNsnFf9Zp+l06rFiDZ5YtXM6x7SRWZ3KGag=
Expand Down
42 changes: 42 additions & 0 deletions proto/evm/gov.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
syntax = "proto3";
package seiprotocol.seichain.evm;

import "gogoproto/gogo.proto";

option go_package = "github.com/sei-protocol/sei-chain/x/evm/types";

message AddERCNativePointerProposal {
option (gogoproto.equal) = false;
option (gogoproto.goproto_getters) = false;
option (gogoproto.goproto_stringer) = false;

string title = 1 [ (gogoproto.moretags) = "yaml:\"title\"" ];
string description = 2 [ (gogoproto.moretags) = "yaml:\"description\"" ];
string token = 3 [(gogoproto.moretags) = "yaml:\"token\""];
string pointer = 4 [(gogoproto.moretags) = "yaml:\"pointer\""];
uint32 version = 5 [(gogoproto.moretags) = "yaml:\"version\""];
}

message AddERCCW20PointerProposal {
option (gogoproto.equal) = false;
option (gogoproto.goproto_getters) = false;
option (gogoproto.goproto_stringer) = false;

string title = 1 [ (gogoproto.moretags) = "yaml:\"title\"" ];
string description = 2 [ (gogoproto.moretags) = "yaml:\"description\"" ];
string pointee = 3 [(gogoproto.moretags) = "yaml:\"pointee\""];
string pointer = 4 [(gogoproto.moretags) = "yaml:\"pointer\""];
uint32 version = 5 [(gogoproto.moretags) = "yaml:\"version\""];
}

message AddERCCW721PointerProposal {
option (gogoproto.equal) = false;
option (gogoproto.goproto_getters) = false;
option (gogoproto.goproto_stringer) = false;

string title = 1 [ (gogoproto.moretags) = "yaml:\"title\"" ];
string description = 2 [ (gogoproto.moretags) = "yaml:\"description\"" ];
string pointee = 3 [(gogoproto.moretags) = "yaml:\"pointee\""];
string pointer = 4 [(gogoproto.moretags) = "yaml:\"pointer\""];
uint32 version = 5 [(gogoproto.moretags) = "yaml:\"version\""];
}
175 changes: 175 additions & 0 deletions x/evm/client/cli/gov_tx.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
package cli

import (
"strconv"
"strings"

"github.com/sei-protocol/sei-chain/x/evm/types"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/tx"
sdk "github.com/cosmos/cosmos-sdk/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"

"github.com/spf13/cobra"
)

func NewAddERCNativePointerProposalTxCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "add-erc-native-pointer title description token version deposit [pointer address]",
Args: cobra.RangeArgs(5, 6),
Short: "Submit an add ERC-native pointer proposal",
Long: strings.TrimSpace(`
Submit a proposal to register an ERC pointer contract address for a native token.
Not specifying the pointer address means a proposal that deletes the existing pointer.
`),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}

version, err := strconv.ParseUint(args[3], 10, 16)
if err != nil {
return err
}
deposit, err := sdk.ParseCoinsNormalized(args[4])
if err != nil {
return err
}
var pointer string
if len(args) == 6 {
pointer = args[5]
}

// Convert proposal to RegisterPairsProposal Type
from := clientCtx.GetFromAddress()

content := types.AddERCNativePointerProposal{
Title: args[0],
Description: args[1],
Token: args[2],
Version: uint32(version),
Pointer: pointer,
}

msg, err := govtypes.NewMsgSubmitProposal(&content, deposit, from)
if err != nil {
return err
}

return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}

flags.AddTxFlagsToCmd(cmd)

return cmd
}

func NewAddERCCW20PointerProposalTxCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "add-erc-cw20-pointer title description cw20address version deposit [pointer address]",
Args: cobra.RangeArgs(5, 6),
Short: "Submit an add ERC-CW20 pointer proposal",
Long: strings.TrimSpace(`
Submit a proposal to register an ERC pointer contract address for a CW20 token.
Not specifying the pointer address means a proposal that deletes the existing pointer.
`),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}

version, err := strconv.ParseUint(args[3], 10, 16)
if err != nil {
return err
}
deposit, err := sdk.ParseCoinsNormalized(args[4])
if err != nil {
return err
}
var pointer string
if len(args) == 6 {
pointer = args[5]
}

// Convert proposal to RegisterPairsProposal Type
from := clientCtx.GetFromAddress()

content := types.AddERCCW20PointerProposal{
Title: args[0],
Description: args[1],
Pointee: args[2],
Version: uint32(version),
Pointer: pointer,
}

msg, err := govtypes.NewMsgSubmitProposal(&content, deposit, from)
if err != nil {
return err
}

return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}

flags.AddTxFlagsToCmd(cmd)

return cmd
}

func NewAddERCCW721PointerProposalTxCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "add-erc-cw721-pointer title description cw721address version deposit [pointer address]",
Args: cobra.RangeArgs(5, 6),
Short: "Submit an add ERC-CW721 pointer proposal",
Long: strings.TrimSpace(`
Submit a proposal to register an ERC pointer contract address for a CW721 token.
Not specifying the pointer address means a proposal that deletes the existing pointer.
`),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}

version, err := strconv.ParseUint(args[3], 10, 16)
if err != nil {
return err
}
deposit, err := sdk.ParseCoinsNormalized(args[4])
if err != nil {
return err
}
var pointer string
if len(args) == 6 {
pointer = args[5]
}

// Convert proposal to RegisterPairsProposal Type
from := clientCtx.GetFromAddress()

content := types.AddERCCW721PointerProposal{
Title: args[0],
Description: args[1],
Pointee: args[2],
Version: uint32(version),
Pointer: pointer,
}

msg, err := govtypes.NewMsgSubmitProposal(&content, deposit, from)
if err != nil {
return err
}

return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}

flags.AddTxFlagsToCmd(cmd)

return cmd
}
3 changes: 3 additions & 0 deletions x/evm/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ func GetTxCmd() *cobra.Command {
cmd.AddCommand(CmdERC20Send())
cmd.AddCommand(CmdDelegate())
cmd.AddCommand(NativeSendTxCmd())
cmd.AddCommand(NewAddERCNativePointerProposalTxCmd())
cmd.AddCommand(NewAddERCCW20PointerProposalTxCmd())
cmd.AddCommand(NewAddERCCW721PointerProposalTxCmd())

return cmd
}
Expand Down
32 changes: 32 additions & 0 deletions x/evm/gov.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package evm

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/ethereum/go-ethereum/common"
"github.com/sei-protocol/sei-chain/x/evm/keeper"
"github.com/sei-protocol/sei-chain/x/evm/types"
)

func HandleAddERCNativePointerProposal(ctx sdk.Context, k *keeper.Keeper, p *types.AddERCNativePointerProposal) error {
if p.Pointer == "" {
k.DeleteERC20NativePointer(ctx, p.Token, uint16(p.Version))
return nil
}
return k.SetERC20NativePointerWithVersion(ctx, p.Token, common.HexToAddress(p.Pointer), uint16(p.Version))
}

func HandleAddERCCW20PointerProposal(ctx sdk.Context, k *keeper.Keeper, p *types.AddERCCW20PointerProposal) error {
if p.Pointer == "" {
k.DeleteERC20CW20Pointer(ctx, p.Pointee, uint16(p.Version))
return nil
}
return k.SetERC20CW20PointerWithVersion(ctx, p.Pointee, common.HexToAddress(p.Pointer), uint16(p.Version))
}

func HandleAddERCCW721PointerProposal(ctx sdk.Context, k *keeper.Keeper, p *types.AddERCCW721PointerProposal) error {
if p.Pointer == "" {
k.DeleteERC721CW721Pointer(ctx, p.Pointee, uint16(p.Version))
return nil
}
return k.SetERC721CW721PointerWithVersion(ctx, p.Pointee, common.HexToAddress(p.Pointer), uint16(p.Version))
}
Loading

0 comments on commit 4c225f4

Please sign in to comment.