-
Notifications
You must be signed in to change notification settings - Fork 815
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add gov proposal types for registering pointers (#1496)
- Loading branch information
Showing
13 changed files
with
1,676 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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\""]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
} |
Oops, something went wrong.