From 083588f1da52971cef41a70ca37ddc5060615b65 Mon Sep 17 00:00:00 2001 From: codchen Date: Wed, 5 Jun 2024 16:14:26 +0800 Subject: [PATCH] Add gov proposal v2 for native pointer (#1711) * Add gov proposal v2 for native pointer * disable upgrade test * test --- contracts/test/CW20toERC20PointerTest.js | 6 +- contracts/test/ERC20toCW20PointerTest.js | 6 +- go.mod | 2 +- go.sum | 4 +- proto/evm/gov.proto | 13 + x/evm/client/cli/gov_tx.go | 235 +------------ x/evm/client/cli/tx.go | 4 - x/evm/gov.go | 149 ++++---- x/evm/gov_test.go | 221 ++---------- x/evm/handler.go | 2 + x/evm/types/codec.go | 1 + x/evm/types/gov.go | 44 ++- x/evm/types/gov.pb.go | 422 +++++++++++++++++++++-- x/evm/types/gov_test.go | 29 ++ 14 files changed, 623 insertions(+), 515 deletions(-) create mode 100644 x/evm/types/gov_test.go diff --git a/contracts/test/CW20toERC20PointerTest.js b/contracts/test/CW20toERC20PointerTest.js index d63875538..4d8154406 100644 --- a/contracts/test/CW20toERC20PointerTest.js +++ b/contracts/test/CW20toERC20PointerTest.js @@ -169,7 +169,11 @@ describe("CW20 to ERC20 Pointer", function () { 1: 1000000000000 }); - describe("Pointer Upgrade", function () { + // Pointer version is going to be coupled with seid version going forward (as in, + // given a seid version, it's impossible to have multiple versions of pointer). + // We need to recreate the equivalent of the following test once we have a framework + // for simulating chain-level upgrade. + describe.skip("Pointer Upgrade", function () { let newPointer; before(async function () { diff --git a/contracts/test/ERC20toCW20PointerTest.js b/contracts/test/ERC20toCW20PointerTest.js index f8cc4ed66..f2bf02a1b 100644 --- a/contracts/test/ERC20toCW20PointerTest.js +++ b/contracts/test/ERC20toCW20PointerTest.js @@ -244,7 +244,11 @@ describe("ERC20 to CW20 Pointer", function () { account1: 3000000 }); - describe("Pointer Upgrade", function () { + // Pointer version is going to be coupled with seid version going forward (as in, + // given a seid version, it's impossible to have multiple versions of pointer). + // We need to recreate the equivalent of the following test once we have a framework + // for simulating chain-level upgrade. + describe.skip("Pointer Upgrade", function () { let newPointer; before(async function () { diff --git a/go.mod b/go.mod index 03bc4393e..2e9537a78 100644 --- a/go.mod +++ b/go.mod @@ -349,7 +349,7 @@ replace ( github.com/cosmos/cosmos-sdk => github.com/sei-protocol/sei-cosmos v0.3.16 github.com/cosmos/iavl => github.com/sei-protocol/sei-iavl v0.1.9 github.com/cosmos/ibc-go/v3 => github.com/sei-protocol/sei-ibc-go/v3 v3.3.0 - github.com/ethereum/go-ethereum => github.com/sei-protocol/go-ethereum v1.13.5-sei-17 + github.com/ethereum/go-ethereum => github.com/sei-protocol/go-ethereum v1.13.5-sei-20 github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1 github.com/sei-protocol/sei-db => github.com/sei-protocol/sei-db v0.0.38 // Latest goleveldb is broken, we have to stick to this version diff --git a/go.sum b/go.sum index 8216de481..6c6744c00 100644 --- a/go.sum +++ b/go.sum @@ -1343,8 +1343,8 @@ github.com/seccomp/libseccomp-golang v0.9.2-0.20220502022130-f33da4d89646/go.mod github.com/securego/gosec/v2 v2.11.0 h1:+PDkpzR41OI2jrw1q6AdXZCbsNGNGT7pQjal0H0cArI= github.com/securego/gosec/v2 v2.11.0/go.mod h1:SX8bptShuG8reGC0XS09+a4H2BoWSJi+fscA+Pulbpo= github.com/segmentio/fasthash v1.0.3/go.mod h1:waKX8l2N8yckOgmSsXJi7x1ZfdKZ4x7KRMzBtS3oedY= -github.com/sei-protocol/go-ethereum v1.13.5-sei-17 h1:NQcNuL/nmLCzVJFj6Za4ZrNj1ODTmNKDH6ELrJIEpkY= -github.com/sei-protocol/go-ethereum v1.13.5-sei-17/go.mod h1:kcRZmuzRn1lVejiFNTz4l4W7imnpq1bDAnuKS/RyhbQ= +github.com/sei-protocol/go-ethereum v1.13.5-sei-20 h1:EA/+30FdFbwAvbkNfkFh1FvjTN1tkZxrFxwzEJ948C0= +github.com/sei-protocol/go-ethereum v1.13.5-sei-20/go.mod h1:kcRZmuzRn1lVejiFNTz4l4W7imnpq1bDAnuKS/RyhbQ= github.com/sei-protocol/goutils v0.0.2 h1:Bfa7Sv+4CVLNM20QcpvGb81B8C5HkQC/kW1CQpIbXDA= github.com/sei-protocol/goutils v0.0.2/go.mod h1:iYE2DuJfEnM+APPehr2gOUXfuLuPsVxorcDO+Tzq9q8= github.com/sei-protocol/sei-cosmos v0.3.16 h1:NVTpiSVExPeETJSLbARB5g3xkOG++/bgSvVtxUZHDNo= diff --git a/proto/evm/gov.proto b/proto/evm/gov.proto index 55ec172d4..b2cbef277 100644 --- a/proto/evm/gov.proto +++ b/proto/evm/gov.proto @@ -64,3 +64,16 @@ message AddCWERC721PointerProposal { string pointer = 4 [(gogoproto.moretags) = "yaml:\"pointer\""]; uint32 version = 5 [(gogoproto.moretags) = "yaml:\"version\""]; } + +message AddERCNativePointerProposalV2 { + 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 name = 4 [(gogoproto.moretags) = "yaml:\"name\""]; + string symbol = 5 [(gogoproto.moretags) = "yaml:\"symbol\""]; + uint32 decimals = 6 [(gogoproto.moretags) = "yaml:\"decimals\""]; +} \ No newline at end of file diff --git a/x/evm/client/cli/gov_tx.go b/x/evm/client/cli/gov_tx.go index efc771b6d..2a7c01551 100644 --- a/x/evm/client/cli/gov_tx.go +++ b/x/evm/client/cli/gov_tx.go @@ -17,12 +17,12 @@ import ( func NewAddERCNativePointerProposalTxCmd() *cobra.Command { cmd := &cobra.Command{ - Use: "add-erc-native-pointer title description token version deposit [pointer address]", - Args: cobra.RangeArgs(5, 6), + Use: "add-erc-native-pointer title description token name symbol decimals deposit", + Args: cobra.ExactArgs(7), 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. + Submit a proposal to register an ERC pointer contract for a native token with + provided metadata. `), RunE: func(cmd *cobra.Command, args []string) error { clientCtx, err := client.GetClientTxContext(cmd) @@ -30,240 +30,25 @@ func NewAddERCNativePointerProposalTxCmd() *cobra.Command { return err } - version, err := strconv.ParseUint(args[3], 10, 16) + decimals, err := strconv.ParseUint(args[5], 10, 8) if err != nil { return err } - deposit, err := sdk.ParseCoinsNormalized(args[4]) + deposit, err := sdk.ParseCoinsNormalized(args[6]) 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{ + content := types.AddERCNativePointerProposalV2{ 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 -} - -func NewAddCWERC20PointerProposalTxCmd() *cobra.Command { - cmd := &cobra.Command{ - Use: "add-cw-erc20-pointer title description erc20address version deposit [pointer address]", - Args: cobra.RangeArgs(5, 6), - Short: "Submit an add CW-ERC20 pointer proposal", - Long: strings.TrimSpace(` - Submit a proposal to register an CW pointer contract address for a ERC20 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.AddCWERC20PointerProposal{ - 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 NewAddCWERC721PointerProposalTxCmd() *cobra.Command { - cmd := &cobra.Command{ - Use: "add-cw-erc721-pointer title description erc721address version deposit [pointer address]", - Args: cobra.RangeArgs(5, 6), - Short: "Submit an add CW-ERC721 pointer proposal", - Long: strings.TrimSpace(` - Submit a proposal to register an CW pointer contract address for a ERC721 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.AddCWERC721PointerProposal{ - Title: args[0], - Description: args[1], - Pointee: args[2], - Version: uint32(version), - Pointer: pointer, + Name: args[3], + Symbol: args[4], + Decimals: uint32(decimals), } msg, err := govtypes.NewMsgSubmitProposal(&content, deposit, from) diff --git a/x/evm/client/cli/tx.go b/x/evm/client/cli/tx.go index 20c8ba612..60cea369a 100644 --- a/x/evm/client/cli/tx.go +++ b/x/evm/client/cli/tx.go @@ -66,10 +66,6 @@ func GetTxCmd() *cobra.Command { cmd.AddCommand(RegisterCwPointerCmd()) cmd.AddCommand(RegisterEvmPointerCmd()) cmd.AddCommand(NewAddERCNativePointerProposalTxCmd()) - cmd.AddCommand(NewAddERCCW20PointerProposalTxCmd()) - cmd.AddCommand(NewAddERCCW721PointerProposalTxCmd()) - cmd.AddCommand(NewAddCWERC20PointerProposalTxCmd()) - cmd.AddCommand(NewAddCWERC721PointerProposalTxCmd()) cmd.AddCommand(AssociateContractAddressCmd()) cmd.AddCommand(NativeAssociateCmd()) diff --git a/x/evm/gov.go b/x/evm/gov.go index 546dba76d..508cc740d 100644 --- a/x/evm/gov.go +++ b/x/evm/gov.go @@ -1,90 +1,111 @@ package evm import ( + "errors" "fmt" + "math" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/ethereum/go-ethereum/common" - "github.com/sei-protocol/sei-chain/x/evm/artifacts/cw20" - "github.com/sei-protocol/sei-chain/x/evm/artifacts/cw721" - "github.com/sei-protocol/sei-chain/x/evm/artifacts/erc20" - "github.com/sei-protocol/sei-chain/x/evm/artifacts/erc721" + "github.com/ethereum/go-ethereum/core" + "github.com/ethereum/go-ethereum/core/vm" + "github.com/ethereum/go-ethereum/crypto" + "github.com/sei-protocol/sei-chain/utils" "github.com/sei-protocol/sei-chain/x/evm/artifacts/native" "github.com/sei-protocol/sei-chain/x/evm/keeper" + "github.com/sei-protocol/sei-chain/x/evm/state" "github.com/sei-protocol/sei-chain/x/evm/types" ) -func HandleAddERCNativePointerProposal(ctx sdk.Context, k *keeper.Keeper, p *types.AddERCNativePointerProposal) error { - ctx.EventManager().EmitEvent(sdk.NewEvent( - types.EventTypePointerRegistered, sdk.NewAttribute(types.AttributeKeyPointerType, "native"), - sdk.NewAttribute(types.AttributeKeyPointerAddress, p.Pointer), sdk.NewAttribute(types.AttributeKeyPointee, p.Token), - sdk.NewAttribute(types.AttributeKeyPointerVersion, fmt.Sprintf("%d", p.Version)))) - if p.Pointer == "" { - k.DeleteERC20NativePointer(ctx, p.Token, uint16(p.Version)) - return nil +func HandleAddERCNativePointerProposalV2(ctx sdk.Context, k *keeper.Keeper, p *types.AddERCNativePointerProposalV2) error { + decimals := uint8(math.MaxUint8) + if p.Decimals <= uint32(decimals) { + // should always be the case given validation + decimals = uint8(p.Decimals) + } + constructorArguments := []interface{}{ + p.Token, p.Name, p.Symbol, decimals, + } + packedArgs, err := native.GetParsedABI().Pack("", constructorArguments...) + if err != nil { + logNativeV2Error(ctx, p, "pack arguments", err.Error()) + return err + } + bin := append(native.GetBin(), packedArgs...) + stateDB := state.NewDBImpl(ctx, k, false) + evmModuleAddress := k.GetEVMAddressOrDefault(ctx, k.AccountKeeper().GetModuleAddress(types.ModuleName)) + msg := core.Message{ + From: evmModuleAddress, + Nonce: stateDB.GetNonce(evmModuleAddress), + Value: utils.Big0, + GasLimit: math.MaxUint64, + GasPrice: utils.Big0, + GasFeeCap: utils.Big0, + GasTipCap: utils.Big0, + Data: bin, + SkipAccountChecks: true, + } + gp := core.GasPool(math.MaxUint64) + blockCtx, err := k.GetVMBlockContext(ctx, gp) + if err != nil { + logNativeV2Error(ctx, p, "get block context", err.Error()) + return err } - if uint16(p.Version) < native.CurrentVersion { - return fmt.Errorf("cannot register pointer with version smaller than %d", native.CurrentVersion) + cfg := types.DefaultChainConfig().EthereumConfig(k.ChainID(ctx)) + txCtx := core.NewEVMTxContext(&msg) + evmInstance := vm.NewEVM(*blockCtx, txCtx, stateDB, cfg, vm.Config{}) + st := core.NewStateTransition(evmInstance, &msg, &gp, true) + // TODO: retain existing contract address if any + res, err := st.TransitionDb() + if err != nil { + logNativeV2Error(ctx, p, "deploying pointer", err.Error()) + return err } - return k.SetERC20NativePointerWithVersion(ctx, p.Token, common.HexToAddress(p.Pointer), uint16(p.Version)) + if res.Err != nil { + logNativeV2Error(ctx, p, "deploying pointer (VM)", res.Err.Error()) + return res.Err + } else { + surplus, err := stateDB.Finalize() + if err != nil { + logNativeV2Error(ctx, p, "finalizing", err.Error()) + return err + } + if !surplus.IsZero() { + // not an error worth quiting for but should be logged + logNativeV2Error(ctx, p, "finalizing (surplus)", surplus.String()) + } + } + contractAddr := crypto.CreateAddress(msg.From, msg.Nonce) + if err := k.SetERC20NativePointer(ctx, p.Token, contractAddr); err != nil { + return err + } + ctx.EventManager().EmitEvent(sdk.NewEvent( + types.EventTypePointerRegistered, sdk.NewAttribute(types.AttributeKeyPointerType, "native"), + sdk.NewAttribute(types.AttributeKeyPointerAddress, contractAddr.Hex()), sdk.NewAttribute(types.AttributeKeyPointee, p.Token), + sdk.NewAttribute(types.AttributeKeyPointerVersion, fmt.Sprintf("%d", native.CurrentVersion)))) + return nil +} + +func logNativeV2Error(ctx sdk.Context, p *types.AddERCNativePointerProposalV2, step string, err string) { + id := fmt.Sprintf("Title: %s, Description: %s, Token: %s", p.Title, p.Description, p.Token) + ctx.Logger().Error(fmt.Sprintf("proposal (%s) encountered error during (%s) due to (%s)", id, step, err)) +} + +func HandleAddERCNativePointerProposal(ctx sdk.Context, k *keeper.Keeper, p *types.AddERCNativePointerProposal) error { + return errors.New("proposal type deprecated") } func HandleAddERCCW20PointerProposal(ctx sdk.Context, k *keeper.Keeper, p *types.AddERCCW20PointerProposal) error { - ctx.EventManager().EmitEvent(sdk.NewEvent( - types.EventTypePointerRegistered, sdk.NewAttribute(types.AttributeKeyPointerType, "cw20"), - sdk.NewAttribute(types.AttributeKeyPointerAddress, p.Pointer), sdk.NewAttribute(types.AttributeKeyPointee, p.Pointee), - sdk.NewAttribute(types.AttributeKeyPointerVersion, fmt.Sprintf("%d", p.Version)))) - if p.Pointer == "" { - k.DeleteERC20CW20Pointer(ctx, p.Pointee, uint16(p.Version)) - return nil - } - if uint16(p.Version) < cw20.CurrentVersion(ctx) { - return fmt.Errorf("cannot register pointer with version smaller than %d", cw20.CurrentVersion(ctx)) - } - return k.SetERC20CW20PointerWithVersion(ctx, p.Pointee, common.HexToAddress(p.Pointer), uint16(p.Version)) + return errors.New("proposal type deprecated") } func HandleAddERCCW721PointerProposal(ctx sdk.Context, k *keeper.Keeper, p *types.AddERCCW721PointerProposal) error { - ctx.EventManager().EmitEvent(sdk.NewEvent( - types.EventTypePointerRegistered, sdk.NewAttribute(types.AttributeKeyPointerType, "cw721"), - sdk.NewAttribute(types.AttributeKeyPointerAddress, p.Pointer), sdk.NewAttribute(types.AttributeKeyPointee, p.Pointee), - sdk.NewAttribute(types.AttributeKeyPointerVersion, fmt.Sprintf("%d", p.Version)))) - if p.Pointer == "" { - k.DeleteERC721CW721Pointer(ctx, p.Pointee, uint16(p.Version)) - return nil - } - if uint16(p.Version) < cw721.CurrentVersion { - return fmt.Errorf("cannot register pointer with version smaller than %d", cw721.CurrentVersion) - } - return k.SetERC721CW721PointerWithVersion(ctx, p.Pointee, common.HexToAddress(p.Pointer), uint16(p.Version)) + return errors.New("proposal type deprecated") } func HandleAddCWERC20PointerProposal(ctx sdk.Context, k *keeper.Keeper, p *types.AddCWERC20PointerProposal) error { - ctx.EventManager().EmitEvent(sdk.NewEvent( - types.EventTypePointerRegistered, sdk.NewAttribute(types.AttributeKeyPointerType, "erc20"), - sdk.NewAttribute(types.AttributeKeyPointerAddress, p.Pointer), sdk.NewAttribute(types.AttributeKeyPointee, p.Pointee), - sdk.NewAttribute(types.AttributeKeyPointerVersion, fmt.Sprintf("%d", p.Version)))) - if p.Pointer == "" { - k.DeleteCW20ERC20Pointer(ctx, common.HexToAddress(p.Pointee), uint16(p.Version)) - return nil - } - if uint16(p.Version) < erc20.CurrentVersion { - return fmt.Errorf("cannot register pointer with version smaller than %d", erc20.CurrentVersion) - } - return k.SetCW20ERC20PointerWithVersion(ctx, common.HexToAddress(p.Pointee), p.Pointer, uint16(p.Version)) + return errors.New("proposal type deprecated") } func HandleAddCWERC721PointerProposal(ctx sdk.Context, k *keeper.Keeper, p *types.AddCWERC721PointerProposal) error { - ctx.EventManager().EmitEvent(sdk.NewEvent( - types.EventTypePointerRegistered, sdk.NewAttribute(types.AttributeKeyPointerType, "erc721"), - sdk.NewAttribute(types.AttributeKeyPointerAddress, p.Pointer), sdk.NewAttribute(types.AttributeKeyPointee, p.Pointee), - sdk.NewAttribute(types.AttributeKeyPointerVersion, fmt.Sprintf("%d", p.Version)))) - if p.Pointer == "" { - k.DeleteCW721ERC721Pointer(ctx, common.HexToAddress(p.Pointee), uint16(p.Version)) - return nil - } - if uint16(p.Version) < erc721.CurrentVersion { - return fmt.Errorf("cannot register pointer with version smaller than %d", erc721.CurrentVersion) - } - return k.SetCW721ERC721PointerWithVersion(ctx, common.HexToAddress(p.Pointee), p.Pointer, uint16(p.Version)) + return errors.New("proposal type deprecated") } diff --git a/x/evm/gov_test.go b/x/evm/gov_test.go index 6a683aa4a..8b6769394 100644 --- a/x/evm/gov_test.go +++ b/x/evm/gov_test.go @@ -5,198 +5,45 @@ import ( testkeeper "github.com/sei-protocol/sei-chain/testutil/keeper" "github.com/sei-protocol/sei-chain/x/evm" - "github.com/sei-protocol/sei-chain/x/evm/artifacts/cw20" - "github.com/sei-protocol/sei-chain/x/evm/artifacts/cw721" - "github.com/sei-protocol/sei-chain/x/evm/artifacts/erc20" - "github.com/sei-protocol/sei-chain/x/evm/artifacts/erc721" "github.com/sei-protocol/sei-chain/x/evm/artifacts/native" "github.com/sei-protocol/sei-chain/x/evm/types" "github.com/stretchr/testify/require" ) -func TestAddERCNativePointerProposals(t *testing.T) { +func TestAddERCNativePointerProposalsV2(t *testing.T) { k, ctx := testkeeper.MockEVMKeeper() - _, pointer1 := testkeeper.MockAddressPair() - _, pointer2 := testkeeper.MockAddressPair() - require.NotNil(t, evm.HandleAddERCNativePointerProposal(ctx, k, &types.AddERCNativePointerProposal{ - Token: "test", - Version: uint32(native.CurrentVersion - 1), - Pointer: pointer1.Hex(), - })) - require.Nil(t, evm.HandleAddERCNativePointerProposal(ctx, k, &types.AddERCNativePointerProposal{ - Token: "test", - Version: uint32(native.CurrentVersion), - Pointer: pointer1.Hex(), - })) - addr, ver, exists := k.GetERC20NativePointer(ctx, "test") - require.True(t, exists) - require.Equal(t, native.CurrentVersion, ver) - require.Equal(t, addr, pointer1) - require.Nil(t, evm.HandleAddERCNativePointerProposal(ctx, k, &types.AddERCNativePointerProposal{ - Token: "test", - Version: uint32(native.CurrentVersion + 1), - Pointer: pointer2.Hex(), - })) - addr, ver, exists = k.GetERC20NativePointer(ctx, "test") - require.True(t, exists) - require.Equal(t, native.CurrentVersion+1, ver) - require.Equal(t, addr, pointer2) - require.Nil(t, evm.HandleAddERCNativePointerProposal(ctx, k, &types.AddERCNativePointerProposal{ - Token: "test", - Version: uint32(native.CurrentVersion + 1), - })) - addr, ver, exists = k.GetERC20NativePointer(ctx, "test") - require.True(t, exists) - require.Equal(t, native.CurrentVersion, ver) - require.Equal(t, addr, pointer1) -} - -func TestAddERCCW20PointerProposals(t *testing.T) { - k, ctx := testkeeper.MockEVMKeeper() - _, pointer1 := testkeeper.MockAddressPair() - _, pointer2 := testkeeper.MockAddressPair() - require.NotNil(t, evm.HandleAddERCCW20PointerProposal(ctx, k, &types.AddERCCW20PointerProposal{ - Pointee: "test", - Version: uint32(cw20.CurrentVersion(ctx) - 1), - Pointer: pointer1.Hex(), - })) - require.Nil(t, evm.HandleAddERCCW20PointerProposal(ctx, k, &types.AddERCCW20PointerProposal{ - Pointee: "test", - Version: uint32(cw20.CurrentVersion(ctx)), - Pointer: pointer1.Hex(), - })) - addr, ver, exists := k.GetERC20CW20Pointer(ctx, "test") - require.True(t, exists) - require.Equal(t, cw20.CurrentVersion(ctx), ver) - require.Equal(t, addr, pointer1) - require.Nil(t, evm.HandleAddERCCW20PointerProposal(ctx, k, &types.AddERCCW20PointerProposal{ - Pointee: "test", - Version: uint32(cw20.CurrentVersion(ctx) + 1), - Pointer: pointer2.Hex(), - })) - addr, ver, exists = k.GetERC20CW20Pointer(ctx, "test") - require.True(t, exists) - require.Equal(t, cw20.CurrentVersion(ctx)+1, ver) - require.Equal(t, addr, pointer2) - require.Nil(t, evm.HandleAddERCCW20PointerProposal(ctx, k, &types.AddERCCW20PointerProposal{ - Pointee: "test", - Version: uint32(cw20.CurrentVersion(ctx) + 1), - })) - addr, ver, exists = k.GetERC20CW20Pointer(ctx, "test") - require.True(t, exists) - require.Equal(t, cw20.CurrentVersion(ctx), ver) - require.Equal(t, addr, pointer1) -} - -func TestAddERCCW721PointerProposals(t *testing.T) { - k, ctx := testkeeper.MockEVMKeeper() - _, pointer1 := testkeeper.MockAddressPair() - _, pointer2 := testkeeper.MockAddressPair() - require.NotNil(t, evm.HandleAddERCCW721PointerProposal(ctx, k, &types.AddERCCW721PointerProposal{ - Pointee: "test", - Version: uint32(cw721.CurrentVersion - 1), - Pointer: pointer1.Hex(), - })) - require.Nil(t, evm.HandleAddERCCW721PointerProposal(ctx, k, &types.AddERCCW721PointerProposal{ - Pointee: "test", - Version: uint32(cw721.CurrentVersion), - Pointer: pointer1.Hex(), - })) - addr, ver, exists := k.GetERC721CW721Pointer(ctx, "test") - require.True(t, exists) - require.Equal(t, cw721.CurrentVersion, ver) - require.Equal(t, addr, pointer1) - require.Nil(t, evm.HandleAddERCCW721PointerProposal(ctx, k, &types.AddERCCW721PointerProposal{ - Pointee: "test", - Version: uint32(cw721.CurrentVersion + 1), - Pointer: pointer2.Hex(), - })) - addr, ver, exists = k.GetERC721CW721Pointer(ctx, "test") - require.True(t, exists) - require.Equal(t, cw721.CurrentVersion+1, ver) - require.Equal(t, addr, pointer2) - require.Nil(t, evm.HandleAddERCCW721PointerProposal(ctx, k, &types.AddERCCW721PointerProposal{ - Pointee: "test", - Version: uint32(cw721.CurrentVersion + 1), - })) - addr, ver, exists = k.GetERC721CW721Pointer(ctx, "test") - require.True(t, exists) - require.Equal(t, cw721.CurrentVersion, ver) - require.Equal(t, addr, pointer1) -} + require.Nil(t, evm.HandleAddERCNativePointerProposalV2(ctx, k, &types.AddERCNativePointerProposalV2{ + Token: "test", + Name: "NAME", + Symbol: "SYMBOL", + Decimals: 6, + })) + pointer, _, exists := k.GetERC20NativePointer(ctx, "test") + require.True(t, exists) + qName, _ := native.GetParsedABI().Pack("name") + resName, err := k.StaticCallEVM(ctx, k.AccountKeeper().GetModuleAddress(types.ModuleName), &pointer, qName) + require.Nil(t, err) + oName, _ := native.GetParsedABI().Unpack("name", resName) + require.Equal(t, "NAME", oName[0].(string)) + qSymbol, _ := native.GetParsedABI().Pack("symbol") + resSymbol, err := k.StaticCallEVM(ctx, k.AccountKeeper().GetModuleAddress(types.ModuleName), &pointer, qSymbol) + require.Nil(t, err) + oSymbol, _ := native.GetParsedABI().Unpack("symbol", resSymbol) + require.Equal(t, "SYMBOL", oSymbol[0].(string)) + qDecimals, _ := native.GetParsedABI().Pack("decimals") + resDecimals, err := k.StaticCallEVM(ctx, k.AccountKeeper().GetModuleAddress(types.ModuleName), &pointer, qDecimals) + require.Nil(t, err) + oDecimals, _ := native.GetParsedABI().Unpack("decimals", resDecimals) + require.Equal(t, uint8(6), oDecimals[0].(uint8)) -func TestAddCWERC20PointerProposals(t *testing.T) { - k, ctx := testkeeper.MockEVMKeeper() - _, pointee1 := testkeeper.MockAddressPair() - pointer1, _ := testkeeper.MockAddressPair() - pointer2, _ := testkeeper.MockAddressPair() - require.NotNil(t, evm.HandleAddCWERC20PointerProposal(ctx, k, &types.AddCWERC20PointerProposal{ - Pointee: pointee1.Hex(), - Version: uint32(erc20.CurrentVersion - 1), - Pointer: pointer1.String(), - })) - require.Nil(t, evm.HandleAddCWERC20PointerProposal(ctx, k, &types.AddCWERC20PointerProposal{ - Pointee: pointee1.Hex(), - Version: uint32(erc20.CurrentVersion), - Pointer: pointer1.String(), - })) - addr, ver, exists := k.GetCW20ERC20Pointer(ctx, pointee1) - require.True(t, exists) - require.Equal(t, erc20.CurrentVersion, ver) - require.Equal(t, addr, pointer1) - require.Nil(t, evm.HandleAddCWERC20PointerProposal(ctx, k, &types.AddCWERC20PointerProposal{ - Pointee: pointee1.Hex(), - Version: uint32(erc20.CurrentVersion + 1), - Pointer: pointer2.String(), - })) - addr, ver, exists = k.GetCW20ERC20Pointer(ctx, pointee1) - require.True(t, exists) - require.Equal(t, erc20.CurrentVersion+1, ver) - require.Equal(t, addr, pointer2) - require.Nil(t, evm.HandleAddCWERC20PointerProposal(ctx, k, &types.AddCWERC20PointerProposal{ - Pointee: pointee1.Hex(), - Version: uint32(erc20.CurrentVersion + 1), - })) - addr, ver, exists = k.GetCW20ERC20Pointer(ctx, pointee1) - require.True(t, exists) - require.Equal(t, erc20.CurrentVersion, ver) - require.Equal(t, addr, pointer1) -} - -func TestAddCWERC721PointerProposals(t *testing.T) { - k, ctx := testkeeper.MockEVMKeeper() - _, pointee1 := testkeeper.MockAddressPair() - pointer1, _ := testkeeper.MockAddressPair() - pointer2, _ := testkeeper.MockAddressPair() - require.NotNil(t, evm.HandleAddCWERC721PointerProposal(ctx, k, &types.AddCWERC721PointerProposal{ - Pointee: pointee1.Hex(), - Version: uint32(erc721.CurrentVersion - 1), - Pointer: pointer1.String(), - })) - require.Nil(t, evm.HandleAddCWERC721PointerProposal(ctx, k, &types.AddCWERC721PointerProposal{ - Pointee: pointee1.Hex(), - Version: uint32(erc721.CurrentVersion), - Pointer: pointer1.String(), - })) - addr, ver, exists := k.GetCW721ERC721Pointer(ctx, pointee1) - require.True(t, exists) - require.Equal(t, uint16(erc721.CurrentVersion), ver) - require.Equal(t, addr, pointer1) - require.Nil(t, evm.HandleAddCWERC721PointerProposal(ctx, k, &types.AddCWERC721PointerProposal{ - Pointee: pointee1.Hex(), - Version: uint32(erc721.CurrentVersion + 1), - Pointer: pointer2.String(), - })) - addr, ver, exists = k.GetCW721ERC721Pointer(ctx, pointee1) - require.True(t, exists) - require.Equal(t, erc721.CurrentVersion+1, ver) - require.Equal(t, addr, pointer2) - require.Nil(t, evm.HandleAddCWERC721PointerProposal(ctx, k, &types.AddCWERC721PointerProposal{ - Pointee: pointee1.Hex(), - Version: uint32(erc721.CurrentVersion + 1), - })) - addr, ver, exists = k.GetCW721ERC721Pointer(ctx, pointee1) - require.True(t, exists) - require.Equal(t, uint16(erc721.CurrentVersion), ver) - require.Equal(t, addr, pointer1) + // make sure pointers deployed this way won't collide in address + require.Nil(t, evm.HandleAddERCNativePointerProposalV2(ctx, k, &types.AddERCNativePointerProposalV2{ + Token: "test2", + Name: "NAME2", + Symbol: "SYMBOL2", + Decimals: 6, + })) + pointer2, _, exists2 := k.GetERC20NativePointer(ctx, "test2") + require.True(t, exists2) + require.NotEqual(t, pointer, pointer2) } diff --git a/x/evm/handler.go b/x/evm/handler.go index d75417883..c9cb53941 100644 --- a/x/evm/handler.go +++ b/x/evm/handler.go @@ -50,6 +50,8 @@ func NewProposalHandler(k keeper.Keeper) govtypes.Handler { return HandleAddCWERC20PointerProposal(ctx, &k, c) case *types.AddCWERC721PointerProposal: return HandleAddCWERC721PointerProposal(ctx, &k, c) + case *types.AddERCNativePointerProposalV2: + return HandleAddERCNativePointerProposalV2(ctx, &k, c) default: return sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized evm proposal content type: %T", c) } diff --git a/x/evm/types/codec.go b/x/evm/types/codec.go index 890b208ed..e70f6d7a9 100644 --- a/x/evm/types/codec.go +++ b/x/evm/types/codec.go @@ -38,6 +38,7 @@ func RegisterInterfaces(registry codectypes.InterfaceRegistry) { &AddERCCW721PointerProposal{}, &AddCWERC20PointerProposal{}, &AddCWERC721PointerProposal{}, + &AddERCNativePointerProposalV2{}, ) registry.RegisterImplementations( (*sdk.Msg)(nil), diff --git a/x/evm/types/gov.go b/x/evm/types/gov.go index 13f35800c..1406e94f8 100644 --- a/x/evm/types/gov.go +++ b/x/evm/types/gov.go @@ -12,11 +12,12 @@ import ( ) const ( - ProposalTypeAddERCNativePointer = "AddERCNativePointer" - ProposalTypeAddERCCW20Pointer = "AddERCCW20Pointer" - ProposalTypeAddERCCW721Pointer = "AddERCCW721Pointer" - ProposalTypeAddCWERC20Pointer = "AddCWERC20Pointer" - ProposalTypeAddCWERC721Pointer = "AddCWERC721Pointer" + ProposalTypeAddERCNativePointer = "AddERCNativePointer" + ProposalTypeAddERCCW20Pointer = "AddERCCW20Pointer" + ProposalTypeAddERCCW721Pointer = "AddERCCW721Pointer" + ProposalTypeAddCWERC20Pointer = "AddCWERC20Pointer" + ProposalTypeAddCWERC721Pointer = "AddCWERC721Pointer" + ProposalTypeAddERCNativePointerV2 = "AddERCNativePointerV2" ) func init() { @@ -26,6 +27,7 @@ func init() { govtypes.RegisterProposalType(ProposalTypeAddERCCW721Pointer) govtypes.RegisterProposalType(ProposalTypeAddCWERC20Pointer) govtypes.RegisterProposalType(ProposalTypeAddCWERC721Pointer) + govtypes.RegisterProposalType(ProposalTypeAddERCNativePointerV2) // for marshal and unmarshal govtypes.RegisterProposalTypeCodec(&AddERCNativePointerProposal{}, "evm/AddERCNativePointerProposal") @@ -33,6 +35,7 @@ func init() { govtypes.RegisterProposalTypeCodec(&AddERCCW721PointerProposal{}, "evm/AddERCCW721PointerProposal") govtypes.RegisterProposalTypeCodec(&AddCWERC20PointerProposal{}, "evm/AddCWERC20PointerProposal") govtypes.RegisterProposalTypeCodec(&AddCWERC721PointerProposal{}, "evm/AddCWERC721PointerProposal") + govtypes.RegisterProposalTypeCodec(&AddERCNativePointerProposalV2{}, "evm/AddCWERC721PointerProposalV2") } func (p *AddERCNativePointerProposal) GetTitle() string { return p.Title } @@ -222,3 +225,34 @@ func (p AddCWERC721PointerProposal) String() string { `, p.Title, p.Description, p.Pointee, p.Pointer, p.Version)) return b.String() } + +func (p *AddERCNativePointerProposalV2) GetTitle() string { return p.Title } + +func (p *AddERCNativePointerProposalV2) GetDescription() string { return p.Description } + +func (p *AddERCNativePointerProposalV2) ProposalRoute() string { return RouterKey } + +func (p *AddERCNativePointerProposalV2) ProposalType() string { + return ProposalTypeAddERCNativePointerV2 +} + +func (p *AddERCNativePointerProposalV2) ValidateBasic() error { + if p.Decimals > math.MaxUint8 { + return errors.New("pointer version must be <= 255") + } + + return govtypes.ValidateAbstract(p) +} + +func (p AddERCNativePointerProposalV2) String() string { + var b strings.Builder + b.WriteString(fmt.Sprintf(`Add ERC native pointer Proposal V2: + Title: %s + Description: %s + Token: %s + Name: %s + Symbol: %s + Decimals: %d +`, p.Title, p.Description, p.Token, p.Name, p.Symbol, p.Decimals)) + return b.String() +} diff --git a/x/evm/types/gov.pb.go b/x/evm/types/gov.pb.go index ef6f6457e..2042b135b 100644 --- a/x/evm/types/gov.pb.go +++ b/x/evm/types/gov.pb.go @@ -223,42 +223,90 @@ func (m *AddCWERC721PointerProposal) XXX_DiscardUnknown() { var xxx_messageInfo_AddCWERC721PointerProposal proto.InternalMessageInfo +type AddERCNativePointerProposalV2 struct { + Title string `protobuf:"bytes,1,opt,name=title,proto3" json:"title,omitempty" yaml:"title"` + Description string `protobuf:"bytes,2,opt,name=description,proto3" json:"description,omitempty" yaml:"description"` + Token string `protobuf:"bytes,3,opt,name=token,proto3" json:"token,omitempty" yaml:"token"` + Name string `protobuf:"bytes,4,opt,name=name,proto3" json:"name,omitempty" yaml:"name"` + Symbol string `protobuf:"bytes,5,opt,name=symbol,proto3" json:"symbol,omitempty" yaml:"symbol"` + Decimals uint32 `protobuf:"varint,6,opt,name=decimals,proto3" json:"decimals,omitempty" yaml:"decimals"` +} + +func (m *AddERCNativePointerProposalV2) Reset() { *m = AddERCNativePointerProposalV2{} } +func (*AddERCNativePointerProposalV2) ProtoMessage() {} +func (*AddERCNativePointerProposalV2) Descriptor() ([]byte, []int) { + return fileDescriptor_fb66eb1aab5c39af, []int{5} +} +func (m *AddERCNativePointerProposalV2) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *AddERCNativePointerProposalV2) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_AddERCNativePointerProposalV2.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *AddERCNativePointerProposalV2) XXX_Merge(src proto.Message) { + xxx_messageInfo_AddERCNativePointerProposalV2.Merge(m, src) +} +func (m *AddERCNativePointerProposalV2) XXX_Size() int { + return m.Size() +} +func (m *AddERCNativePointerProposalV2) XXX_DiscardUnknown() { + xxx_messageInfo_AddERCNativePointerProposalV2.DiscardUnknown(m) +} + +var xxx_messageInfo_AddERCNativePointerProposalV2 proto.InternalMessageInfo + func init() { proto.RegisterType((*AddERCNativePointerProposal)(nil), "seiprotocol.seichain.evm.AddERCNativePointerProposal") proto.RegisterType((*AddERCCW20PointerProposal)(nil), "seiprotocol.seichain.evm.AddERCCW20PointerProposal") proto.RegisterType((*AddERCCW721PointerProposal)(nil), "seiprotocol.seichain.evm.AddERCCW721PointerProposal") proto.RegisterType((*AddCWERC20PointerProposal)(nil), "seiprotocol.seichain.evm.AddCWERC20PointerProposal") proto.RegisterType((*AddCWERC721PointerProposal)(nil), "seiprotocol.seichain.evm.AddCWERC721PointerProposal") + proto.RegisterType((*AddERCNativePointerProposalV2)(nil), "seiprotocol.seichain.evm.AddERCNativePointerProposalV2") } func init() { proto.RegisterFile("evm/gov.proto", fileDescriptor_fb66eb1aab5c39af) } var fileDescriptor_fb66eb1aab5c39af = []byte{ - // 377 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x4d, 0x2d, 0xcb, 0xd5, - 0x4f, 0xcf, 0x2f, 0xd3, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x92, 0x28, 0x4e, 0xcd, 0x04, 0xb3, - 0x92, 0xf3, 0x73, 0xf4, 0x8a, 0x53, 0x33, 0x93, 0x33, 0x12, 0x33, 0xf3, 0xf4, 0x52, 0xcb, 0x72, - 0xa5, 0x44, 0xd2, 0xf3, 0xd3, 0xf3, 0xc1, 0x52, 0xfa, 0x20, 0x16, 0x44, 0xbd, 0xd2, 0x44, 0x26, - 0x2e, 0x69, 0xc7, 0x94, 0x14, 0xd7, 0x20, 0x67, 0xbf, 0xc4, 0x92, 0xcc, 0xb2, 0xd4, 0x80, 0xfc, - 0xcc, 0xbc, 0x92, 0xd4, 0xa2, 0x80, 0xa2, 0xfc, 0x82, 0xfc, 0xe2, 0xc4, 0x1c, 0x21, 0x35, 0x2e, - 0xd6, 0x92, 0xcc, 0x92, 0x9c, 0x54, 0x09, 0x46, 0x05, 0x46, 0x0d, 0x4e, 0x27, 0x81, 0x4f, 0xf7, - 0xe4, 0x79, 0x2a, 0x13, 0x73, 0x73, 0xac, 0x94, 0xc0, 0xc2, 0x4a, 0x41, 0x10, 0x69, 0x21, 0x0b, - 0x2e, 0xee, 0x94, 0xd4, 0xe2, 0xe4, 0xa2, 0xcc, 0x82, 0x92, 0xcc, 0xfc, 0x3c, 0x09, 0x26, 0xb0, - 0x6a, 0xb1, 0x4f, 0xf7, 0xe4, 0x85, 0x20, 0xaa, 0x91, 0x24, 0x95, 0x82, 0x90, 0x95, 0x82, 0x6d, - 0xc8, 0xcf, 0x4e, 0xcd, 0x93, 0x60, 0xc6, 0xb0, 0x01, 0x24, 0x0c, 0xb2, 0x01, 0x44, 0x0b, 0xe9, - 0x70, 0xb1, 0x17, 0x40, 0x1c, 0x27, 0xc1, 0x02, 0x56, 0x29, 0xf4, 0xe9, 0x9e, 0x3c, 0x1f, 0x44, - 0x25, 0x54, 0x42, 0x29, 0x08, 0xa6, 0x04, 0xa4, 0xba, 0x2c, 0xb5, 0xa8, 0x18, 0xe4, 0x16, 0x56, - 0x05, 0x46, 0x0d, 0x5e, 0x64, 0xd5, 0x50, 0x09, 0xa5, 0x20, 0x98, 0x12, 0x2b, 0x9e, 0x8e, 0x05, - 0xf2, 0x0c, 0x33, 0x16, 0xc8, 0x33, 0xbc, 0x58, 0x20, 0xcf, 0xa0, 0x34, 0x95, 0x89, 0x4b, 0x12, - 0x12, 0x26, 0xce, 0xe1, 0x46, 0x06, 0xf4, 0x0f, 0x11, 0xb8, 0x4f, 0x53, 0xa1, 0x61, 0x82, 0xe1, - 0xd3, 0x54, 0xb8, 0x4f, 0x53, 0xe9, 0x18, 0x2e, 0xd3, 0x98, 0xb8, 0xa4, 0x60, 0xe1, 0x62, 0x6e, - 0x64, 0x38, 0x1a, 0x30, 0x68, 0x09, 0xc6, 0x39, 0xdc, 0x35, 0xc8, 0x79, 0x34, 0xc1, 0x60, 0x24, - 0x18, 0x70, 0xb8, 0x8c, 0x26, 0x18, 0x44, 0xc0, 0x38, 0xb9, 0x9f, 0x78, 0x24, 0xc7, 0x78, 0xe1, - 0x91, 0x1c, 0xe3, 0x83, 0x47, 0x72, 0x8c, 0x13, 0x1e, 0xcb, 0x31, 0x5c, 0x78, 0x2c, 0xc7, 0x70, - 0xe3, 0xb1, 0x1c, 0x43, 0x94, 0x6e, 0x7a, 0x66, 0x49, 0x46, 0x69, 0x92, 0x5e, 0x72, 0x7e, 0xae, - 0x7e, 0x71, 0x6a, 0xa6, 0x2e, 0xac, 0x2c, 0x07, 0x73, 0xc0, 0x85, 0xb9, 0x7e, 0x85, 0x3e, 0xa8, - 0xc8, 0x2f, 0xa9, 0x2c, 0x48, 0x2d, 0x4e, 0x62, 0x03, 0xcb, 0x1b, 0x03, 0x02, 0x00, 0x00, 0xff, - 0xff, 0xb2, 0xe1, 0xcb, 0x45, 0x06, 0x06, 0x00, 0x00, + // 466 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xec, 0x95, 0xc1, 0x6a, 0xd4, 0x40, + 0x18, 0xc7, 0x93, 0xd8, 0xae, 0x76, 0xda, 0xb5, 0x1a, 0x45, 0x62, 0xc5, 0x4c, 0x19, 0x41, 0x2a, + 0xd8, 0x8d, 0xae, 0x07, 0xa5, 0x37, 0x77, 0x29, 0xde, 0xa4, 0xcc, 0xc1, 0x82, 0xb7, 0x6c, 0xf6, + 0x63, 0x3b, 0x98, 0x64, 0x42, 0x66, 0x0c, 0xee, 0x1b, 0x78, 0xd4, 0x83, 0xe2, 0x71, 0x1f, 0xc3, + 0x47, 0xf0, 0xd8, 0xa3, 0xa7, 0x20, 0xbb, 0x17, 0xcf, 0x79, 0x02, 0x99, 0x99, 0x64, 0x89, 0x2e, + 0x78, 0x2c, 0x3d, 0xec, 0x29, 0x93, 0xef, 0xff, 0x83, 0x99, 0xf9, 0xf1, 0x31, 0x1f, 0xea, 0x42, + 0x91, 0x04, 0x13, 0x5e, 0xf4, 0xb2, 0x9c, 0x4b, 0xee, 0x7a, 0x02, 0x98, 0x5e, 0x45, 0x3c, 0xee, + 0x09, 0x60, 0xd1, 0x59, 0xc8, 0xd2, 0x1e, 0x14, 0xc9, 0xde, 0xed, 0x09, 0x9f, 0x70, 0x1d, 0x05, + 0x6a, 0x65, 0x78, 0xf2, 0xd9, 0x41, 0xf7, 0x5e, 0x8e, 0xc7, 0xc7, 0x74, 0xf8, 0x3a, 0x94, 0xac, + 0x80, 0x13, 0xce, 0x52, 0x09, 0xf9, 0x49, 0xce, 0x33, 0x2e, 0xc2, 0xd8, 0x7d, 0x88, 0x36, 0x25, + 0x93, 0x31, 0x78, 0xf6, 0xbe, 0x7d, 0xb0, 0x35, 0xb8, 0x51, 0x95, 0x78, 0x67, 0x1a, 0x26, 0xf1, + 0x11, 0xd1, 0x65, 0x42, 0x4d, 0xec, 0xbe, 0x40, 0xdb, 0x63, 0x10, 0x51, 0xce, 0x32, 0xc9, 0x78, + 0xea, 0x39, 0x9a, 0xbe, 0x53, 0x95, 0xd8, 0x35, 0x74, 0x2b, 0x24, 0xb4, 0x8d, 0xea, 0x1d, 0xf8, + 0x3b, 0x48, 0xbd, 0x2b, 0x2b, 0x3b, 0xa8, 0xb2, 0xda, 0x41, 0x7d, 0xdd, 0xc7, 0xe8, 0x6a, 0x66, + 0x0e, 0xe7, 0x6d, 0x68, 0xd2, 0xad, 0x4a, 0x7c, 0xdd, 0x90, 0x75, 0x40, 0x68, 0x83, 0x28, 0xba, + 0x80, 0x5c, 0xa8, 0xb3, 0x6c, 0xee, 0xdb, 0x07, 0xdd, 0x36, 0x5d, 0x07, 0x84, 0x36, 0xc8, 0xd1, + 0xce, 0xc7, 0x19, 0xb6, 0xbe, 0xcd, 0xb0, 0xf5, 0x7b, 0x86, 0x2d, 0xf2, 0xc5, 0x41, 0x77, 0x8d, + 0x93, 0xe1, 0x69, 0xff, 0xc9, 0xc5, 0x1b, 0x59, 0xde, 0x14, 0x6a, 0x27, 0x2b, 0x37, 0x85, 0xe5, + 0x4d, 0xe1, 0x02, 0xbd, 0x7c, 0x75, 0xd0, 0x5e, 0xe3, 0xe5, 0x79, 0xff, 0xe9, 0x5a, 0xcc, 0x3f, + 0x0d, 0x33, 0x3c, 0x3d, 0xa6, 0xc3, 0x75, 0xc3, 0xac, 0x34, 0x8c, 0xf6, 0xb2, 0x6e, 0x98, 0x96, + 0x98, 0xef, 0x0e, 0xba, 0xff, 0x9f, 0x57, 0xf7, 0x4d, 0xff, 0x12, 0xbd, 0xbb, 0x0f, 0xd0, 0x46, + 0x1a, 0x26, 0x50, 0x2b, 0xd9, 0xad, 0x4a, 0xbc, 0x6d, 0x30, 0x55, 0x25, 0x54, 0x87, 0xee, 0x23, + 0xd4, 0x11, 0xd3, 0x64, 0xc4, 0x63, 0xed, 0x62, 0x6b, 0x70, 0xb3, 0x2a, 0x71, 0xd7, 0x60, 0xa6, + 0x4e, 0x68, 0x0d, 0xb8, 0x01, 0xba, 0x36, 0x86, 0x88, 0x25, 0x61, 0x2c, 0xbc, 0x8e, 0x16, 0x77, + 0xab, 0x2a, 0xf1, 0x6e, 0x73, 0x5c, 0x93, 0x10, 0xba, 0x84, 0xfe, 0x56, 0x37, 0x78, 0xf5, 0x63, + 0xee, 0xdb, 0xe7, 0x73, 0xdf, 0xfe, 0x35, 0xf7, 0xed, 0x4f, 0x0b, 0xdf, 0x3a, 0x5f, 0xf8, 0xd6, + 0xcf, 0x85, 0x6f, 0xbd, 0x3d, 0x9c, 0x30, 0x79, 0xf6, 0x7e, 0xd4, 0x8b, 0x78, 0x12, 0x08, 0x60, + 0x87, 0xcd, 0x18, 0xd4, 0x3f, 0x7a, 0x0e, 0x06, 0x1f, 0x02, 0x35, 0x2d, 0xe5, 0x34, 0x03, 0x31, + 0xea, 0xe8, 0xfc, 0xd9, 0x9f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x9f, 0x47, 0x09, 0x4e, 0x41, 0x07, + 0x00, 0x00, } func (m *AddERCNativePointerProposal) Marshal() (dAtA []byte, err error) { @@ -541,6 +589,69 @@ func (m *AddCWERC721PointerProposal) MarshalToSizedBuffer(dAtA []byte) (int, err return len(dAtA) - i, nil } +func (m *AddERCNativePointerProposalV2) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *AddERCNativePointerProposalV2) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *AddERCNativePointerProposalV2) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Decimals != 0 { + i = encodeVarintGov(dAtA, i, uint64(m.Decimals)) + i-- + dAtA[i] = 0x30 + } + if len(m.Symbol) > 0 { + i -= len(m.Symbol) + copy(dAtA[i:], m.Symbol) + i = encodeVarintGov(dAtA, i, uint64(len(m.Symbol))) + i-- + dAtA[i] = 0x2a + } + if len(m.Name) > 0 { + i -= len(m.Name) + copy(dAtA[i:], m.Name) + i = encodeVarintGov(dAtA, i, uint64(len(m.Name))) + i-- + dAtA[i] = 0x22 + } + if len(m.Token) > 0 { + i -= len(m.Token) + copy(dAtA[i:], m.Token) + i = encodeVarintGov(dAtA, i, uint64(len(m.Token))) + i-- + dAtA[i] = 0x1a + } + if len(m.Description) > 0 { + i -= len(m.Description) + copy(dAtA[i:], m.Description) + i = encodeVarintGov(dAtA, i, uint64(len(m.Description))) + i-- + dAtA[i] = 0x12 + } + if len(m.Title) > 0 { + i -= len(m.Title) + copy(dAtA[i:], m.Title) + i = encodeVarintGov(dAtA, i, uint64(len(m.Title))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + func encodeVarintGov(dAtA []byte, offset int, v uint64) int { offset -= sovGov(v) base := offset @@ -692,6 +803,38 @@ func (m *AddCWERC721PointerProposal) Size() (n int) { return n } +func (m *AddERCNativePointerProposalV2) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Title) + if l > 0 { + n += 1 + l + sovGov(uint64(l)) + } + l = len(m.Description) + if l > 0 { + n += 1 + l + sovGov(uint64(l)) + } + l = len(m.Token) + if l > 0 { + n += 1 + l + sovGov(uint64(l)) + } + l = len(m.Name) + if l > 0 { + n += 1 + l + sovGov(uint64(l)) + } + l = len(m.Symbol) + if l > 0 { + n += 1 + l + sovGov(uint64(l)) + } + if m.Decimals != 0 { + n += 1 + sovGov(uint64(m.Decimals)) + } + return n +} + func sovGov(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -1683,6 +1826,235 @@ func (m *AddCWERC721PointerProposal) Unmarshal(dAtA []byte) error { } return nil } +func (m *AddERCNativePointerProposalV2) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGov + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: AddERCNativePointerProposalV2: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: AddERCNativePointerProposalV2: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Title", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGov + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGov + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGov + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Title = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Description", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGov + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGov + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGov + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Description = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Token", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGov + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGov + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGov + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Token = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGov + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGov + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGov + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Name = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Symbol", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGov + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGov + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGov + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Symbol = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 6: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Decimals", wireType) + } + m.Decimals = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGov + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Decimals |= uint32(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipGov(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthGov + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func skipGov(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 diff --git a/x/evm/types/gov_test.go b/x/evm/types/gov_test.go new file mode 100644 index 000000000..86ce9ec7c --- /dev/null +++ b/x/evm/types/gov_test.go @@ -0,0 +1,29 @@ +package types_test + +import ( + "math" + "testing" + + "github.com/sei-protocol/sei-chain/x/evm/types" + "github.com/stretchr/testify/require" +) + +func TestAddERCNativePointerProposalV2(t *testing.T) { + p := types.AddERCNativePointerProposalV2{ + Title: "title", + Description: "desc", + Token: "test", + Name: "TEST", + Symbol: "Test", + Decimals: 6, + } + require.Equal(t, "title", p.GetTitle()) + require.Equal(t, "desc", p.GetDescription()) + require.Equal(t, "evm", p.ProposalRoute()) + require.Equal(t, "AddERCNativePointerV2", p.ProposalType()) + p.Decimals = math.MaxUint32 + require.NotNil(t, p.ValidateBasic()) + p.Decimals = 6 + require.Nil(t, p.ValidateBasic()) + require.NotEmpty(t, p.String()) +}