From ef65c2edb8000ecf8fa5eab3378b1e47e6973f02 Mon Sep 17 00:00:00 2001 From: dreamer Date: Mon, 22 Apr 2024 10:59:58 +0800 Subject: [PATCH 1/7] fix test error --- modules/token/client/cli/cli_test.go | 2 +- modules/token/client/testutil/grpc_query_test.go | 2 +- modules/token/migrations/v2/migrate_test.go | 2 ++ modules/token/simulation/genesis.go | 11 ++++++++++- modules/token/types/v1/params.go | 3 ++- 5 files changed, 16 insertions(+), 4 deletions(-) diff --git a/modules/token/client/cli/cli_test.go b/modules/token/client/cli/cli_test.go index 250ba628..933a1e8e 100644 --- a/modules/token/client/cli/cli_test.go +++ b/modules/token/client/cli/cli_test.go @@ -98,7 +98,7 @@ func (s *IntegrationTestSuite) TestToken() { //------test GetCmdQueryParams()------------- queryParamsResponse := tokentestutil.QueryParamsExec(s.T(), s.network, clientCtx) - expectedParams := "{\"token_tax_rate\":\"0.400000000000000000\",\"issue_token_base_fee\":{\"denom\":\"stake\",\"amount\":\"60000\"},\"mint_token_fee_ratio\":\"0.100000000000000000\"}" + expectedParams := "{\"token_tax_rate\":\"0.400000000000000000\",\"issue_token_base_fee\":{\"denom\":\"stake\",\"amount\":\"60000\"},\"mint_token_fee_ratio\":\"0.100000000000000000\",\"enable_erc20\":true}" result, _ = json.Marshal(queryParamsResponse) s.Require().Equal(expectedParams, string(result)) diff --git a/modules/token/client/testutil/grpc_query_test.go b/modules/token/client/testutil/grpc_query_test.go index cb707187..c11fc3c5 100644 --- a/modules/token/client/testutil/grpc_query_test.go +++ b/modules/token/client/testutil/grpc_query_test.go @@ -123,7 +123,7 @@ func (s *IntegrationTestSuite) TestToken() { s.Require().NoError(clientCtx.Codec.UnmarshalJSON(resp, respType)) paramsResp := respType.(*v1.QueryParamsResponse) s.Require().NoError(err) - expectedParams := "{\"token_tax_rate\":\"0.400000000000000000\",\"issue_token_base_fee\":{\"denom\":\"stake\",\"amount\":\"60000\"},\"mint_token_fee_ratio\":\"0.100000000000000000\"}" + expectedParams := "{\"token_tax_rate\":\"0.400000000000000000\",\"issue_token_base_fee\":{\"denom\":\"stake\",\"amount\":\"60000\"},\"mint_token_fee_ratio\":\"0.100000000000000000\",\"enable_erc20\":true}" result, _ = json.Marshal(paramsResp.Params) s.Require().Equal(expectedParams, string(result)) } diff --git a/modules/token/migrations/v2/migrate_test.go b/modules/token/migrations/v2/migrate_test.go index b36a272c..563821dd 100644 --- a/modules/token/migrations/v2/migrate_test.go +++ b/modules/token/migrations/v2/migrate_test.go @@ -30,6 +30,8 @@ func TestMigrate(t *testing.T) { require.NoError(t, err) expParams := app.TokenKeeper.GetParams(ctx) + // compatible with previous logic + expParams.EnableErc20 = true require.Equal(t, expParams, params, "v2.Migrate failed") } diff --git a/modules/token/simulation/genesis.go b/modules/token/simulation/genesis.go index 7d73f6b1..82c080b0 100644 --- a/modules/token/simulation/genesis.go +++ b/modules/token/simulation/genesis.go @@ -19,6 +19,7 @@ const ( TokenTaxRate = "token_tax_rate" IssueTokenBaseFee = "issue_token_base_fee" MintTokenFeeRatio = "mint_token_fee_ratio" + EnableErc20 = "enable_erc20" ) // RandomDec randomized sdk.RandomDec @@ -37,6 +38,7 @@ func RandomizedGenState(simState *module.SimulationState) { var tokenTaxRate sdk.Dec var issueTokenBaseFee sdk.Int var mintTokenFeeRatio sdk.Dec + var enableErc20 bool var tokens []v1.Token simState.AppParams.GetOrGenerate( @@ -61,8 +63,15 @@ func RandomizedGenState(simState *module.SimulationState) { func(r *rand.Rand) { mintTokenFeeRatio = sdk.NewDecWithPrec(int64(r.Intn(5)), 1) }, ) + simState.AppParams.GetOrGenerate( + simState.Cdc, EnableErc20, &enableErc20, simState.Rand, + func(r *rand.Rand) { + enableErc20 = true + }, + ) + tokenGenesis := v1.NewGenesisState( - v1.NewParams(tokenTaxRate, sdk.NewCoin(sdk.DefaultBondDenom, issueTokenBaseFee), mintTokenFeeRatio), + v1.NewParams(tokenTaxRate, sdk.NewCoin(sdk.DefaultBondDenom, issueTokenBaseFee), mintTokenFeeRatio,enableErc20), tokens, ) diff --git a/modules/token/types/v1/params.go b/modules/token/types/v1/params.go index 30df9236..cf89e48d 100644 --- a/modules/token/types/v1/params.go +++ b/modules/token/types/v1/params.go @@ -8,12 +8,13 @@ import ( // NewParams constructs a new Params instance func NewParams(tokenTaxRate sdk.Dec, issueTokenBaseFee sdk.Coin, - mintTokenFeeRatio sdk.Dec, + mintTokenFeeRatio sdk.Dec, enableErc20 bool, ) Params { return Params{ TokenTaxRate: tokenTaxRate, IssueTokenBaseFee: issueTokenBaseFee, MintTokenFeeRatio: mintTokenFeeRatio, + EnableErc20: enableErc20, } } From 226b711f632123d88031e947ab95a6111b083ff1 Mon Sep 17 00:00:00 2001 From: dreamer Date: Mon, 22 Apr 2024 11:18:33 +0800 Subject: [PATCH 2/7] add beacon for gov params --- api/irismod/token/v1/token.pulsar.go | 104 ++++++++++++++++++++---- modules/token/simulation/genesis.go | 9 +-- modules/token/types/v1/params.go | 23 +++++- modules/token/types/v1/token.pb.go | 113 +++++++++++++++++++-------- proto/irismod/token/v1/token.proto | 1 + 5 files changed, 194 insertions(+), 56 deletions(-) diff --git a/api/irismod/token/v1/token.pulsar.go b/api/irismod/token/v1/token.pulsar.go index 715473ef..e945319c 100644 --- a/api/irismod/token/v1/token.pulsar.go +++ b/api/irismod/token/v1/token.pulsar.go @@ -894,6 +894,7 @@ var ( fd_Params_issue_token_base_fee protoreflect.FieldDescriptor fd_Params_mint_token_fee_ratio protoreflect.FieldDescriptor fd_Params_enable_erc20 protoreflect.FieldDescriptor + fd_Params_beacon protoreflect.FieldDescriptor ) func init() { @@ -903,6 +904,7 @@ func init() { fd_Params_issue_token_base_fee = md_Params.Fields().ByName("issue_token_base_fee") fd_Params_mint_token_fee_ratio = md_Params.Fields().ByName("mint_token_fee_ratio") fd_Params_enable_erc20 = md_Params.Fields().ByName("enable_erc20") + fd_Params_beacon = md_Params.Fields().ByName("beacon") } var _ protoreflect.Message = (*fastReflection_Params)(nil) @@ -994,6 +996,12 @@ func (x *fastReflection_Params) Range(f func(protoreflect.FieldDescriptor, proto return } } + if x.Beacon != "" { + value := protoreflect.ValueOfString(x.Beacon) + if !f(fd_Params_beacon, value) { + return + } + } } // Has reports whether a field is populated. @@ -1017,6 +1025,8 @@ func (x *fastReflection_Params) Has(fd protoreflect.FieldDescriptor) bool { return x.MintTokenFeeRatio != "" case "irismod.token.v1.Params.enable_erc20": return x.EnableErc20 != false + case "irismod.token.v1.Params.beacon": + return x.Beacon != "" default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: irismod.token.v1.Params")) @@ -1041,6 +1051,8 @@ func (x *fastReflection_Params) Clear(fd protoreflect.FieldDescriptor) { x.MintTokenFeeRatio = "" case "irismod.token.v1.Params.enable_erc20": x.EnableErc20 = false + case "irismod.token.v1.Params.beacon": + x.Beacon = "" default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: irismod.token.v1.Params")) @@ -1069,6 +1081,9 @@ func (x *fastReflection_Params) Get(descriptor protoreflect.FieldDescriptor) pro case "irismod.token.v1.Params.enable_erc20": value := x.EnableErc20 return protoreflect.ValueOfBool(value) + case "irismod.token.v1.Params.beacon": + value := x.Beacon + return protoreflect.ValueOfString(value) default: if descriptor.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: irismod.token.v1.Params")) @@ -1097,6 +1112,8 @@ func (x *fastReflection_Params) Set(fd protoreflect.FieldDescriptor, value proto x.MintTokenFeeRatio = value.Interface().(string) case "irismod.token.v1.Params.enable_erc20": x.EnableErc20 = value.Bool() + case "irismod.token.v1.Params.beacon": + x.Beacon = value.Interface().(string) default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: irismod.token.v1.Params")) @@ -1128,6 +1145,8 @@ func (x *fastReflection_Params) Mutable(fd protoreflect.FieldDescriptor) protore panic(fmt.Errorf("field mint_token_fee_ratio of message irismod.token.v1.Params is not mutable")) case "irismod.token.v1.Params.enable_erc20": panic(fmt.Errorf("field enable_erc20 of message irismod.token.v1.Params is not mutable")) + case "irismod.token.v1.Params.beacon": + panic(fmt.Errorf("field beacon of message irismod.token.v1.Params is not mutable")) default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: irismod.token.v1.Params")) @@ -1150,6 +1169,8 @@ func (x *fastReflection_Params) NewField(fd protoreflect.FieldDescriptor) protor return protoreflect.ValueOfString("") case "irismod.token.v1.Params.enable_erc20": return protoreflect.ValueOfBool(false) + case "irismod.token.v1.Params.beacon": + return protoreflect.ValueOfString("") default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: irismod.token.v1.Params")) @@ -1234,6 +1255,10 @@ func (x *fastReflection_Params) ProtoMethods() *protoiface.Methods { if x.EnableErc20 { n += 2 } + l = len(x.Beacon) + if l > 0 { + n += 1 + l + runtime.Sov(uint64(l)) + } if x.unknownFields != nil { n += len(x.unknownFields) } @@ -1263,6 +1288,13 @@ func (x *fastReflection_Params) ProtoMethods() *protoiface.Methods { i -= len(x.unknownFields) copy(dAtA[i:], x.unknownFields) } + if len(x.Beacon) > 0 { + i -= len(x.Beacon) + copy(dAtA[i:], x.Beacon) + i = runtime.EncodeVarint(dAtA, i, uint64(len(x.Beacon))) + i-- + dAtA[i] = 0x2a + } if x.EnableErc20 { i-- if x.EnableErc20 { @@ -1470,6 +1502,38 @@ func (x *fastReflection_Params) ProtoMethods() *protoiface.Methods { } } x.EnableErc20 = bool(v != 0) + case 5: + if wireType != 2 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Beacon", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if postIndex > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + x.Beacon = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex default: iNdEx = preIndex skippy, err := runtime.Skip(dAtA[iNdEx:]) @@ -1628,6 +1692,7 @@ type Params struct { IssueTokenBaseFee *v1beta1.Coin `protobuf:"bytes,2,opt,name=issue_token_base_fee,json=issueTokenBaseFee,proto3" json:"issue_token_base_fee,omitempty"` MintTokenFeeRatio string `protobuf:"bytes,3,opt,name=mint_token_fee_ratio,json=mintTokenFeeRatio,proto3" json:"mint_token_fee_ratio,omitempty"` EnableErc20 bool `protobuf:"varint,4,opt,name=enable_erc20,json=enableErc20,proto3" json:"enable_erc20,omitempty"` + Beacon string `protobuf:"bytes,5,opt,name=beacon,proto3" json:"beacon,omitempty"` } func (x *Params) Reset() { @@ -1678,6 +1743,13 @@ func (x *Params) GetEnableErc20() bool { return false } +func (x *Params) GetBeacon() string { + if x != nil { + return x.Beacon + } + return "" +} + var File_irismod_token_v1_token_proto protoreflect.FileDescriptor var file_irismod_token_v1_token_proto_rawDesc = []byte{ @@ -1703,7 +1775,7 @@ var file_irismod_token_v1_token_proto_rawDesc = []byte{ 0x14, 0x0a, 0x05, 0x6f, 0x77, 0x6e, 0x65, 0x72, 0x18, 0x08, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x6f, 0x77, 0x6e, 0x65, 0x72, 0x12, 0x1a, 0x0a, 0x08, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x61, 0x63, 0x74, 0x18, 0x09, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x61, 0x63, - 0x74, 0x3a, 0x04, 0x88, 0xa0, 0x1f, 0x00, 0x22, 0xba, 0x02, 0x0a, 0x06, 0x50, 0x61, 0x72, 0x61, + 0x74, 0x3a, 0x04, 0x88, 0xa0, 0x1f, 0x00, 0x22, 0xd2, 0x02, 0x0a, 0x06, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x12, 0x54, 0x0a, 0x0e, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x5f, 0x74, 0x61, 0x78, 0x5f, 0x72, 0x61, 0x74, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x42, 0x2e, 0xc8, 0xde, 0x1f, 0x00, 0xda, 0xde, 0x1f, 0x26, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x63, @@ -1722,20 +1794,22 @@ var file_irismod_token_v1_token_proto_rawDesc = []byte{ 0x79, 0x70, 0x65, 0x73, 0x2e, 0x44, 0x65, 0x63, 0x52, 0x11, 0x6d, 0x69, 0x6e, 0x74, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x46, 0x65, 0x65, 0x52, 0x61, 0x74, 0x69, 0x6f, 0x12, 0x21, 0x0a, 0x0c, 0x65, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x5f, 0x65, 0x72, 0x63, 0x32, 0x30, 0x18, 0x04, 0x20, 0x01, 0x28, - 0x08, 0x52, 0x0b, 0x65, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x45, 0x72, 0x63, 0x32, 0x30, 0x3a, 0x04, - 0xe8, 0xa0, 0x1f, 0x01, 0x42, 0xc1, 0x01, 0xc8, 0xe1, 0x1e, 0x00, 0x0a, 0x14, 0x63, 0x6f, 0x6d, - 0x2e, 0x69, 0x72, 0x69, 0x73, 0x6d, 0x6f, 0x64, 0x2e, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x2e, 0x76, - 0x31, 0x42, 0x0a, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, - 0x37, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x69, 0x72, 0x69, 0x73, - 0x6e, 0x65, 0x74, 0x2f, 0x69, 0x72, 0x69, 0x73, 0x6d, 0x6f, 0x64, 0x2f, 0x61, 0x70, 0x69, 0x2f, - 0x69, 0x72, 0x69, 0x73, 0x6d, 0x6f, 0x64, 0x2f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x2f, 0x76, 0x31, - 0x3b, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x76, 0x31, 0xa2, 0x02, 0x03, 0x49, 0x54, 0x58, 0xaa, 0x02, - 0x10, 0x49, 0x72, 0x69, 0x73, 0x6d, 0x6f, 0x64, 0x2e, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x2e, 0x56, - 0x31, 0xca, 0x02, 0x10, 0x49, 0x72, 0x69, 0x73, 0x6d, 0x6f, 0x64, 0x5c, 0x54, 0x6f, 0x6b, 0x65, - 0x6e, 0x5c, 0x56, 0x31, 0xe2, 0x02, 0x1c, 0x49, 0x72, 0x69, 0x73, 0x6d, 0x6f, 0x64, 0x5c, 0x54, - 0x6f, 0x6b, 0x65, 0x6e, 0x5c, 0x56, 0x31, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, - 0x61, 0x74, 0x61, 0xea, 0x02, 0x12, 0x49, 0x72, 0x69, 0x73, 0x6d, 0x6f, 0x64, 0x3a, 0x3a, 0x54, - 0x6f, 0x6b, 0x65, 0x6e, 0x3a, 0x3a, 0x56, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x08, 0x52, 0x0b, 0x65, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x45, 0x72, 0x63, 0x32, 0x30, 0x12, 0x16, + 0x0a, 0x06, 0x62, 0x65, 0x61, 0x63, 0x6f, 0x6e, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, + 0x62, 0x65, 0x61, 0x63, 0x6f, 0x6e, 0x3a, 0x04, 0xe8, 0xa0, 0x1f, 0x01, 0x42, 0xc1, 0x01, 0xc8, + 0xe1, 0x1e, 0x00, 0x0a, 0x14, 0x63, 0x6f, 0x6d, 0x2e, 0x69, 0x72, 0x69, 0x73, 0x6d, 0x6f, 0x64, + 0x2e, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x2e, 0x76, 0x31, 0x42, 0x0a, 0x54, 0x6f, 0x6b, 0x65, 0x6e, + 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x37, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, + 0x63, 0x6f, 0x6d, 0x2f, 0x69, 0x72, 0x69, 0x73, 0x6e, 0x65, 0x74, 0x2f, 0x69, 0x72, 0x69, 0x73, + 0x6d, 0x6f, 0x64, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x69, 0x72, 0x69, 0x73, 0x6d, 0x6f, 0x64, 0x2f, + 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x2f, 0x76, 0x31, 0x3b, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x76, 0x31, + 0xa2, 0x02, 0x03, 0x49, 0x54, 0x58, 0xaa, 0x02, 0x10, 0x49, 0x72, 0x69, 0x73, 0x6d, 0x6f, 0x64, + 0x2e, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x2e, 0x56, 0x31, 0xca, 0x02, 0x10, 0x49, 0x72, 0x69, 0x73, + 0x6d, 0x6f, 0x64, 0x5c, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x5c, 0x56, 0x31, 0xe2, 0x02, 0x1c, 0x49, + 0x72, 0x69, 0x73, 0x6d, 0x6f, 0x64, 0x5c, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x5c, 0x56, 0x31, 0x5c, + 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x12, 0x49, 0x72, + 0x69, 0x73, 0x6d, 0x6f, 0x64, 0x3a, 0x3a, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x3a, 0x3a, 0x56, 0x31, + 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/modules/token/simulation/genesis.go b/modules/token/simulation/genesis.go index 82c080b0..eadb1dea 100644 --- a/modules/token/simulation/genesis.go +++ b/modules/token/simulation/genesis.go @@ -19,7 +19,7 @@ const ( TokenTaxRate = "token_tax_rate" IssueTokenBaseFee = "issue_token_base_fee" MintTokenFeeRatio = "mint_token_fee_ratio" - EnableErc20 = "enable_erc20" + EnableErc20 = "enable_erc20" ) // RandomDec randomized sdk.RandomDec @@ -34,7 +34,6 @@ func RandomInt(r *rand.Rand) sdk.Int { // RandomizedGenState generates a random GenesisState for bank func RandomizedGenState(simState *module.SimulationState) { - var tokenTaxRate sdk.Dec var issueTokenBaseFee sdk.Int var mintTokenFeeRatio sdk.Dec @@ -65,13 +64,13 @@ func RandomizedGenState(simState *module.SimulationState) { simState.AppParams.GetOrGenerate( simState.Cdc, EnableErc20, &enableErc20, simState.Rand, - func(r *rand.Rand) { + func(r *rand.Rand) { enableErc20 = true - }, + }, ) tokenGenesis := v1.NewGenesisState( - v1.NewParams(tokenTaxRate, sdk.NewCoin(sdk.DefaultBondDenom, issueTokenBaseFee), mintTokenFeeRatio,enableErc20), + v1.NewParams(tokenTaxRate, sdk.NewCoin(sdk.DefaultBondDenom, issueTokenBaseFee), mintTokenFeeRatio, enableErc20, ""), tokens, ) diff --git a/modules/token/types/v1/params.go b/modules/token/types/v1/params.go index cf89e48d..7cfe3d35 100644 --- a/modules/token/types/v1/params.go +++ b/modules/token/types/v1/params.go @@ -3,18 +3,22 @@ package v1 import ( "fmt" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/ethereum/go-ethereum/common" ) // NewParams constructs a new Params instance func NewParams(tokenTaxRate sdk.Dec, issueTokenBaseFee sdk.Coin, - mintTokenFeeRatio sdk.Dec, enableErc20 bool, + mintTokenFeeRatio sdk.Dec, enableErc20 bool, beacon string, ) Params { return Params{ TokenTaxRate: tokenTaxRate, IssueTokenBaseFee: issueTokenBaseFee, MintTokenFeeRatio: mintTokenFeeRatio, EnableErc20: enableErc20, + Beacon: beacon, } } @@ -40,8 +44,7 @@ func (p Params) Validate() error { if err := validateIssueTokenBaseFee(p.IssueTokenBaseFee); err != nil { return err } - - return nil + return validateBeacon(p.Beacon) } func validateTaxRate(i interface{}) error { @@ -77,3 +80,17 @@ func validateIssueTokenBaseFee(i interface{}) error { } return nil } + +func validateBeacon(i interface{}) error { + v, ok := i.(string) + if !ok { + return fmt.Errorf("invalid parameter type: %T", i) + } + if len(v) == 0 { + return nil + } + if !common.IsHexAddress(v) { + return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "beacon expecting a hex address, got %s", v) + } + return nil +} diff --git a/modules/token/types/v1/token.pb.go b/modules/token/types/v1/token.pb.go index ecdab375..bf08409e 100644 --- a/modules/token/types/v1/token.pb.go +++ b/modules/token/types/v1/token.pb.go @@ -77,6 +77,7 @@ type Params struct { IssueTokenBaseFee types.Coin `protobuf:"bytes,2,opt,name=issue_token_base_fee,json=issueTokenBaseFee,proto3" json:"issue_token_base_fee"` MintTokenFeeRatio github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,3,opt,name=mint_token_fee_ratio,json=mintTokenFeeRatio,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"mint_token_fee_ratio"` EnableErc20 bool `protobuf:"varint,4,opt,name=enable_erc20,json=enableErc20,proto3" json:"enable_erc20,omitempty"` + Beacon string `protobuf:"bytes,5,opt,name=beacon,proto3" json:"beacon,omitempty"` } func (m *Params) Reset() { *m = Params{} } @@ -120,39 +121,39 @@ func init() { func init() { proto.RegisterFile("irismod/token/v1/token.proto", fileDescriptor_c5b3436d30fd508a) } var fileDescriptor_c5b3436d30fd508a = []byte{ - // 502 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x52, 0xcd, 0x6e, 0xd3, 0x40, - 0x10, 0xf6, 0x16, 0x27, 0x4d, 0xb6, 0x3f, 0xa2, 0xab, 0x08, 0xb9, 0x11, 0x38, 0xa1, 0x12, 0x28, - 0x17, 0x6c, 0x5c, 0x6e, 0x3d, 0x06, 0xe8, 0x95, 0xca, 0x84, 0x0b, 0x17, 0x6b, 0xed, 0x4c, 0xc3, - 0xaa, 0xde, 0xdd, 0xc8, 0xbb, 0x0e, 0xc9, 0x1b, 0x70, 0xe4, 0x11, 0xfa, 0x1c, 0x3c, 0x41, 0x8e, - 0x3d, 0x22, 0x0e, 0x15, 0x24, 0x17, 0x9e, 0x02, 0xa1, 0xdd, 0x75, 0x2b, 0xae, 0x9c, 0x3c, 0xf3, - 0xed, 0xcc, 0x37, 0xe3, 0xf9, 0x3e, 0xfc, 0x98, 0x55, 0x4c, 0x71, 0x39, 0x8d, 0xb5, 0xbc, 0x02, - 0x11, 0x2f, 0x12, 0x17, 0x44, 0xf3, 0x4a, 0x6a, 0x49, 0x1e, 0x36, 0xaf, 0x91, 0x03, 0x17, 0x49, - 0x3f, 0x2c, 0xa4, 0xe2, 0x52, 0xc5, 0x39, 0x55, 0x10, 0x2f, 0x92, 0x1c, 0x34, 0x4d, 0xe2, 0x42, - 0xb2, 0xa6, 0xa3, 0x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0x24, 0x09, 0xfd, 0x02, 0x00, 0x00, + // 511 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x52, 0xcb, 0x6e, 0xd3, 0x40, + 0x14, 0xb5, 0x8b, 0x93, 0x26, 0xd3, 0x87, 0xe8, 0x28, 0x42, 0x6e, 0x04, 0x4e, 0xa8, 0x04, 0xca, + 0x06, 0x9b, 0x94, 0x5d, 0x97, 0x01, 0xba, 0xa5, 0x1a, 0xc2, 0x86, 0x8d, 0x35, 0x76, 0x6e, 0xc3, + 0xa8, 0x9e, 0x99, 0xc8, 0x33, 0x09, 0xc9, 0x1f, 0xb0, 0xe4, 0x13, 0xfa, 0x39, 0x59, 0x56, 0xac, + 0x10, 0x8b, 0x0a, 0x92, 0x0d, 0x5f, 0x81, 0xd0, 0x3c, 0x5a, 0xb1, 0x65, 0xe5, 0x7b, 0xce, 0xcc, + 0x9c, 0x7b, 0x7d, 0xcf, 0x41, 0x8f, 0x59, 0xcd, 0x14, 0x97, 0x93, 0x4c, 0xcb, 0x2b, 0x10, 0xd9, + 0x62, 0xe8, 0x8a, 0x74, 0x56, 0x4b, 0x2d, 0xf1, 0x43, 0x7f, 0x9a, 0x3a, 0x72, 0x31, 0xec, 0x26, + 0xa5, 0x54, 0x5c, 0xaa, 0xac, 0xa0, 0x0a, 0xb2, 0xc5, 0xb0, 0x00, 0x4d, 0x87, 0x59, 0x29, 0x99, + 0x7f, 0xd1, 0xed, 0x4c, 0xe5, 0x54, 0xda, 0x32, 0x33, 0x95, 0x63, 0x4f, 0xfe, 0x84, 0xa8, 0x31, + 0x36, 0x12, 0xf8, 0x11, 0x6a, 0xaa, 0x15, 0x2f, 0x64, 0x15, 0x87, 0xfd, 0x70, 0xd0, 0x26, 0x1e, + 0x61, 0x8c, 0x22, 0x41, 0x39, 0xc4, 0x3b, 0x96, 0xb5, 0x35, 0xee, 0xa0, 0x86, 0x2a, 0x69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0xb8, 0x7d, 0xee, 0x9d, 0x1e, 0xa7, 0x4e, 0x22, 0x35, 0x7c, 0xea, 0x6d, 0x4b, + 0x5f, 0x4b, 0x26, 0x46, 0x91, 0x69, 0x4b, 0x8e, 0xec, 0x63, 0x6b, 0xd1, 0x88, 0x2a, 0x38, 0x07, + 0xc0, 0x39, 0xea, 0x98, 0xdf, 0xf6, 0x82, 0x97, 0x00, 0x66, 0x58, 0x26, 0xad, 0x19, 0xff, 0x3f, + 0xed, 0x91, 0xd1, 0xb2, 0xfa, 0xe7, 0x00, 0xc4, 0x08, 0xe1, 0xa7, 0x68, 0x1f, 0x84, 0xd9, 0x6a, + 0x0e, 0x75, 0x79, 0xfa, 0xd2, 0x9a, 0xd9, 0x22, 0x7b, 0x8e, 0x7b, 0x6b, 0x28, 0x93, 0x96, 0x02, + 0x68, 0x29, 0x85, 0x35, 0xb2, 0x4d, 0x3c, 0x3a, 0x8b, 0x7e, 0x5f, 0xf7, 0xc2, 0xd1, 0xbb, 0xf5, + 0xaf, 0x24, 0x58, 0x6f, 0x92, 0xf0, 0x66, 0x93, 0x84, 0x3f, 0x37, 0x49, 0xf8, 0x75, 0x9b, 0x04, + 0x37, 0xdb, 0x24, 0xf8, 0xbe, 0x4d, 0x82, 0x8f, 0xc3, 0x7f, 0x26, 0x33, 0x31, 0x16, 0xa0, 0xb3, + 0xbb, 0xb0, 0x73, 0x39, 0x99, 0x57, 0xa0, 0x7c, 0xe8, 0xed, 0x94, 0x26, 0xcc, 0x4d, 0x9b, 0xd6, + 0x57, 0x7f, 0x03, 0x00, 0x00, 0xff, 0xff, 0x94, 0x92, 0x51, 0xfb, 0x15, 0x03, 0x00, 0x00, } func (this *Params) Equal(that interface{}) bool { @@ -186,6 +187,9 @@ func (this *Params) Equal(that interface{}) bool { if this.EnableErc20 != that1.EnableErc20 { return false } + if this.Beacon != that1.Beacon { + return false + } return true } func (m *Token) Marshal() (dAtA []byte, err error) { @@ -291,6 +295,13 @@ func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if len(m.Beacon) > 0 { + i -= len(m.Beacon) + copy(dAtA[i:], m.Beacon) + i = encodeVarintToken(dAtA, i, uint64(len(m.Beacon))) + i-- + dAtA[i] = 0x2a + } if m.EnableErc20 { i-- if m.EnableErc20 { @@ -401,6 +412,10 @@ func (m *Params) Size() (n int) { if m.EnableErc20 { n += 2 } + l = len(m.Beacon) + if l > 0 { + n += 1 + l + sovToken(uint64(l)) + } return n } @@ -847,6 +862,38 @@ func (m *Params) Unmarshal(dAtA []byte) error { } } m.EnableErc20 = bool(v != 0) + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Beacon", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowToken + } + 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 ErrInvalidLengthToken + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthToken + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Beacon = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipToken(dAtA[iNdEx:]) diff --git a/proto/irismod/token/v1/token.proto b/proto/irismod/token/v1/token.proto index 7087e684..4c202201 100644 --- a/proto/irismod/token/v1/token.proto +++ b/proto/irismod/token/v1/token.proto @@ -40,4 +40,5 @@ message Params { ]; bool enable_erc20 = 4; + string beacon = 5; } \ No newline at end of file From 8fb202631fd9f3ead9de6b6b4460ca64b4b4220f Mon Sep 17 00:00:00 2001 From: dreamer Date: Mon, 22 Apr 2024 11:32:41 +0800 Subject: [PATCH 3/7] deploy TokenProxy contract --- contracts/erc20.go | 1 + modules/token/keeper/erc20.go | 38 ++++++++++++++++++++++++++--------- modules/token/types/errors.go | 1 + 3 files changed, 31 insertions(+), 9 deletions(-) diff --git a/contracts/erc20.go b/contracts/erc20.go index 068996f2..a564000c 100644 --- a/contracts/erc20.go +++ b/contracts/erc20.go @@ -12,6 +12,7 @@ const ( MethodMint = "mint" MethodBurn = "burn" MethodBalanceOf = "balanceOf" + MethodInitialize = "initialize" ) var ( diff --git a/modules/token/keeper/erc20.go b/modules/token/keeper/erc20.go index 8e06cb22..041f1801 100644 --- a/modules/token/keeper/erc20.go +++ b/modules/token/keeper/erc20.go @@ -42,20 +42,40 @@ func (k Keeper) DeployERC20( return common.Address{}, errorsmod.Wrapf(types.ErrERC20AlreadyExists, "token: %s already deployed erc20 contract: %s", token.Symbol, token.Contract) } - contractArgs, err := contracts.ERC20TokenContract.ABI.Pack( - "", + params := k.GetParams(ctx) + if !params.EnableErc20 { + return common.Address{}, errorsmod.Wrapf(types.ErrERC20Disabled, "ERC20 is disabled") + } + + if len(params.Beacon) == 0 { + return common.Address{}, errorsmod.Wrapf(types.ErrBeaconNotSet, "beacon not set") + } + + deployer := k.getModuleEthAddress(ctx) + + initArgs, err := contracts.ERC20TokenContract.ABI.Pack( + contracts.MethodInitialize, name, symbol, scale, + deployer, + ) + if err != nil { + return common.Address{}, err + } + + contractArgs, err := contracts.TokenProxyContract.ABI.Pack( + "", + params.Beacon, + initArgs, ) if err != nil { return common.Address{}, errorsmod.Wrapf(types.ErrABIPack, "erc20 metadata is invalid %s: %s", name, err.Error()) } - deployer := k.getModuleEthAddress(ctx) - data := make([]byte, len(contracts.ERC20TokenContract.Bin)+len(contractArgs)) - copy(data[:len(contracts.ERC20TokenContract.Bin)], contracts.ERC20TokenContract.Bin) - copy(data[len(contracts.ERC20TokenContract.Bin):], contractArgs) + data := make([]byte, len(contracts.TokenProxyContract.Bin)+len(contractArgs)) + copy(data[:len(contracts.TokenProxyContract.Bin)], contracts.TokenProxyContract.Bin) + copy(data[len(contracts.TokenProxyContract.Bin):], contractArgs) nonce, err := k.accountKeeper.GetSequence(ctx, sdk.AccAddress(deployer.Bytes())) if err != nil { @@ -102,7 +122,7 @@ func (k Keeper) SwapFromERC20( if !k.ERC20Enabled(ctx) { return types.ErrERC20Disabled } - + token, err := k.getTokenByMinUnit(ctx, wantedAmount.Denom) if err != nil { return err @@ -153,7 +173,7 @@ func (k Keeper) SwapToERC20( if !k.ERC20Enabled(ctx) { return types.ErrERC20Disabled } - + receiverAcc := k.accountKeeper.GetAccount(ctx, sdk.AccAddress(receiver.Bytes())) if receiverAcc != nil { if !k.evmKeeper.SupportedKey(receiverAcc.GetPubKey()) { @@ -329,7 +349,7 @@ func (k Keeper) BalanceOf( } func (k Keeper) getModuleEthAddress(ctx sdk.Context) common.Address { - moduleAccount := k.accountKeeper.GetModuleAccount(ctx,types.ModuleName) + moduleAccount := k.accountKeeper.GetModuleAccount(ctx, types.ModuleName) return common.BytesToAddress(moduleAccount.GetAddress().Bytes()) } diff --git a/modules/token/types/errors.go b/modules/token/types/errors.go index f4183615..407d8f88 100644 --- a/modules/token/types/errors.go +++ b/modules/token/types/errors.go @@ -32,4 +32,5 @@ var ( ErrUnsupportedKey = errorsmod.Register(ModuleName, 24, "evm not supported public key") ErrInvalidContract = errorsmod.Register(ModuleName, 25, "invalid contract") ErrERC20Disabled = errorsmod.Register(ModuleName, 26, "erc20 swap is disabled") + ErrBeaconNotSet = errorsmod.Register(ModuleName, 27, "beacon contract not set") ) From 2dfd446b5c6e16bd7f2b77211c23d49de59806fc Mon Sep 17 00:00:00 2001 From: dreamer Date: Mon, 22 Apr 2024 11:51:03 +0800 Subject: [PATCH 4/7] fix test error --- modules/token/keeper/erc20.go | 2 +- modules/token/keeper/keeper_test.go | 6 +++++- simapp/mocks/evm.go | 18 +++++++++++++----- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/modules/token/keeper/erc20.go b/modules/token/keeper/erc20.go index 041f1801..b08d1c0b 100644 --- a/modules/token/keeper/erc20.go +++ b/modules/token/keeper/erc20.go @@ -66,7 +66,7 @@ func (k Keeper) DeployERC20( contractArgs, err := contracts.TokenProxyContract.ABI.Pack( "", - params.Beacon, + common.HexToAddress(params.Beacon), initArgs, ) if err != nil { diff --git a/modules/token/keeper/keeper_test.go b/modules/token/keeper/keeper_test.go index 4e64887d..4aa47516 100644 --- a/modules/token/keeper/keeper_test.go +++ b/modules/token/keeper/keeper_test.go @@ -3,6 +3,7 @@ package keeper_test import ( "testing" + "github.com/ethereum/go-ethereum/common" "github.com/stretchr/testify/suite" "github.com/cometbft/cometbft/crypto/tmhash" @@ -29,6 +30,7 @@ var ( add2 = sdk.AccAddress(tmhash.SumTruncated([]byte("tokenTest1"))) initAmt = sdkmath.NewIntWithDecimal(100000000, int(6)) initCoin = sdk.Coins{sdk.NewCoin(denom, initAmt)} + beacon = common.BytesToAddress(owner.Bytes()) ) type KeeperTestSuite struct { @@ -51,7 +53,9 @@ func (suite *KeeperTestSuite) SetupTest() { suite.app = app // set params - suite.keeper.SetParams(suite.ctx, v1.DefaultParams()) + params := v1.DefaultParams() + params.Beacon = beacon.String() + suite.keeper.SetParams(suite.ctx, params) // init tokens to addr err := suite.bk.MintCoins(suite.ctx, types.ModuleName, initCoin) diff --git a/simapp/mocks/evm.go b/simapp/mocks/evm.go index 89638e56..89e6fc8b 100644 --- a/simapp/mocks/evm.go +++ b/simapp/mocks/evm.go @@ -34,14 +34,22 @@ func (e *evm) ApplyMessage(ctx sdk.Context, msg core.Message, tracer vm.EVMLogge if isCreate { contractAddr := crypto.CreateAddress(msg.From(), msg.Nonce()) - data := msg.Data()[len(contracts.ERC20TokenContract.Bin):] - argss, err := contracts.ERC20TokenContract.ABI.Constructor.Inputs.Unpack(data) + data := msg.Data()[len(contracts.TokenProxyContract.Bin):] + args, err := contracts.TokenProxyContract.ABI.Constructor.Inputs.Unpack(data) if err != nil { return nil, err } - name, _ := argss[0].(string) - symbol, _ := argss[1].(string) - scale, _ := argss[2].(uint8) + + data = args[1].([]byte) + data = data[4:] + args, err = contracts.ERC20TokenContract.ABI.Methods[contracts.MethodInitialize].Inputs.Unpack(data) + if err != nil { + return nil, err + } + + name, _ := args[0].(string) + symbol, _ := args[1].(string) + scale, _ := args[2].(uint8) e.erc20s[contractAddr] = &erc20{ address: contractAddr, scale: scale, From d5cc5fea0f2aaa95e4ce5ac64c04cb02ef68cd23 Mon Sep 17 00:00:00 2001 From: dreamer Date: Mon, 22 Apr 2024 13:57:16 +0800 Subject: [PATCH 5/7] implement UpgradeERC20 --- Makefile | 3 +- api/irismod/token/v1/tx.pulsar.go | 1140 +++++++++++++++-- api/irismod/token/v1/tx_grpc.pb.go | 39 + .../compiled_contracts/UpgradeableBeacon.json | 145 +++ contracts/erc20.go | 12 + modules/token/keeper/erc20.go | 38 +- modules/token/keeper/msg_server.go | 19 + modules/token/types/v1/tx.pb.go | 500 +++++++- proto/irismod/token/v1/tx.proto | 17 +- 9 files changed, 1753 insertions(+), 160 deletions(-) create mode 100644 contracts/compiled_contracts/UpgradeableBeacon.json diff --git a/Makefile b/Makefile index 628d62d8..63d8efc6 100644 --- a/Makefile +++ b/Makefile @@ -144,6 +144,7 @@ contracts-clean: # Compile, filter out and format contracts into the following format. create-contracts-abi: solc --combined-json abi,bin --evm-version paris --include-path node_modules --base-path $(CONTRACTS_DIR)/ $(CONTRACTS_DIR)/Token.sol | jq '.contracts["Token.sol:Token"]' > $(COMPILED_DIR)/Token.json \ - && solc --combined-json abi,bin --evm-version paris --include-path node_modules --base-path $(CONTRACTS_DIR)/ $(CONTRACTS_DIR)/TokenProxy.sol | jq '.contracts["TokenProxy.sol:TokenProxy"]' > $(COMPILED_DIR)/TokenProxy.json + && solc --combined-json abi,bin --evm-version paris --include-path node_modules --base-path $(CONTRACTS_DIR)/ $(CONTRACTS_DIR)/TokenProxy.sol | jq '.contracts["TokenProxy.sol:TokenProxy"]' > $(COMPILED_DIR)/TokenProxy.json \ + && solc --combined-json abi,bin --evm-version paris --include-path node_modules --base-path $(CONTRACTS_DIR)/ $(CONTRACTS_DIR)/UpgradeableBeacon.sol | jq '.contracts["UpgradeableBeacon.sol:UpgradeableBeacon"]' > $(COMPILED_DIR)/UpgradeableBeacon.json \ diff --git a/api/irismod/token/v1/tx.pulsar.go b/api/irismod/token/v1/tx.pulsar.go index bec8f041..199ff332 100644 --- a/api/irismod/token/v1/tx.pulsar.go +++ b/api/irismod/token/v1/tx.pulsar.go @@ -9583,6 +9583,846 @@ func (x *fastReflection_MsgSwapFromERC20Response) ProtoMethods() *protoiface.Met } } +var ( + md_MsgUpgradeERC20 protoreflect.MessageDescriptor + fd_MsgUpgradeERC20_implementation protoreflect.FieldDescriptor + fd_MsgUpgradeERC20_authority protoreflect.FieldDescriptor +) + +func init() { + file_irismod_token_v1_tx_proto_init() + md_MsgUpgradeERC20 = File_irismod_token_v1_tx_proto.Messages().ByName("MsgUpgradeERC20") + fd_MsgUpgradeERC20_implementation = md_MsgUpgradeERC20.Fields().ByName("implementation") + fd_MsgUpgradeERC20_authority = md_MsgUpgradeERC20.Fields().ByName("authority") +} + +var _ protoreflect.Message = (*fastReflection_MsgUpgradeERC20)(nil) + +type fastReflection_MsgUpgradeERC20 MsgUpgradeERC20 + +func (x *MsgUpgradeERC20) ProtoReflect() protoreflect.Message { + return (*fastReflection_MsgUpgradeERC20)(x) +} + +func (x *MsgUpgradeERC20) slowProtoReflect() protoreflect.Message { + mi := &file_irismod_token_v1_tx_proto_msgTypes[20] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +var _fastReflection_MsgUpgradeERC20_messageType fastReflection_MsgUpgradeERC20_messageType +var _ protoreflect.MessageType = fastReflection_MsgUpgradeERC20_messageType{} + +type fastReflection_MsgUpgradeERC20_messageType struct{} + +func (x fastReflection_MsgUpgradeERC20_messageType) Zero() protoreflect.Message { + return (*fastReflection_MsgUpgradeERC20)(nil) +} +func (x fastReflection_MsgUpgradeERC20_messageType) New() protoreflect.Message { + return new(fastReflection_MsgUpgradeERC20) +} +func (x fastReflection_MsgUpgradeERC20_messageType) Descriptor() protoreflect.MessageDescriptor { + return md_MsgUpgradeERC20 +} + +// Descriptor returns message descriptor, which contains only the protobuf +// type information for the message. +func (x *fastReflection_MsgUpgradeERC20) Descriptor() protoreflect.MessageDescriptor { + return md_MsgUpgradeERC20 +} + +// Type returns the message type, which encapsulates both Go and protobuf +// type information. If the Go type information is not needed, +// it is recommended that the message descriptor be used instead. +func (x *fastReflection_MsgUpgradeERC20) Type() protoreflect.MessageType { + return _fastReflection_MsgUpgradeERC20_messageType +} + +// New returns a newly allocated and mutable empty message. +func (x *fastReflection_MsgUpgradeERC20) New() protoreflect.Message { + return new(fastReflection_MsgUpgradeERC20) +} + +// Interface unwraps the message reflection interface and +// returns the underlying ProtoMessage interface. +func (x *fastReflection_MsgUpgradeERC20) Interface() protoreflect.ProtoMessage { + return (*MsgUpgradeERC20)(x) +} + +// Range iterates over every populated field in an undefined order, +// calling f for each field descriptor and value encountered. +// Range returns immediately if f returns false. +// While iterating, mutating operations may only be performed +// on the current field descriptor. +func (x *fastReflection_MsgUpgradeERC20) Range(f func(protoreflect.FieldDescriptor, protoreflect.Value) bool) { + if x.Implementation != "" { + value := protoreflect.ValueOfString(x.Implementation) + if !f(fd_MsgUpgradeERC20_implementation, value) { + return + } + } + if x.Authority != "" { + value := protoreflect.ValueOfString(x.Authority) + if !f(fd_MsgUpgradeERC20_authority, value) { + return + } + } +} + +// Has reports whether a field is populated. +// +// Some fields have the property of nullability where it is possible to +// distinguish between the default value of a field and whether the field +// was explicitly populated with the default value. Singular message fields, +// member fields of a oneof, and proto2 scalar fields are nullable. Such +// fields are populated only if explicitly set. +// +// In other cases (aside from the nullable cases above), +// a proto3 scalar field is populated if it contains a non-zero value, and +// a repeated field is populated if it is non-empty. +func (x *fastReflection_MsgUpgradeERC20) Has(fd protoreflect.FieldDescriptor) bool { + switch fd.FullName() { + case "irismod.token.v1.MsgUpgradeERC20.implementation": + return x.Implementation != "" + case "irismod.token.v1.MsgUpgradeERC20.authority": + return x.Authority != "" + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: irismod.token.v1.MsgUpgradeERC20")) + } + panic(fmt.Errorf("message irismod.token.v1.MsgUpgradeERC20 does not contain field %s", fd.FullName())) + } +} + +// Clear clears the field such that a subsequent Has call reports false. +// +// Clearing an extension field clears both the extension type and value +// associated with the given field number. +// +// Clear is a mutating operation and unsafe for concurrent use. +func (x *fastReflection_MsgUpgradeERC20) Clear(fd protoreflect.FieldDescriptor) { + switch fd.FullName() { + case "irismod.token.v1.MsgUpgradeERC20.implementation": + x.Implementation = "" + case "irismod.token.v1.MsgUpgradeERC20.authority": + x.Authority = "" + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: irismod.token.v1.MsgUpgradeERC20")) + } + panic(fmt.Errorf("message irismod.token.v1.MsgUpgradeERC20 does not contain field %s", fd.FullName())) + } +} + +// Get retrieves the value for a field. +// +// For unpopulated scalars, it returns the default value, where +// the default value of a bytes scalar is guaranteed to be a copy. +// For unpopulated composite types, it returns an empty, read-only view +// of the value; to obtain a mutable reference, use Mutable. +func (x *fastReflection_MsgUpgradeERC20) Get(descriptor protoreflect.FieldDescriptor) protoreflect.Value { + switch descriptor.FullName() { + case "irismod.token.v1.MsgUpgradeERC20.implementation": + value := x.Implementation + return protoreflect.ValueOfString(value) + case "irismod.token.v1.MsgUpgradeERC20.authority": + value := x.Authority + return protoreflect.ValueOfString(value) + default: + if descriptor.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: irismod.token.v1.MsgUpgradeERC20")) + } + panic(fmt.Errorf("message irismod.token.v1.MsgUpgradeERC20 does not contain field %s", descriptor.FullName())) + } +} + +// Set stores the value for a field. +// +// For a field belonging to a oneof, it implicitly clears any other field +// that may be currently set within the same oneof. +// For extension fields, it implicitly stores the provided ExtensionType. +// When setting a composite type, it is unspecified whether the stored value +// aliases the source's memory in any way. If the composite value is an +// empty, read-only value, then it panics. +// +// Set is a mutating operation and unsafe for concurrent use. +func (x *fastReflection_MsgUpgradeERC20) Set(fd protoreflect.FieldDescriptor, value protoreflect.Value) { + switch fd.FullName() { + case "irismod.token.v1.MsgUpgradeERC20.implementation": + x.Implementation = value.Interface().(string) + case "irismod.token.v1.MsgUpgradeERC20.authority": + x.Authority = value.Interface().(string) + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: irismod.token.v1.MsgUpgradeERC20")) + } + panic(fmt.Errorf("message irismod.token.v1.MsgUpgradeERC20 does not contain field %s", fd.FullName())) + } +} + +// Mutable returns a mutable reference to a composite type. +// +// If the field is unpopulated, it may allocate a composite value. +// For a field belonging to a oneof, it implicitly clears any other field +// that may be currently set within the same oneof. +// For extension fields, it implicitly stores the provided ExtensionType +// if not already stored. +// It panics if the field does not contain a composite type. +// +// Mutable is a mutating operation and unsafe for concurrent use. +func (x *fastReflection_MsgUpgradeERC20) Mutable(fd protoreflect.FieldDescriptor) protoreflect.Value { + switch fd.FullName() { + case "irismod.token.v1.MsgUpgradeERC20.implementation": + panic(fmt.Errorf("field implementation of message irismod.token.v1.MsgUpgradeERC20 is not mutable")) + case "irismod.token.v1.MsgUpgradeERC20.authority": + panic(fmt.Errorf("field authority of message irismod.token.v1.MsgUpgradeERC20 is not mutable")) + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: irismod.token.v1.MsgUpgradeERC20")) + } + panic(fmt.Errorf("message irismod.token.v1.MsgUpgradeERC20 does not contain field %s", fd.FullName())) + } +} + +// NewField returns a new value that is assignable to the field +// for the given descriptor. For scalars, this returns the default value. +// For lists, maps, and messages, this returns a new, empty, mutable value. +func (x *fastReflection_MsgUpgradeERC20) NewField(fd protoreflect.FieldDescriptor) protoreflect.Value { + switch fd.FullName() { + case "irismod.token.v1.MsgUpgradeERC20.implementation": + return protoreflect.ValueOfString("") + case "irismod.token.v1.MsgUpgradeERC20.authority": + return protoreflect.ValueOfString("") + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: irismod.token.v1.MsgUpgradeERC20")) + } + panic(fmt.Errorf("message irismod.token.v1.MsgUpgradeERC20 does not contain field %s", fd.FullName())) + } +} + +// WhichOneof reports which field within the oneof is populated, +// returning nil if none are populated. +// It panics if the oneof descriptor does not belong to this message. +func (x *fastReflection_MsgUpgradeERC20) WhichOneof(d protoreflect.OneofDescriptor) protoreflect.FieldDescriptor { + switch d.FullName() { + default: + panic(fmt.Errorf("%s is not a oneof field in irismod.token.v1.MsgUpgradeERC20", d.FullName())) + } + panic("unreachable") +} + +// GetUnknown retrieves the entire list of unknown fields. +// The caller may only mutate the contents of the RawFields +// if the mutated bytes are stored back into the message with SetUnknown. +func (x *fastReflection_MsgUpgradeERC20) GetUnknown() protoreflect.RawFields { + return x.unknownFields +} + +// SetUnknown stores an entire list of unknown fields. +// The raw fields must be syntactically valid according to the wire format. +// An implementation may panic if this is not the case. +// Once stored, the caller must not mutate the content of the RawFields. +// An empty RawFields may be passed to clear the fields. +// +// SetUnknown is a mutating operation and unsafe for concurrent use. +func (x *fastReflection_MsgUpgradeERC20) SetUnknown(fields protoreflect.RawFields) { + x.unknownFields = fields +} + +// IsValid reports whether the message is valid. +// +// An invalid message is an empty, read-only value. +// +// An invalid message often corresponds to a nil pointer of the concrete +// message type, but the details are implementation dependent. +// Validity is not part of the protobuf data model, and may not +// be preserved in marshaling or other operations. +func (x *fastReflection_MsgUpgradeERC20) IsValid() bool { + return x != nil +} + +// ProtoMethods returns optional fastReflectionFeature-path implementations of various operations. +// This method may return nil. +// +// The returned methods type is identical to +// "google.golang.org/protobuf/runtime/protoiface".Methods. +// Consult the protoiface package documentation for details. +func (x *fastReflection_MsgUpgradeERC20) ProtoMethods() *protoiface.Methods { + size := func(input protoiface.SizeInput) protoiface.SizeOutput { + x := input.Message.Interface().(*MsgUpgradeERC20) + if x == nil { + return protoiface.SizeOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Size: 0, + } + } + options := runtime.SizeInputToOptions(input) + _ = options + var n int + var l int + _ = l + l = len(x.Implementation) + if l > 0 { + n += 1 + l + runtime.Sov(uint64(l)) + } + l = len(x.Authority) + if l > 0 { + n += 1 + l + runtime.Sov(uint64(l)) + } + if x.unknownFields != nil { + n += len(x.unknownFields) + } + return protoiface.SizeOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Size: n, + } + } + + marshal := func(input protoiface.MarshalInput) (protoiface.MarshalOutput, error) { + x := input.Message.Interface().(*MsgUpgradeERC20) + if x == nil { + return protoiface.MarshalOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Buf: input.Buf, + }, nil + } + options := runtime.MarshalInputToOptions(input) + _ = options + size := options.Size(x) + dAtA := make([]byte, size) + i := len(dAtA) + _ = i + var l int + _ = l + if x.unknownFields != nil { + i -= len(x.unknownFields) + copy(dAtA[i:], x.unknownFields) + } + if len(x.Authority) > 0 { + i -= len(x.Authority) + copy(dAtA[i:], x.Authority) + i = runtime.EncodeVarint(dAtA, i, uint64(len(x.Authority))) + i-- + dAtA[i] = 0x12 + } + if len(x.Implementation) > 0 { + i -= len(x.Implementation) + copy(dAtA[i:], x.Implementation) + i = runtime.EncodeVarint(dAtA, i, uint64(len(x.Implementation))) + i-- + dAtA[i] = 0xa + } + if input.Buf != nil { + input.Buf = append(input.Buf, dAtA...) + } else { + input.Buf = dAtA + } + return protoiface.MarshalOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Buf: input.Buf, + }, nil + } + unmarshal := func(input protoiface.UnmarshalInput) (protoiface.UnmarshalOutput, error) { + x := input.Message.Interface().(*MsgUpgradeERC20) + if x == nil { + return protoiface.UnmarshalOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Flags: input.Flags, + }, nil + } + options := runtime.UnmarshalInputToOptions(input) + _ = options + dAtA := input.Buf + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, 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 protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: MsgUpgradeERC20: wiretype end group for non-group") + } + if fieldNum <= 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: MsgUpgradeERC20: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Implementation", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if postIndex > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + x.Implementation = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Authority", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if postIndex > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + x.Authority = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := runtime.Skip(dAtA[iNdEx:]) + if err != nil { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if (iNdEx + skippy) > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + if !options.DiscardUnknown { + x.unknownFields = append(x.unknownFields, dAtA[iNdEx:iNdEx+skippy]...) + } + iNdEx += skippy + } + } + + if iNdEx > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, nil + } + return &protoiface.Methods{ + NoUnkeyedLiterals: struct{}{}, + Flags: protoiface.SupportMarshalDeterministic | protoiface.SupportUnmarshalDiscardUnknown, + Size: size, + Marshal: marshal, + Unmarshal: unmarshal, + Merge: nil, + CheckInitialized: nil, + } +} + +var ( + md_MsgUpgradeERC20Response protoreflect.MessageDescriptor +) + +func init() { + file_irismod_token_v1_tx_proto_init() + md_MsgUpgradeERC20Response = File_irismod_token_v1_tx_proto.Messages().ByName("MsgUpgradeERC20Response") +} + +var _ protoreflect.Message = (*fastReflection_MsgUpgradeERC20Response)(nil) + +type fastReflection_MsgUpgradeERC20Response MsgUpgradeERC20Response + +func (x *MsgUpgradeERC20Response) ProtoReflect() protoreflect.Message { + return (*fastReflection_MsgUpgradeERC20Response)(x) +} + +func (x *MsgUpgradeERC20Response) slowProtoReflect() protoreflect.Message { + mi := &file_irismod_token_v1_tx_proto_msgTypes[21] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +var _fastReflection_MsgUpgradeERC20Response_messageType fastReflection_MsgUpgradeERC20Response_messageType +var _ protoreflect.MessageType = fastReflection_MsgUpgradeERC20Response_messageType{} + +type fastReflection_MsgUpgradeERC20Response_messageType struct{} + +func (x fastReflection_MsgUpgradeERC20Response_messageType) Zero() protoreflect.Message { + return (*fastReflection_MsgUpgradeERC20Response)(nil) +} +func (x fastReflection_MsgUpgradeERC20Response_messageType) New() protoreflect.Message { + return new(fastReflection_MsgUpgradeERC20Response) +} +func (x fastReflection_MsgUpgradeERC20Response_messageType) Descriptor() protoreflect.MessageDescriptor { + return md_MsgUpgradeERC20Response +} + +// Descriptor returns message descriptor, which contains only the protobuf +// type information for the message. +func (x *fastReflection_MsgUpgradeERC20Response) Descriptor() protoreflect.MessageDescriptor { + return md_MsgUpgradeERC20Response +} + +// Type returns the message type, which encapsulates both Go and protobuf +// type information. If the Go type information is not needed, +// it is recommended that the message descriptor be used instead. +func (x *fastReflection_MsgUpgradeERC20Response) Type() protoreflect.MessageType { + return _fastReflection_MsgUpgradeERC20Response_messageType +} + +// New returns a newly allocated and mutable empty message. +func (x *fastReflection_MsgUpgradeERC20Response) New() protoreflect.Message { + return new(fastReflection_MsgUpgradeERC20Response) +} + +// Interface unwraps the message reflection interface and +// returns the underlying ProtoMessage interface. +func (x *fastReflection_MsgUpgradeERC20Response) Interface() protoreflect.ProtoMessage { + return (*MsgUpgradeERC20Response)(x) +} + +// Range iterates over every populated field in an undefined order, +// calling f for each field descriptor and value encountered. +// Range returns immediately if f returns false. +// While iterating, mutating operations may only be performed +// on the current field descriptor. +func (x *fastReflection_MsgUpgradeERC20Response) Range(f func(protoreflect.FieldDescriptor, protoreflect.Value) bool) { +} + +// Has reports whether a field is populated. +// +// Some fields have the property of nullability where it is possible to +// distinguish between the default value of a field and whether the field +// was explicitly populated with the default value. Singular message fields, +// member fields of a oneof, and proto2 scalar fields are nullable. Such +// fields are populated only if explicitly set. +// +// In other cases (aside from the nullable cases above), +// a proto3 scalar field is populated if it contains a non-zero value, and +// a repeated field is populated if it is non-empty. +func (x *fastReflection_MsgUpgradeERC20Response) Has(fd protoreflect.FieldDescriptor) bool { + switch fd.FullName() { + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: irismod.token.v1.MsgUpgradeERC20Response")) + } + panic(fmt.Errorf("message irismod.token.v1.MsgUpgradeERC20Response does not contain field %s", fd.FullName())) + } +} + +// Clear clears the field such that a subsequent Has call reports false. +// +// Clearing an extension field clears both the extension type and value +// associated with the given field number. +// +// Clear is a mutating operation and unsafe for concurrent use. +func (x *fastReflection_MsgUpgradeERC20Response) Clear(fd protoreflect.FieldDescriptor) { + switch fd.FullName() { + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: irismod.token.v1.MsgUpgradeERC20Response")) + } + panic(fmt.Errorf("message irismod.token.v1.MsgUpgradeERC20Response does not contain field %s", fd.FullName())) + } +} + +// Get retrieves the value for a field. +// +// For unpopulated scalars, it returns the default value, where +// the default value of a bytes scalar is guaranteed to be a copy. +// For unpopulated composite types, it returns an empty, read-only view +// of the value; to obtain a mutable reference, use Mutable. +func (x *fastReflection_MsgUpgradeERC20Response) Get(descriptor protoreflect.FieldDescriptor) protoreflect.Value { + switch descriptor.FullName() { + default: + if descriptor.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: irismod.token.v1.MsgUpgradeERC20Response")) + } + panic(fmt.Errorf("message irismod.token.v1.MsgUpgradeERC20Response does not contain field %s", descriptor.FullName())) + } +} + +// Set stores the value for a field. +// +// For a field belonging to a oneof, it implicitly clears any other field +// that may be currently set within the same oneof. +// For extension fields, it implicitly stores the provided ExtensionType. +// When setting a composite type, it is unspecified whether the stored value +// aliases the source's memory in any way. If the composite value is an +// empty, read-only value, then it panics. +// +// Set is a mutating operation and unsafe for concurrent use. +func (x *fastReflection_MsgUpgradeERC20Response) Set(fd protoreflect.FieldDescriptor, value protoreflect.Value) { + switch fd.FullName() { + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: irismod.token.v1.MsgUpgradeERC20Response")) + } + panic(fmt.Errorf("message irismod.token.v1.MsgUpgradeERC20Response does not contain field %s", fd.FullName())) + } +} + +// Mutable returns a mutable reference to a composite type. +// +// If the field is unpopulated, it may allocate a composite value. +// For a field belonging to a oneof, it implicitly clears any other field +// that may be currently set within the same oneof. +// For extension fields, it implicitly stores the provided ExtensionType +// if not already stored. +// It panics if the field does not contain a composite type. +// +// Mutable is a mutating operation and unsafe for concurrent use. +func (x *fastReflection_MsgUpgradeERC20Response) Mutable(fd protoreflect.FieldDescriptor) protoreflect.Value { + switch fd.FullName() { + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: irismod.token.v1.MsgUpgradeERC20Response")) + } + panic(fmt.Errorf("message irismod.token.v1.MsgUpgradeERC20Response does not contain field %s", fd.FullName())) + } +} + +// NewField returns a new value that is assignable to the field +// for the given descriptor. For scalars, this returns the default value. +// For lists, maps, and messages, this returns a new, empty, mutable value. +func (x *fastReflection_MsgUpgradeERC20Response) NewField(fd protoreflect.FieldDescriptor) protoreflect.Value { + switch fd.FullName() { + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: irismod.token.v1.MsgUpgradeERC20Response")) + } + panic(fmt.Errorf("message irismod.token.v1.MsgUpgradeERC20Response does not contain field %s", fd.FullName())) + } +} + +// WhichOneof reports which field within the oneof is populated, +// returning nil if none are populated. +// It panics if the oneof descriptor does not belong to this message. +func (x *fastReflection_MsgUpgradeERC20Response) WhichOneof(d protoreflect.OneofDescriptor) protoreflect.FieldDescriptor { + switch d.FullName() { + default: + panic(fmt.Errorf("%s is not a oneof field in irismod.token.v1.MsgUpgradeERC20Response", d.FullName())) + } + panic("unreachable") +} + +// GetUnknown retrieves the entire list of unknown fields. +// The caller may only mutate the contents of the RawFields +// if the mutated bytes are stored back into the message with SetUnknown. +func (x *fastReflection_MsgUpgradeERC20Response) GetUnknown() protoreflect.RawFields { + return x.unknownFields +} + +// SetUnknown stores an entire list of unknown fields. +// The raw fields must be syntactically valid according to the wire format. +// An implementation may panic if this is not the case. +// Once stored, the caller must not mutate the content of the RawFields. +// An empty RawFields may be passed to clear the fields. +// +// SetUnknown is a mutating operation and unsafe for concurrent use. +func (x *fastReflection_MsgUpgradeERC20Response) SetUnknown(fields protoreflect.RawFields) { + x.unknownFields = fields +} + +// IsValid reports whether the message is valid. +// +// An invalid message is an empty, read-only value. +// +// An invalid message often corresponds to a nil pointer of the concrete +// message type, but the details are implementation dependent. +// Validity is not part of the protobuf data model, and may not +// be preserved in marshaling or other operations. +func (x *fastReflection_MsgUpgradeERC20Response) IsValid() bool { + return x != nil +} + +// ProtoMethods returns optional fastReflectionFeature-path implementations of various operations. +// This method may return nil. +// +// The returned methods type is identical to +// "google.golang.org/protobuf/runtime/protoiface".Methods. +// Consult the protoiface package documentation for details. +func (x *fastReflection_MsgUpgradeERC20Response) ProtoMethods() *protoiface.Methods { + size := func(input protoiface.SizeInput) protoiface.SizeOutput { + x := input.Message.Interface().(*MsgUpgradeERC20Response) + if x == nil { + return protoiface.SizeOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Size: 0, + } + } + options := runtime.SizeInputToOptions(input) + _ = options + var n int + var l int + _ = l + if x.unknownFields != nil { + n += len(x.unknownFields) + } + return protoiface.SizeOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Size: n, + } + } + + marshal := func(input protoiface.MarshalInput) (protoiface.MarshalOutput, error) { + x := input.Message.Interface().(*MsgUpgradeERC20Response) + if x == nil { + return protoiface.MarshalOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Buf: input.Buf, + }, nil + } + options := runtime.MarshalInputToOptions(input) + _ = options + size := options.Size(x) + dAtA := make([]byte, size) + i := len(dAtA) + _ = i + var l int + _ = l + if x.unknownFields != nil { + i -= len(x.unknownFields) + copy(dAtA[i:], x.unknownFields) + } + if input.Buf != nil { + input.Buf = append(input.Buf, dAtA...) + } else { + input.Buf = dAtA + } + return protoiface.MarshalOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Buf: input.Buf, + }, nil + } + unmarshal := func(input protoiface.UnmarshalInput) (protoiface.UnmarshalOutput, error) { + x := input.Message.Interface().(*MsgUpgradeERC20Response) + if x == nil { + return protoiface.UnmarshalOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Flags: input.Flags, + }, nil + } + options := runtime.UnmarshalInputToOptions(input) + _ = options + dAtA := input.Buf + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, 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 protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: MsgUpgradeERC20Response: wiretype end group for non-group") + } + if fieldNum <= 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: MsgUpgradeERC20Response: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := runtime.Skip(dAtA[iNdEx:]) + if err != nil { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if (iNdEx + skippy) > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + if !options.DiscardUnknown { + x.unknownFields = append(x.unknownFields, dAtA[iNdEx:iNdEx+skippy]...) + } + iNdEx += skippy + } + } + + if iNdEx > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, nil + } + return &protoiface.Methods{ + NoUnkeyedLiterals: struct{}{}, + Flags: protoiface.SupportMarshalDeterministic | protoiface.SupportUnmarshalDiscardUnknown, + Size: size, + Marshal: marshal, + Unmarshal: unmarshal, + Merge: nil, + CheckInitialized: nil, + } +} + // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.27.0 @@ -10462,6 +11302,78 @@ func (*MsgSwapFromERC20Response) Descriptor() ([]byte, []int) { return file_irismod_token_v1_tx_proto_rawDescGZIP(), []int{19} } +// MsgUpgradeERC20 defines an SDK message for UpgradeERC20 +type MsgUpgradeERC20 struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + // implementation is the new erc20 contract address + Implementation string `protobuf:"bytes,1,opt,name=implementation,proto3" json:"implementation,omitempty"` + Authority string `protobuf:"bytes,2,opt,name=authority,proto3" json:"authority,omitempty"` +} + +func (x *MsgUpgradeERC20) Reset() { + *x = MsgUpgradeERC20{} + if protoimpl.UnsafeEnabled { + mi := &file_irismod_token_v1_tx_proto_msgTypes[20] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *MsgUpgradeERC20) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*MsgUpgradeERC20) ProtoMessage() {} + +// Deprecated: Use MsgUpgradeERC20.ProtoReflect.Descriptor instead. +func (*MsgUpgradeERC20) Descriptor() ([]byte, []int) { + return file_irismod_token_v1_tx_proto_rawDescGZIP(), []int{20} +} + +func (x *MsgUpgradeERC20) GetImplementation() string { + if x != nil { + return x.Implementation + } + return "" +} + +func (x *MsgUpgradeERC20) GetAuthority() string { + if x != nil { + return x.Authority + } + return "" +} + +// MsgUpgradeERC20Response defines the Msg/UpgradeERC20 response type +type MsgUpgradeERC20Response struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields +} + +func (x *MsgUpgradeERC20Response) Reset() { + *x = MsgUpgradeERC20Response{} + if protoimpl.UnsafeEnabled { + mi := &file_irismod_token_v1_tx_proto_msgTypes[21] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *MsgUpgradeERC20Response) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*MsgUpgradeERC20Response) ProtoMessage() {} + +// Deprecated: Use MsgUpgradeERC20Response.ProtoReflect.Descriptor instead. +func (*MsgUpgradeERC20Response) Descriptor() ([]byte, []int) { + return file_irismod_token_v1_tx_proto_rawDescGZIP(), []int{21} +} + var File_irismod_token_v1_tx_proto protoreflect.FileDescriptor var file_irismod_token_v1_tx_proto_rawDesc = []byte{ @@ -10609,78 +11521,94 @@ var file_irismod_token_v1_tx_proto_rawDesc = []byte{ 0x74, 0x72, 0x69, 0x6e, 0x67, 0x52, 0x08, 0x72, 0x65, 0x63, 0x65, 0x69, 0x76, 0x65, 0x72, 0x3a, 0x0b, 0x82, 0xe7, 0xb0, 0x2a, 0x06, 0x73, 0x65, 0x6e, 0x64, 0x65, 0x72, 0x22, 0x1a, 0x0a, 0x18, 0x4d, 0x73, 0x67, 0x53, 0x77, 0x61, 0x70, 0x46, 0x72, 0x6f, 0x6d, 0x45, 0x52, 0x43, 0x32, 0x30, - 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x32, 0xa6, 0x07, 0x0a, 0x03, 0x4d, 0x73, 0x67, - 0x12, 0x56, 0x0a, 0x0a, 0x49, 0x73, 0x73, 0x75, 0x65, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x12, 0x1f, - 0x2e, 0x69, 0x72, 0x69, 0x73, 0x6d, 0x6f, 0x64, 0x2e, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x2e, 0x76, - 0x31, 0x2e, 0x4d, 0x73, 0x67, 0x49, 0x73, 0x73, 0x75, 0x65, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x1a, - 0x27, 0x2e, 0x69, 0x72, 0x69, 0x73, 0x6d, 0x6f, 0x64, 0x2e, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x2e, - 0x76, 0x31, 0x2e, 0x4d, 0x73, 0x67, 0x49, 0x73, 0x73, 0x75, 0x65, 0x54, 0x6f, 0x6b, 0x65, 0x6e, - 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x53, 0x0a, 0x09, 0x45, 0x64, 0x69, 0x74, - 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x12, 0x1e, 0x2e, 0x69, 0x72, 0x69, 0x73, 0x6d, 0x6f, 0x64, 0x2e, - 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x4d, 0x73, 0x67, 0x45, 0x64, 0x69, 0x74, - 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x1a, 0x26, 0x2e, 0x69, 0x72, 0x69, 0x73, 0x6d, 0x6f, 0x64, 0x2e, - 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x4d, 0x73, 0x67, 0x45, 0x64, 0x69, 0x74, - 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x53, 0x0a, - 0x09, 0x4d, 0x69, 0x6e, 0x74, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x12, 0x1e, 0x2e, 0x69, 0x72, 0x69, - 0x73, 0x6d, 0x6f, 0x64, 0x2e, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x4d, 0x73, - 0x67, 0x4d, 0x69, 0x6e, 0x74, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x1a, 0x26, 0x2e, 0x69, 0x72, 0x69, - 0x73, 0x6d, 0x6f, 0x64, 0x2e, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x4d, 0x73, - 0x67, 0x4d, 0x69, 0x6e, 0x74, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, - 0x73, 0x65, 0x12, 0x53, 0x0a, 0x09, 0x42, 0x75, 0x72, 0x6e, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x12, - 0x1e, 0x2e, 0x69, 0x72, 0x69, 0x73, 0x6d, 0x6f, 0x64, 0x2e, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x2e, - 0x76, 0x31, 0x2e, 0x4d, 0x73, 0x67, 0x42, 0x75, 0x72, 0x6e, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x1a, - 0x26, 0x2e, 0x69, 0x72, 0x69, 0x73, 0x6d, 0x6f, 0x64, 0x2e, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x2e, - 0x76, 0x31, 0x2e, 0x4d, 0x73, 0x67, 0x42, 0x75, 0x72, 0x6e, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x52, - 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x6e, 0x0a, 0x12, 0x54, 0x72, 0x61, 0x6e, 0x73, - 0x66, 0x65, 0x72, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x4f, 0x77, 0x6e, 0x65, 0x72, 0x12, 0x27, 0x2e, + 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x81, 0x01, 0x0a, 0x0f, 0x4d, 0x73, 0x67, + 0x55, 0x70, 0x67, 0x72, 0x61, 0x64, 0x65, 0x45, 0x52, 0x43, 0x32, 0x30, 0x12, 0x26, 0x0a, 0x0e, + 0x69, 0x6d, 0x70, 0x6c, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x0e, 0x69, 0x6d, 0x70, 0x6c, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x61, + 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x36, 0x0a, 0x09, 0x61, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x69, 0x74, + 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x42, 0x18, 0xd2, 0xb4, 0x2d, 0x14, 0x63, 0x6f, 0x73, + 0x6d, 0x6f, 0x73, 0x2e, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x53, 0x74, 0x72, 0x69, 0x6e, + 0x67, 0x52, 0x09, 0x61, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x69, 0x74, 0x79, 0x3a, 0x0e, 0x82, 0xe7, + 0xb0, 0x2a, 0x09, 0x61, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x69, 0x74, 0x79, 0x22, 0x19, 0x0a, 0x17, + 0x4d, 0x73, 0x67, 0x55, 0x70, 0x67, 0x72, 0x61, 0x64, 0x65, 0x45, 0x52, 0x43, 0x32, 0x30, 0x52, + 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x32, 0x84, 0x08, 0x0a, 0x03, 0x4d, 0x73, 0x67, 0x12, + 0x56, 0x0a, 0x0a, 0x49, 0x73, 0x73, 0x75, 0x65, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x12, 0x1f, 0x2e, 0x69, 0x72, 0x69, 0x73, 0x6d, 0x6f, 0x64, 0x2e, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x2e, 0x76, 0x31, - 0x2e, 0x4d, 0x73, 0x67, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x66, 0x65, 0x72, 0x54, 0x6f, 0x6b, 0x65, - 0x6e, 0x4f, 0x77, 0x6e, 0x65, 0x72, 0x1a, 0x2f, 0x2e, 0x69, 0x72, 0x69, 0x73, 0x6d, 0x6f, 0x64, - 0x2e, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x4d, 0x73, 0x67, 0x54, 0x72, 0x61, - 0x6e, 0x73, 0x66, 0x65, 0x72, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x4f, 0x77, 0x6e, 0x65, 0x72, 0x52, - 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x5c, 0x0a, 0x0c, 0x53, 0x77, 0x61, 0x70, 0x46, - 0x65, 0x65, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x12, 0x21, 0x2e, 0x69, 0x72, 0x69, 0x73, 0x6d, 0x6f, - 0x64, 0x2e, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x4d, 0x73, 0x67, 0x53, 0x77, - 0x61, 0x70, 0x46, 0x65, 0x65, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x1a, 0x29, 0x2e, 0x69, 0x72, 0x69, - 0x73, 0x6d, 0x6f, 0x64, 0x2e, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x4d, 0x73, - 0x67, 0x53, 0x77, 0x61, 0x70, 0x46, 0x65, 0x65, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x52, 0x65, 0x73, - 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x59, 0x0a, 0x0b, 0x53, 0x77, 0x61, 0x70, 0x54, 0x6f, 0x45, - 0x52, 0x43, 0x32, 0x30, 0x12, 0x20, 0x2e, 0x69, 0x72, 0x69, 0x73, 0x6d, 0x6f, 0x64, 0x2e, 0x74, - 0x6f, 0x6b, 0x65, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x4d, 0x73, 0x67, 0x53, 0x77, 0x61, 0x70, 0x54, - 0x6f, 0x45, 0x52, 0x43, 0x32, 0x30, 0x1a, 0x28, 0x2e, 0x69, 0x72, 0x69, 0x73, 0x6d, 0x6f, 0x64, + 0x2e, 0x4d, 0x73, 0x67, 0x49, 0x73, 0x73, 0x75, 0x65, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x1a, 0x27, + 0x2e, 0x69, 0x72, 0x69, 0x73, 0x6d, 0x6f, 0x64, 0x2e, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x2e, 0x76, + 0x31, 0x2e, 0x4d, 0x73, 0x67, 0x49, 0x73, 0x73, 0x75, 0x65, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x52, + 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x53, 0x0a, 0x09, 0x45, 0x64, 0x69, 0x74, 0x54, + 0x6f, 0x6b, 0x65, 0x6e, 0x12, 0x1e, 0x2e, 0x69, 0x72, 0x69, 0x73, 0x6d, 0x6f, 0x64, 0x2e, 0x74, + 0x6f, 0x6b, 0x65, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x4d, 0x73, 0x67, 0x45, 0x64, 0x69, 0x74, 0x54, + 0x6f, 0x6b, 0x65, 0x6e, 0x1a, 0x26, 0x2e, 0x69, 0x72, 0x69, 0x73, 0x6d, 0x6f, 0x64, 0x2e, 0x74, + 0x6f, 0x6b, 0x65, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x4d, 0x73, 0x67, 0x45, 0x64, 0x69, 0x74, 0x54, + 0x6f, 0x6b, 0x65, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x53, 0x0a, 0x09, + 0x4d, 0x69, 0x6e, 0x74, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x12, 0x1e, 0x2e, 0x69, 0x72, 0x69, 0x73, + 0x6d, 0x6f, 0x64, 0x2e, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x4d, 0x73, 0x67, + 0x4d, 0x69, 0x6e, 0x74, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x1a, 0x26, 0x2e, 0x69, 0x72, 0x69, 0x73, + 0x6d, 0x6f, 0x64, 0x2e, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x4d, 0x73, 0x67, + 0x4d, 0x69, 0x6e, 0x74, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, + 0x65, 0x12, 0x53, 0x0a, 0x09, 0x42, 0x75, 0x72, 0x6e, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x12, 0x1e, + 0x2e, 0x69, 0x72, 0x69, 0x73, 0x6d, 0x6f, 0x64, 0x2e, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x2e, 0x76, + 0x31, 0x2e, 0x4d, 0x73, 0x67, 0x42, 0x75, 0x72, 0x6e, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x1a, 0x26, + 0x2e, 0x69, 0x72, 0x69, 0x73, 0x6d, 0x6f, 0x64, 0x2e, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x2e, 0x76, + 0x31, 0x2e, 0x4d, 0x73, 0x67, 0x42, 0x75, 0x72, 0x6e, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x52, 0x65, + 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x6e, 0x0a, 0x12, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x66, + 0x65, 0x72, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x4f, 0x77, 0x6e, 0x65, 0x72, 0x12, 0x27, 0x2e, 0x69, + 0x72, 0x69, 0x73, 0x6d, 0x6f, 0x64, 0x2e, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x2e, 0x76, 0x31, 0x2e, + 0x4d, 0x73, 0x67, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x66, 0x65, 0x72, 0x54, 0x6f, 0x6b, 0x65, 0x6e, + 0x4f, 0x77, 0x6e, 0x65, 0x72, 0x1a, 0x2f, 0x2e, 0x69, 0x72, 0x69, 0x73, 0x6d, 0x6f, 0x64, 0x2e, + 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x4d, 0x73, 0x67, 0x54, 0x72, 0x61, 0x6e, + 0x73, 0x66, 0x65, 0x72, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x4f, 0x77, 0x6e, 0x65, 0x72, 0x52, 0x65, + 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x5c, 0x0a, 0x0c, 0x53, 0x77, 0x61, 0x70, 0x46, 0x65, + 0x65, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x12, 0x21, 0x2e, 0x69, 0x72, 0x69, 0x73, 0x6d, 0x6f, 0x64, 0x2e, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x4d, 0x73, 0x67, 0x53, 0x77, 0x61, - 0x70, 0x54, 0x6f, 0x45, 0x52, 0x43, 0x32, 0x30, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, - 0x12, 0x5f, 0x0a, 0x0d, 0x53, 0x77, 0x61, 0x70, 0x46, 0x72, 0x6f, 0x6d, 0x45, 0x52, 0x43, 0x32, - 0x30, 0x12, 0x22, 0x2e, 0x69, 0x72, 0x69, 0x73, 0x6d, 0x6f, 0x64, 0x2e, 0x74, 0x6f, 0x6b, 0x65, - 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x4d, 0x73, 0x67, 0x53, 0x77, 0x61, 0x70, 0x46, 0x72, 0x6f, 0x6d, - 0x45, 0x52, 0x43, 0x32, 0x30, 0x1a, 0x2a, 0x2e, 0x69, 0x72, 0x69, 0x73, 0x6d, 0x6f, 0x64, 0x2e, + 0x70, 0x46, 0x65, 0x65, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x1a, 0x29, 0x2e, 0x69, 0x72, 0x69, 0x73, + 0x6d, 0x6f, 0x64, 0x2e, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x4d, 0x73, 0x67, + 0x53, 0x77, 0x61, 0x70, 0x46, 0x65, 0x65, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x52, 0x65, 0x73, 0x70, + 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x59, 0x0a, 0x0b, 0x53, 0x77, 0x61, 0x70, 0x54, 0x6f, 0x45, 0x52, + 0x43, 0x32, 0x30, 0x12, 0x20, 0x2e, 0x69, 0x72, 0x69, 0x73, 0x6d, 0x6f, 0x64, 0x2e, 0x74, 0x6f, + 0x6b, 0x65, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x4d, 0x73, 0x67, 0x53, 0x77, 0x61, 0x70, 0x54, 0x6f, + 0x45, 0x52, 0x43, 0x32, 0x30, 0x1a, 0x28, 0x2e, 0x69, 0x72, 0x69, 0x73, 0x6d, 0x6f, 0x64, 0x2e, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x4d, 0x73, 0x67, 0x53, 0x77, 0x61, 0x70, - 0x46, 0x72, 0x6f, 0x6d, 0x45, 0x52, 0x43, 0x32, 0x30, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, - 0x65, 0x12, 0x5c, 0x0a, 0x0c, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x50, 0x61, 0x72, 0x61, 0x6d, - 0x73, 0x12, 0x21, 0x2e, 0x69, 0x72, 0x69, 0x73, 0x6d, 0x6f, 0x64, 0x2e, 0x74, 0x6f, 0x6b, 0x65, - 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x4d, 0x73, 0x67, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x50, 0x61, - 0x72, 0x61, 0x6d, 0x73, 0x1a, 0x29, 0x2e, 0x69, 0x72, 0x69, 0x73, 0x6d, 0x6f, 0x64, 0x2e, 0x74, - 0x6f, 0x6b, 0x65, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x4d, 0x73, 0x67, 0x55, 0x70, 0x64, 0x61, 0x74, - 0x65, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, - 0x59, 0x0a, 0x0b, 0x44, 0x65, 0x70, 0x6c, 0x6f, 0x79, 0x45, 0x52, 0x43, 0x32, 0x30, 0x12, 0x20, - 0x2e, 0x69, 0x72, 0x69, 0x73, 0x6d, 0x6f, 0x64, 0x2e, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x2e, 0x76, - 0x31, 0x2e, 0x4d, 0x73, 0x67, 0x44, 0x65, 0x70, 0x6c, 0x6f, 0x79, 0x45, 0x52, 0x43, 0x32, 0x30, - 0x1a, 0x28, 0x2e, 0x69, 0x72, 0x69, 0x73, 0x6d, 0x6f, 0x64, 0x2e, 0x74, 0x6f, 0x6b, 0x65, 0x6e, - 0x2e, 0x76, 0x31, 0x2e, 0x4d, 0x73, 0x67, 0x44, 0x65, 0x70, 0x6c, 0x6f, 0x79, 0x45, 0x52, 0x43, - 0x32, 0x30, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x1a, 0x05, 0x80, 0xe7, 0xb0, 0x2a, - 0x01, 0x42, 0xbe, 0x01, 0xc8, 0xe1, 0x1e, 0x00, 0x0a, 0x14, 0x63, 0x6f, 0x6d, 0x2e, 0x69, 0x72, - 0x69, 0x73, 0x6d, 0x6f, 0x64, 0x2e, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x2e, 0x76, 0x31, 0x42, 0x07, - 0x54, 0x78, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x37, 0x67, 0x69, 0x74, 0x68, 0x75, - 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x69, 0x72, 0x69, 0x73, 0x6e, 0x65, 0x74, 0x2f, 0x69, 0x72, - 0x69, 0x73, 0x6d, 0x6f, 0x64, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x69, 0x72, 0x69, 0x73, 0x6d, 0x6f, - 0x64, 0x2f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x2f, 0x76, 0x31, 0x3b, 0x74, 0x6f, 0x6b, 0x65, 0x6e, - 0x76, 0x31, 0xa2, 0x02, 0x03, 0x49, 0x54, 0x58, 0xaa, 0x02, 0x10, 0x49, 0x72, 0x69, 0x73, 0x6d, - 0x6f, 0x64, 0x2e, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x2e, 0x56, 0x31, 0xca, 0x02, 0x10, 0x49, 0x72, - 0x69, 0x73, 0x6d, 0x6f, 0x64, 0x5c, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x5c, 0x56, 0x31, 0xe2, 0x02, - 0x1c, 0x49, 0x72, 0x69, 0x73, 0x6d, 0x6f, 0x64, 0x5c, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x5c, 0x56, - 0x31, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x12, - 0x49, 0x72, 0x69, 0x73, 0x6d, 0x6f, 0x64, 0x3a, 0x3a, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x3a, 0x3a, - 0x56, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x54, 0x6f, 0x45, 0x52, 0x43, 0x32, 0x30, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, + 0x5f, 0x0a, 0x0d, 0x53, 0x77, 0x61, 0x70, 0x46, 0x72, 0x6f, 0x6d, 0x45, 0x52, 0x43, 0x32, 0x30, + 0x12, 0x22, 0x2e, 0x69, 0x72, 0x69, 0x73, 0x6d, 0x6f, 0x64, 0x2e, 0x74, 0x6f, 0x6b, 0x65, 0x6e, + 0x2e, 0x76, 0x31, 0x2e, 0x4d, 0x73, 0x67, 0x53, 0x77, 0x61, 0x70, 0x46, 0x72, 0x6f, 0x6d, 0x45, + 0x52, 0x43, 0x32, 0x30, 0x1a, 0x2a, 0x2e, 0x69, 0x72, 0x69, 0x73, 0x6d, 0x6f, 0x64, 0x2e, 0x74, + 0x6f, 0x6b, 0x65, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x4d, 0x73, 0x67, 0x53, 0x77, 0x61, 0x70, 0x46, + 0x72, 0x6f, 0x6d, 0x45, 0x52, 0x43, 0x32, 0x30, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, + 0x12, 0x5c, 0x0a, 0x0c, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, + 0x12, 0x21, 0x2e, 0x69, 0x72, 0x69, 0x73, 0x6d, 0x6f, 0x64, 0x2e, 0x74, 0x6f, 0x6b, 0x65, 0x6e, + 0x2e, 0x76, 0x31, 0x2e, 0x4d, 0x73, 0x67, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x50, 0x61, 0x72, + 0x61, 0x6d, 0x73, 0x1a, 0x29, 0x2e, 0x69, 0x72, 0x69, 0x73, 0x6d, 0x6f, 0x64, 0x2e, 0x74, 0x6f, + 0x6b, 0x65, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x4d, 0x73, 0x67, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, + 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x59, + 0x0a, 0x0b, 0x44, 0x65, 0x70, 0x6c, 0x6f, 0x79, 0x45, 0x52, 0x43, 0x32, 0x30, 0x12, 0x20, 0x2e, + 0x69, 0x72, 0x69, 0x73, 0x6d, 0x6f, 0x64, 0x2e, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x2e, 0x76, 0x31, + 0x2e, 0x4d, 0x73, 0x67, 0x44, 0x65, 0x70, 0x6c, 0x6f, 0x79, 0x45, 0x52, 0x43, 0x32, 0x30, 0x1a, + 0x28, 0x2e, 0x69, 0x72, 0x69, 0x73, 0x6d, 0x6f, 0x64, 0x2e, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x2e, + 0x76, 0x31, 0x2e, 0x4d, 0x73, 0x67, 0x44, 0x65, 0x70, 0x6c, 0x6f, 0x79, 0x45, 0x52, 0x43, 0x32, + 0x30, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x5c, 0x0a, 0x0c, 0x55, 0x70, 0x67, + 0x72, 0x61, 0x64, 0x65, 0x45, 0x52, 0x43, 0x32, 0x30, 0x12, 0x21, 0x2e, 0x69, 0x72, 0x69, 0x73, + 0x6d, 0x6f, 0x64, 0x2e, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x4d, 0x73, 0x67, + 0x55, 0x70, 0x67, 0x72, 0x61, 0x64, 0x65, 0x45, 0x52, 0x43, 0x32, 0x30, 0x1a, 0x29, 0x2e, 0x69, + 0x72, 0x69, 0x73, 0x6d, 0x6f, 0x64, 0x2e, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x2e, 0x76, 0x31, 0x2e, + 0x4d, 0x73, 0x67, 0x55, 0x70, 0x67, 0x72, 0x61, 0x64, 0x65, 0x45, 0x52, 0x43, 0x32, 0x30, 0x52, + 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x1a, 0x05, 0x80, 0xe7, 0xb0, 0x2a, 0x01, 0x42, 0xbe, + 0x01, 0xc8, 0xe1, 0x1e, 0x00, 0x0a, 0x14, 0x63, 0x6f, 0x6d, 0x2e, 0x69, 0x72, 0x69, 0x73, 0x6d, + 0x6f, 0x64, 0x2e, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x2e, 0x76, 0x31, 0x42, 0x07, 0x54, 0x78, 0x50, + 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x37, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, + 0x6f, 0x6d, 0x2f, 0x69, 0x72, 0x69, 0x73, 0x6e, 0x65, 0x74, 0x2f, 0x69, 0x72, 0x69, 0x73, 0x6d, + 0x6f, 0x64, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x69, 0x72, 0x69, 0x73, 0x6d, 0x6f, 0x64, 0x2f, 0x74, + 0x6f, 0x6b, 0x65, 0x6e, 0x2f, 0x76, 0x31, 0x3b, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x76, 0x31, 0xa2, + 0x02, 0x03, 0x49, 0x54, 0x58, 0xaa, 0x02, 0x10, 0x49, 0x72, 0x69, 0x73, 0x6d, 0x6f, 0x64, 0x2e, + 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x2e, 0x56, 0x31, 0xca, 0x02, 0x10, 0x49, 0x72, 0x69, 0x73, 0x6d, + 0x6f, 0x64, 0x5c, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x5c, 0x56, 0x31, 0xe2, 0x02, 0x1c, 0x49, 0x72, + 0x69, 0x73, 0x6d, 0x6f, 0x64, 0x5c, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x5c, 0x56, 0x31, 0x5c, 0x47, + 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x12, 0x49, 0x72, 0x69, + 0x73, 0x6d, 0x6f, 0x64, 0x3a, 0x3a, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x3a, 0x3a, 0x56, 0x31, 0x62, + 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -10695,7 +11623,7 @@ func file_irismod_token_v1_tx_proto_rawDescGZIP() []byte { return file_irismod_token_v1_tx_proto_rawDescData } -var file_irismod_token_v1_tx_proto_msgTypes = make([]protoimpl.MessageInfo, 20) +var file_irismod_token_v1_tx_proto_msgTypes = make([]protoimpl.MessageInfo, 22) var file_irismod_token_v1_tx_proto_goTypes = []interface{}{ (*MsgIssueToken)(nil), // 0: irismod.token.v1.MsgIssueToken (*MsgIssueTokenResponse)(nil), // 1: irismod.token.v1.MsgIssueTokenResponse @@ -10717,17 +11645,19 @@ var file_irismod_token_v1_tx_proto_goTypes = []interface{}{ (*MsgSwapToERC20Response)(nil), // 17: irismod.token.v1.MsgSwapToERC20Response (*MsgSwapFromERC20)(nil), // 18: irismod.token.v1.MsgSwapFromERC20 (*MsgSwapFromERC20Response)(nil), // 19: irismod.token.v1.MsgSwapFromERC20Response - (*v1beta1.Coin)(nil), // 20: cosmos.base.v1beta1.Coin - (*Params)(nil), // 21: irismod.token.v1.Params + (*MsgUpgradeERC20)(nil), // 20: irismod.token.v1.MsgUpgradeERC20 + (*MsgUpgradeERC20Response)(nil), // 21: irismod.token.v1.MsgUpgradeERC20Response + (*v1beta1.Coin)(nil), // 22: cosmos.base.v1beta1.Coin + (*Params)(nil), // 23: irismod.token.v1.Params } var file_irismod_token_v1_tx_proto_depIdxs = []int32{ - 20, // 0: irismod.token.v1.MsgMintToken.coin:type_name -> cosmos.base.v1beta1.Coin - 20, // 1: irismod.token.v1.MsgBurnToken.coin:type_name -> cosmos.base.v1beta1.Coin - 20, // 2: irismod.token.v1.MsgSwapFeeToken.fee_paid:type_name -> cosmos.base.v1beta1.Coin - 20, // 3: irismod.token.v1.MsgSwapFeeTokenResponse.fee_got:type_name -> cosmos.base.v1beta1.Coin - 21, // 4: irismod.token.v1.MsgUpdateParams.params:type_name -> irismod.token.v1.Params - 20, // 5: irismod.token.v1.MsgSwapToERC20.amount:type_name -> cosmos.base.v1beta1.Coin - 20, // 6: irismod.token.v1.MsgSwapFromERC20.wanted_amount:type_name -> cosmos.base.v1beta1.Coin + 22, // 0: irismod.token.v1.MsgMintToken.coin:type_name -> cosmos.base.v1beta1.Coin + 22, // 1: irismod.token.v1.MsgBurnToken.coin:type_name -> cosmos.base.v1beta1.Coin + 22, // 2: irismod.token.v1.MsgSwapFeeToken.fee_paid:type_name -> cosmos.base.v1beta1.Coin + 22, // 3: irismod.token.v1.MsgSwapFeeTokenResponse.fee_got:type_name -> cosmos.base.v1beta1.Coin + 23, // 4: irismod.token.v1.MsgUpdateParams.params:type_name -> irismod.token.v1.Params + 22, // 5: irismod.token.v1.MsgSwapToERC20.amount:type_name -> cosmos.base.v1beta1.Coin + 22, // 6: irismod.token.v1.MsgSwapFromERC20.wanted_amount:type_name -> cosmos.base.v1beta1.Coin 0, // 7: irismod.token.v1.Msg.IssueToken:input_type -> irismod.token.v1.MsgIssueToken 4, // 8: irismod.token.v1.Msg.EditToken:input_type -> irismod.token.v1.MsgEditToken 6, // 9: irismod.token.v1.Msg.MintToken:input_type -> irismod.token.v1.MsgMintToken @@ -10738,18 +11668,20 @@ var file_irismod_token_v1_tx_proto_depIdxs = []int32{ 18, // 14: irismod.token.v1.Msg.SwapFromERC20:input_type -> irismod.token.v1.MsgSwapFromERC20 12, // 15: irismod.token.v1.Msg.UpdateParams:input_type -> irismod.token.v1.MsgUpdateParams 14, // 16: irismod.token.v1.Msg.DeployERC20:input_type -> irismod.token.v1.MsgDeployERC20 - 1, // 17: irismod.token.v1.Msg.IssueToken:output_type -> irismod.token.v1.MsgIssueTokenResponse - 5, // 18: irismod.token.v1.Msg.EditToken:output_type -> irismod.token.v1.MsgEditTokenResponse - 7, // 19: irismod.token.v1.Msg.MintToken:output_type -> irismod.token.v1.MsgMintTokenResponse - 9, // 20: irismod.token.v1.Msg.BurnToken:output_type -> irismod.token.v1.MsgBurnTokenResponse - 3, // 21: irismod.token.v1.Msg.TransferTokenOwner:output_type -> irismod.token.v1.MsgTransferTokenOwnerResponse - 11, // 22: irismod.token.v1.Msg.SwapFeeToken:output_type -> irismod.token.v1.MsgSwapFeeTokenResponse - 17, // 23: irismod.token.v1.Msg.SwapToERC20:output_type -> irismod.token.v1.MsgSwapToERC20Response - 19, // 24: irismod.token.v1.Msg.SwapFromERC20:output_type -> irismod.token.v1.MsgSwapFromERC20Response - 13, // 25: irismod.token.v1.Msg.UpdateParams:output_type -> irismod.token.v1.MsgUpdateParamsResponse - 15, // 26: irismod.token.v1.Msg.DeployERC20:output_type -> irismod.token.v1.MsgDeployERC20Response - 17, // [17:27] is the sub-list for method output_type - 7, // [7:17] is the sub-list for method input_type + 20, // 17: irismod.token.v1.Msg.UpgradeERC20:input_type -> irismod.token.v1.MsgUpgradeERC20 + 1, // 18: irismod.token.v1.Msg.IssueToken:output_type -> irismod.token.v1.MsgIssueTokenResponse + 5, // 19: irismod.token.v1.Msg.EditToken:output_type -> irismod.token.v1.MsgEditTokenResponse + 7, // 20: irismod.token.v1.Msg.MintToken:output_type -> irismod.token.v1.MsgMintTokenResponse + 9, // 21: irismod.token.v1.Msg.BurnToken:output_type -> irismod.token.v1.MsgBurnTokenResponse + 3, // 22: irismod.token.v1.Msg.TransferTokenOwner:output_type -> irismod.token.v1.MsgTransferTokenOwnerResponse + 11, // 23: irismod.token.v1.Msg.SwapFeeToken:output_type -> irismod.token.v1.MsgSwapFeeTokenResponse + 17, // 24: irismod.token.v1.Msg.SwapToERC20:output_type -> irismod.token.v1.MsgSwapToERC20Response + 19, // 25: irismod.token.v1.Msg.SwapFromERC20:output_type -> irismod.token.v1.MsgSwapFromERC20Response + 13, // 26: irismod.token.v1.Msg.UpdateParams:output_type -> irismod.token.v1.MsgUpdateParamsResponse + 15, // 27: irismod.token.v1.Msg.DeployERC20:output_type -> irismod.token.v1.MsgDeployERC20Response + 21, // 28: irismod.token.v1.Msg.UpgradeERC20:output_type -> irismod.token.v1.MsgUpgradeERC20Response + 18, // [18:29] is the sub-list for method output_type + 7, // [7:18] is the sub-list for method input_type 7, // [7:7] is the sub-list for extension type_name 7, // [7:7] is the sub-list for extension extendee 0, // [0:7] is the sub-list for field type_name @@ -11002,6 +11934,30 @@ func file_irismod_token_v1_tx_proto_init() { return nil } } + file_irismod_token_v1_tx_proto_msgTypes[20].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*MsgUpgradeERC20); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_irismod_token_v1_tx_proto_msgTypes[21].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*MsgUpgradeERC20Response); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } } type x struct{} out := protoimpl.TypeBuilder{ @@ -11009,7 +11965,7 @@ func file_irismod_token_v1_tx_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_irismod_token_v1_tx_proto_rawDesc, NumEnums: 0, - NumMessages: 20, + NumMessages: 22, NumExtensions: 0, NumServices: 1, }, diff --git a/api/irismod/token/v1/tx_grpc.pb.go b/api/irismod/token/v1/tx_grpc.pb.go index be92a204..298b17bc 100644 --- a/api/irismod/token/v1/tx_grpc.pb.go +++ b/api/irismod/token/v1/tx_grpc.pb.go @@ -29,6 +29,7 @@ const ( Msg_SwapFromERC20_FullMethodName = "/irismod.token.v1.Msg/SwapFromERC20" Msg_UpdateParams_FullMethodName = "/irismod.token.v1.Msg/UpdateParams" Msg_DeployERC20_FullMethodName = "/irismod.token.v1.Msg/DeployERC20" + Msg_UpgradeERC20_FullMethodName = "/irismod.token.v1.Msg/UpgradeERC20" ) // MsgClient is the client API for Msg service. @@ -61,6 +62,8 @@ type MsgClient interface { // DeployERC20 defines a governance operation for deploying an ERC20 contract // that binds to a native token DeployERC20(ctx context.Context, in *MsgDeployERC20, opts ...grpc.CallOption) (*MsgDeployERC20Response, error) + // UpgradeERC20 defines a governance operation for upgrading an ERC20 contract + UpgradeERC20(ctx context.Context, in *MsgUpgradeERC20, opts ...grpc.CallOption) (*MsgUpgradeERC20Response, error) } type msgClient struct { @@ -161,6 +164,15 @@ func (c *msgClient) DeployERC20(ctx context.Context, in *MsgDeployERC20, opts .. return out, nil } +func (c *msgClient) UpgradeERC20(ctx context.Context, in *MsgUpgradeERC20, opts ...grpc.CallOption) (*MsgUpgradeERC20Response, error) { + out := new(MsgUpgradeERC20Response) + err := c.cc.Invoke(ctx, Msg_UpgradeERC20_FullMethodName, in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // MsgServer is the server API for Msg service. // All implementations must embed UnimplementedMsgServer // for forward compatibility @@ -191,6 +203,8 @@ type MsgServer interface { // DeployERC20 defines a governance operation for deploying an ERC20 contract // that binds to a native token DeployERC20(context.Context, *MsgDeployERC20) (*MsgDeployERC20Response, error) + // UpgradeERC20 defines a governance operation for upgrading an ERC20 contract + UpgradeERC20(context.Context, *MsgUpgradeERC20) (*MsgUpgradeERC20Response, error) mustEmbedUnimplementedMsgServer() } @@ -228,6 +242,9 @@ func (UnimplementedMsgServer) UpdateParams(context.Context, *MsgUpdateParams) (* func (UnimplementedMsgServer) DeployERC20(context.Context, *MsgDeployERC20) (*MsgDeployERC20Response, error) { return nil, status.Errorf(codes.Unimplemented, "method DeployERC20 not implemented") } +func (UnimplementedMsgServer) UpgradeERC20(context.Context, *MsgUpgradeERC20) (*MsgUpgradeERC20Response, error) { + return nil, status.Errorf(codes.Unimplemented, "method UpgradeERC20 not implemented") +} func (UnimplementedMsgServer) mustEmbedUnimplementedMsgServer() {} // UnsafeMsgServer may be embedded to opt out of forward compatibility for this service. @@ -421,6 +438,24 @@ func _Msg_DeployERC20_Handler(srv interface{}, ctx context.Context, dec func(int return interceptor(ctx, in, info, handler) } +func _Msg_UpgradeERC20_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgUpgradeERC20) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).UpgradeERC20(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Msg_UpgradeERC20_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).UpgradeERC20(ctx, req.(*MsgUpgradeERC20)) + } + return interceptor(ctx, in, info, handler) +} + // Msg_ServiceDesc is the grpc.ServiceDesc for Msg service. // It's only intended for direct use with grpc.RegisterService, // and not to be introspected or modified (even as a copy) @@ -468,6 +503,10 @@ var Msg_ServiceDesc = grpc.ServiceDesc{ MethodName: "DeployERC20", Handler: _Msg_DeployERC20_Handler, }, + { + MethodName: "UpgradeERC20", + Handler: _Msg_UpgradeERC20_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "irismod/token/v1/tx.proto", diff --git a/contracts/compiled_contracts/UpgradeableBeacon.json b/contracts/compiled_contracts/UpgradeableBeacon.json new file mode 100644 index 00000000..1edf3b01 --- /dev/null +++ b/contracts/compiled_contracts/UpgradeableBeacon.json @@ -0,0 +1,145 @@ +{ + "abi": [ + { + "inputs": [ + { + "internalType": "address", + "name": "implementation_", + "type": "address" + }, + { + "internalType": "address", + "name": "initialOwner", + "type": "address" + } + ], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "implementation", + "type": "address" + } + ], + "name": "BeaconInvalidImplementation", + "type": "error" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "owner", + "type": "address" + } + ], + "name": "OwnableInvalidOwner", + "type": "error" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "account", + "type": "address" + } + ], + "name": "OwnableUnauthorizedAccount", + "type": "error" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "previousOwner", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "newOwner", + "type": "address" + } + ], + "name": "OwnershipTransferred", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "implementation", + "type": "address" + } + ], + "name": "Upgraded", + "type": "event" + }, + { + "inputs": [], + "name": "implementation", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "owner", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "renounceOwnership", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "newOwner", + "type": "address" + } + ], + "name": "transferOwnership", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "newImplementation", + "type": "address" + } + ], + "name": "upgradeTo", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + } + ], + "bin": "608060405234801561001057600080fd5b5060405161084f38038061084f833981810160405281019061003291906102d5565b80600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16036100a55760006040517f1e4fbdf700000000000000000000000000000000000000000000000000000000815260040161009c9190610324565b60405180910390fd5b6100b4816100cb60201b60201c565b506100c48261018f60201b60201c565b505061033f565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff169050816000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508173ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a35050565b60008173ffffffffffffffffffffffffffffffffffffffff163b036101eb57806040517f847ac5640000000000000000000000000000000000000000000000000000000081526004016101e29190610324565b60405180910390fd5b80600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508073ffffffffffffffffffffffffffffffffffffffff167fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b60405160405180910390a250565b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b60006102a282610277565b9050919050565b6102b281610297565b81146102bd57600080fd5b50565b6000815190506102cf816102a9565b92915050565b600080604083850312156102ec576102eb610272565b5b60006102fa858286016102c0565b925050602061030b858286016102c0565b9150509250929050565b61031e81610297565b82525050565b60006020820190506103396000830184610315565b92915050565b6105018061034e6000396000f3fe608060405234801561001057600080fd5b50600436106100575760003560e01c80633659cfe61461005c5780635c60da1b14610078578063715018a6146100965780638da5cb5b146100a0578063f2fde38b146100be575b600080fd5b61007660048036038101906100719190610474565b6100da565b005b6100806100ee565b60405161008d91906104b0565b60405180910390f35b61009e610118565b005b6100a861012c565b6040516100b591906104b0565b60405180910390f35b6100d860048036038101906100d39190610474565b610155565b005b6100e26101db565b6100eb81610262565b50565b6000600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b6101206101db565b61012a6000610345565b565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b61015d6101db565b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16036101cf5760006040517f1e4fbdf70000000000000000000000000000000000000000000000000000000081526004016101c691906104b0565b60405180910390fd5b6101d881610345565b50565b6101e3610409565b73ffffffffffffffffffffffffffffffffffffffff1661020161012c565b73ffffffffffffffffffffffffffffffffffffffff161461026057610224610409565b6040517f118cdaa700000000000000000000000000000000000000000000000000000000815260040161025791906104b0565b60405180910390fd5b565b60008173ffffffffffffffffffffffffffffffffffffffff163b036102be57806040517f847ac5640000000000000000000000000000000000000000000000000000000081526004016102b591906104b0565b60405180910390fd5b80600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508073ffffffffffffffffffffffffffffffffffffffff167fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b60405160405180910390a250565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff169050816000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508173ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a35050565b600033905090565b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b600061044182610416565b9050919050565b61045181610436565b811461045c57600080fd5b50565b60008135905061046e81610448565b92915050565b60006020828403121561048a57610489610411565b5b60006104988482850161045f565b91505092915050565b6104aa81610436565b82525050565b60006020820190506104c560008301846104a1565b9291505056fea264697066735822122022522b074e70ca37bd6bd300c1eba3d7f88a2c4dbd01054e923572600c6d3f4e64736f6c63430008170033" +} diff --git a/contracts/erc20.go b/contracts/erc20.go index a564000c..858bee28 100644 --- a/contracts/erc20.go +++ b/contracts/erc20.go @@ -13,6 +13,7 @@ const ( MethodBurn = "burn" MethodBalanceOf = "balanceOf" MethodInitialize = "initialize" + MethodUpgradeTo = "upgradeTo" ) var ( @@ -22,11 +23,17 @@ var ( //go:embed compiled_contracts/TokenProxy.json TokenProxyJSON []byte //nolint: golint + //go:embed compiled_contracts/UpgradeableBeacon.json + BeaconJSON []byte //nolint: golint + // ERC20TokenContract is the compiled erc20 contract ERC20TokenContract types.CompiledContract // TokenProxyContract is the compiled erc20 contract proxy TokenProxyContract types.CompiledContract + + // BeaconContract is the compiled beacon contract proxy + BeaconContract types.CompiledContract ) func init() { @@ -35,6 +42,11 @@ func init() { panic(err) } + err = json.Unmarshal(BeaconJSON, &BeaconContract) + if err != nil { + panic(err) + } + err = json.Unmarshal(TokenProxyJSON, &TokenProxyContract) if err != nil { panic(err) diff --git a/modules/token/keeper/erc20.go b/modules/token/keeper/erc20.go index b08d1c0b..31cd0cf2 100644 --- a/modules/token/keeper/erc20.go +++ b/modules/token/keeper/erc20.go @@ -44,7 +44,7 @@ func (k Keeper) DeployERC20( params := k.GetParams(ctx) if !params.EnableErc20 { - return common.Address{}, errorsmod.Wrapf(types.ErrERC20Disabled, "ERC20 is disabled") + return common.Address{}, errorsmod.Wrapf(types.ErrERC20Disabled, "erc20 is disabled") } if len(params.Beacon) == 0 { @@ -316,6 +316,42 @@ func (k Keeper) BurnERC20( return nil } +// UpgradeERC20 upgrades the ERC20 contract to a new implementation. +// +// Parameters: +// - ctx: the SDK context. +// - implementation: the address of the new implementation contract. +// +// Returns: +// - error: an error if the upgrade fails. +func (k Keeper) UpgradeERC20( + ctx sdk.Context, + implementation common.Address, +) error { + params := k.GetParams(ctx) + if !params.EnableErc20 { + return errorsmod.Wrapf(types.ErrERC20Disabled, "erc20 is disabled") + } + + if len(params.Beacon) == 0 { + return errorsmod.Wrapf(types.ErrBeaconNotSet, "beacon not set") + } + + beacon := common.HexToAddress(params.Beacon) + abi := contracts.BeaconContract.ABI + res, err := k.CallEVM(ctx, abi, k.getModuleEthAddress(ctx), beacon, true, contracts.MethodUpgradeTo, implementation) + if err != nil { + return err + } + if res.Failed() { + return errorsmod.Wrapf( + types.ErrVMExecution, "failed to upgrade contract reason: %s", + res.Revert(), + ) + } + return nil +} + // BalanceOf retrieves the balance of a specific account in the contract. // // Parameters: diff --git a/modules/token/keeper/msg_server.go b/modules/token/keeper/msg_server.go index f3598a56..ee16ef02 100644 --- a/modules/token/keeper/msg_server.go +++ b/modules/token/keeper/msg_server.go @@ -323,3 +323,22 @@ func (m msgServer) SwapToERC20(goCtx context.Context, msg *v1.MsgSwapToERC20) (* } return &v1.MsgSwapToERC20Response{}, nil } + +// UpgradeERC20 implements v1.MsgServer. +func (m msgServer) UpgradeERC20(goCtx context.Context, msg *v1.MsgUpgradeERC20) (*v1.MsgUpgradeERC20Response, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + if m.k.authority != msg.Authority { + return nil, errorsmod.Wrapf( + sdkerrors.ErrUnauthorized, + "invalid authority; expected %s, got %s", + m.k.authority, + msg.Authority, + ) + } + + implementation := common.HexToAddress(msg.Implementation) + if err := m.k.UpgradeERC20(ctx, implementation); err != nil { + return nil, err + } + return &v1.MsgUpgradeERC20Response{}, nil +} diff --git a/modules/token/types/v1/tx.pb.go b/modules/token/types/v1/tx.pb.go index 8f7d997e..932907c6 100644 --- a/modules/token/types/v1/tx.pb.go +++ b/modules/token/types/v1/tx.pb.go @@ -821,6 +821,83 @@ func (m *MsgSwapFromERC20Response) XXX_DiscardUnknown() { var xxx_messageInfo_MsgSwapFromERC20Response proto.InternalMessageInfo +// MsgUpgradeERC20 defines an SDK message for UpgradeERC20 +type MsgUpgradeERC20 struct { + // implementation is the new erc20 contract address + Implementation string `protobuf:"bytes,1,opt,name=implementation,proto3" json:"implementation,omitempty"` + Authority string `protobuf:"bytes,2,opt,name=authority,proto3" json:"authority,omitempty"` +} + +func (m *MsgUpgradeERC20) Reset() { *m = MsgUpgradeERC20{} } +func (m *MsgUpgradeERC20) String() string { return proto.CompactTextString(m) } +func (*MsgUpgradeERC20) ProtoMessage() {} +func (*MsgUpgradeERC20) Descriptor() ([]byte, []int) { + return fileDescriptor_f5fa171367154e01, []int{20} +} +func (m *MsgUpgradeERC20) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgUpgradeERC20) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgUpgradeERC20.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 *MsgUpgradeERC20) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUpgradeERC20.Merge(m, src) +} +func (m *MsgUpgradeERC20) XXX_Size() int { + return m.Size() +} +func (m *MsgUpgradeERC20) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUpgradeERC20.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgUpgradeERC20 proto.InternalMessageInfo + +// MsgUpgradeERC20Response defines the Msg/UpgradeERC20 response type +type MsgUpgradeERC20Response struct { +} + +func (m *MsgUpgradeERC20Response) Reset() { *m = MsgUpgradeERC20Response{} } +func (m *MsgUpgradeERC20Response) String() string { return proto.CompactTextString(m) } +func (*MsgUpgradeERC20Response) ProtoMessage() {} +func (*MsgUpgradeERC20Response) Descriptor() ([]byte, []int) { + return fileDescriptor_f5fa171367154e01, []int{21} +} +func (m *MsgUpgradeERC20Response) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgUpgradeERC20Response) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgUpgradeERC20Response.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 *MsgUpgradeERC20Response) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUpgradeERC20Response.Merge(m, src) +} +func (m *MsgUpgradeERC20Response) XXX_Size() int { + return m.Size() +} +func (m *MsgUpgradeERC20Response) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUpgradeERC20Response.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgUpgradeERC20Response proto.InternalMessageInfo + func init() { proto.RegisterType((*MsgIssueToken)(nil), "irismod.token.v1.MsgIssueToken") proto.RegisterType((*MsgIssueTokenResponse)(nil), "irismod.token.v1.MsgIssueTokenResponse") @@ -842,77 +919,82 @@ func init() { proto.RegisterType((*MsgSwapToERC20Response)(nil), "irismod.token.v1.MsgSwapToERC20Response") proto.RegisterType((*MsgSwapFromERC20)(nil), "irismod.token.v1.MsgSwapFromERC20") proto.RegisterType((*MsgSwapFromERC20Response)(nil), "irismod.token.v1.MsgSwapFromERC20Response") + proto.RegisterType((*MsgUpgradeERC20)(nil), "irismod.token.v1.MsgUpgradeERC20") + proto.RegisterType((*MsgUpgradeERC20Response)(nil), "irismod.token.v1.MsgUpgradeERC20Response") } func init() { proto.RegisterFile("irismod/token/v1/tx.proto", fileDescriptor_f5fa171367154e01) } var fileDescriptor_f5fa171367154e01 = []byte{ - // 1032 bytes of a gzipped FileDescriptorProto + // 1086 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x57, 0xcf, 0x6f, 0x1b, 0x45, - 0x14, 0xce, 0xd6, 0xb1, 0xe3, 0x4c, 0xe2, 0x50, 0xad, 0x42, 0xb2, 0x5e, 0xa8, 0x63, 0x2c, 0x01, - 0x26, 0x12, 0xbb, 0x75, 0x82, 0x5a, 0x94, 0x5b, 0xdd, 0x16, 0xc4, 0xc1, 0x6a, 0x65, 0xa7, 0x48, - 0x20, 0x24, 0x6b, 0xed, 0x9d, 0x6c, 0x47, 0x78, 0x67, 0x56, 0x3b, 0xe3, 0x24, 0xbe, 0xa1, 0x1e, - 0x39, 0x81, 0x38, 0x72, 0x05, 0xc4, 0xb1, 0x07, 0xfe, 0x88, 0x5c, 0x90, 0x2a, 0x4e, 0x9c, 0x2a, - 0x48, 0x0e, 0x95, 0xf8, 0x13, 0x38, 0xa1, 0x9d, 0x19, 0x8f, 0x77, 0xed, 0xf5, 0xaf, 0xa0, 0xde, - 0x3c, 0xfb, 0xbe, 0x7d, 0xf3, 0x7d, 0xdf, 0x7b, 0xf3, 0x66, 0x0d, 0x8a, 0x28, 0x44, 0xd4, 0x27, - 0xae, 0xcd, 0xc8, 0xd7, 0x10, 0xdb, 0xa7, 0x35, 0x9b, 0x9d, 0x5b, 0x41, 0x48, 0x18, 0xd1, 0x6f, - 0xca, 0x90, 0xc5, 0x43, 0xd6, 0x69, 0xcd, 0xdc, 0xf6, 0x88, 0x47, 0x78, 0xd0, 0x8e, 0x7e, 0x09, - 0x9c, 0x59, 0xea, 0x12, 0xea, 0x13, 0x6a, 0x77, 0x1c, 0x0a, 0xed, 0xd3, 0x5a, 0x07, 0x32, 0xa7, - 0x66, 0x77, 0x09, 0xc2, 0x32, 0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, 0x3b, 0xe3, 0xfc, 0xb8, 0x41, 0xc5, + 0x89, 0x13, 0x88, 0x23, 0x57, 0x90, 0x38, 0xf6, 0xc0, 0x1f, 0x91, 0x0b, 0x52, 0xc5, 0x89, 0x53, + 0x05, 0xc9, 0xa1, 0x12, 0x7f, 0x02, 0x27, 0xb4, 0x33, 0xb3, 0xb3, 0xbb, 0xf6, 0x6e, 0x62, 0x07, + 0xf5, 0xe6, 0xd9, 0xf7, 0xed, 0x9b, 0xef, 0xfb, 0xde, 0x9b, 0x79, 0x6b, 0xb0, 0x86, 0x43, 0xcc, + 0x7c, 0xea, 0x36, 0x38, 0xfd, 0x0a, 0x91, 0xc6, 0xd1, 0x76, 0x83, 0x9f, 0x38, 0x41, 0x48, 0x39, + 0x35, 0x6f, 0xa8, 0x90, 0x23, 0x42, 0xce, 0xd1, 0xb6, 0xbd, 0xec, 0x51, 0x8f, 0x8a, 0x60, 0x23, + 0xfa, 0x25, 0x71, 0x76, 0xad, 0x47, 0x99, 0x4f, 0x59, 0xe3, 0x00, 0x32, 0xd4, 0x38, 0xda, 0x3e, + 0x40, 0x1c, 0x6e, 0x37, 0x7a, 0x14, 0x13, 0x15, 0x5f, 0x55, 0x71, 0x9f, 0x79, 0x51, 0x7e, 0x9f, + 0x79, 0x2a, 0xb0, 0x26, 0x03, 0x5d, 0x99, 0x51, 0x2e, 0x54, 0xe8, 0xed, 0x51, 0x5a, 0x82, 0x84, + 0x88, 0xd6, 0xbf, 0x9b, 0x06, 0x8b, 0x2d, 0xe6, 0x7d, 0xca, 0xd8, 0x00, 0xed, 0x47, 0xcf, 0xcd, + 0x15, 0x50, 0x61, 0xa7, 0xfe, 0x01, 0xed, 0x5b, 0xc6, 0x86, 0xb1, 0x39, 0xd7, 0x56, 0x2b, 0xd3, + 0x04, 0x33, 0x04, 0xfa, 0xc8, 0x9a, 0x16, 0x4f, 0xc5, 0x6f, 0x73, 0x19, 0x94, 0x59, 0x0f, 0xf6, + 0x91, 0x55, 0xda,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x8b, 0xd9, 0xeb, 0xa0, 0x5e, 0x4c, + 0x2b, 0xc6, 0xd8, 0x5b, 0x57, 0x63, 0xd2, 0xce, 0x64, 0x26, 0x54, 0xbe, 0x33, 0x69, 0x48, 0x81, + 0x33, 0x79, 0x43, 0x25, 0x72, 0x26, 0x3d, 0x50, 0xf2, 0x9d, 0x49, 0x21, 0x0a, 0x9c, 0xc9, 0xb9, + 0xed, 0x25, 0xf1, 0xd4, 0xe5, 0x51, 0x44, 0x3c, 0x81, 0x14, 0x12, 0x1f, 0x3d, 0xff, 0x76, 0xf9, + 0xeb, 0x57, 0xcf, 0xb7, 0x8c, 0xe6, 0xa3, 0xb3, 0xbf, 0x6b, 0x53, 0x67, 0xe7, 0x35, 0xe3, 0xc5, + 0x79, 0xcd, 0xf8, 0xeb, 0xbc, 0x66, 0x7c, 0x7f, 0x51, 0x9b, 0x7a, 0x71, 0x51, 0x9b, 0xfa, 0xf3, + 0xa2, 0x36, 0xf5, 0xc5, 0xf6, 0x64, 0xdf, 0xb1, 0xd1, 0x7f, 0xb5, 0x8a, 0xf8, 0x43, 0xb5, 0xfb, + 0x5f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x48, 0xbd, 0x49, 0x69, 0x07, 0x0e, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -953,6 +1035,8 @@ type MsgClient interface { // DeployERC20 defines a governance operation for deploying an ERC20 contract // that binds to a native token DeployERC20(ctx context.Context, in *MsgDeployERC20, opts ...grpc.CallOption) (*MsgDeployERC20Response, error) + // UpgradeERC20 defines a governance operation for upgrading an ERC20 contract + UpgradeERC20(ctx context.Context, in *MsgUpgradeERC20, opts ...grpc.CallOption) (*MsgUpgradeERC20Response, error) } type msgClient struct { @@ -1053,6 +1137,15 @@ func (c *msgClient) DeployERC20(ctx context.Context, in *MsgDeployERC20, opts .. return out, nil } +func (c *msgClient) UpgradeERC20(ctx context.Context, in *MsgUpgradeERC20, opts ...grpc.CallOption) (*MsgUpgradeERC20Response, error) { + out := new(MsgUpgradeERC20Response) + err := c.cc.Invoke(ctx, "/irismod.token.v1.Msg/UpgradeERC20", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // MsgServer is the server API for Msg service. type MsgServer interface { // IssueToken defines a method for issuing a new token @@ -1081,6 +1174,8 @@ type MsgServer interface { // DeployERC20 defines a governance operation for deploying an ERC20 contract // that binds to a native token DeployERC20(context.Context, *MsgDeployERC20) (*MsgDeployERC20Response, error) + // UpgradeERC20 defines a governance operation for upgrading an ERC20 contract + UpgradeERC20(context.Context, *MsgUpgradeERC20) (*MsgUpgradeERC20Response, error) } // UnimplementedMsgServer can be embedded to have forward compatible implementations. @@ -1117,6 +1212,9 @@ func (*UnimplementedMsgServer) UpdateParams(ctx context.Context, req *MsgUpdateP func (*UnimplementedMsgServer) DeployERC20(ctx context.Context, req *MsgDeployERC20) (*MsgDeployERC20Response, error) { return nil, status.Errorf(codes.Unimplemented, "method DeployERC20 not implemented") } +func (*UnimplementedMsgServer) UpgradeERC20(ctx context.Context, req *MsgUpgradeERC20) (*MsgUpgradeERC20Response, error) { + return nil, status.Errorf(codes.Unimplemented, "method UpgradeERC20 not implemented") +} func RegisterMsgServer(s grpc1.Server, srv MsgServer) { s.RegisterService(&_Msg_serviceDesc, srv) @@ -1302,6 +1400,24 @@ func _Msg_DeployERC20_Handler(srv interface{}, ctx context.Context, dec func(int return interceptor(ctx, in, info, handler) } +func _Msg_UpgradeERC20_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgUpgradeERC20) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).UpgradeERC20(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/irismod.token.v1.Msg/UpgradeERC20", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).UpgradeERC20(ctx, req.(*MsgUpgradeERC20)) + } + return interceptor(ctx, in, info, handler) +} + var _Msg_serviceDesc = grpc.ServiceDesc{ ServiceName: "irismod.token.v1.Msg", HandlerType: (*MsgServer)(nil), @@ -1346,6 +1462,10 @@ var _Msg_serviceDesc = grpc.ServiceDesc{ MethodName: "DeployERC20", Handler: _Msg_DeployERC20_Handler, }, + { + MethodName: "UpgradeERC20", + Handler: _Msg_UpgradeERC20_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "irismod/token/v1/tx.proto", @@ -2091,6 +2211,66 @@ func (m *MsgSwapFromERC20Response) MarshalToSizedBuffer(dAtA []byte) (int, error return len(dAtA) - i, nil } +func (m *MsgUpgradeERC20) 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 *MsgUpgradeERC20) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpgradeERC20) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Authority) > 0 { + i -= len(m.Authority) + copy(dAtA[i:], m.Authority) + i = encodeVarintTx(dAtA, i, uint64(len(m.Authority))) + i-- + dAtA[i] = 0x12 + } + if len(m.Implementation) > 0 { + i -= len(m.Implementation) + copy(dAtA[i:], m.Implementation) + i = encodeVarintTx(dAtA, i, uint64(len(m.Implementation))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgUpgradeERC20Response) 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 *MsgUpgradeERC20Response) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpgradeERC20Response) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + func encodeVarintTx(dAtA []byte, offset int, v uint64) int { offset -= sovTx(v) base := offset @@ -2414,6 +2594,32 @@ func (m *MsgSwapFromERC20Response) Size() (n int) { return n } +func (m *MsgUpgradeERC20) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Implementation) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.Authority) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *MsgUpgradeERC20Response) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + func sovTx(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -4566,6 +4772,170 @@ func (m *MsgSwapFromERC20Response) Unmarshal(dAtA []byte) error { } return nil } +func (m *MsgUpgradeERC20) 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 ErrIntOverflowTx + } + 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: MsgUpgradeERC20: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgUpgradeERC20: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Implementation", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + 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 ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Implementation = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Authority", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + 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 ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Authority = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgUpgradeERC20Response) 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 ErrIntOverflowTx + } + 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: MsgUpgradeERC20Response: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgUpgradeERC20Response: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func skipTx(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 diff --git a/proto/irismod/token/v1/tx.proto b/proto/irismod/token/v1/tx.proto index db2f80cf..67cfc9de 100644 --- a/proto/irismod/token/v1/tx.proto +++ b/proto/irismod/token/v1/tx.proto @@ -50,6 +50,9 @@ service Msg { // DeployERC20 defines a governance operation for deploying an ERC20 contract // that binds to a native token rpc DeployERC20(MsgDeployERC20) returns (MsgDeployERC20Response); + + // UpgradeERC20 defines a governance operation for upgrading an ERC20 contract + rpc UpgradeERC20(MsgUpgradeERC20) returns (MsgUpgradeERC20Response); } // MsgIssueToken defines an SDK message for issuing a new token @@ -191,4 +194,16 @@ message MsgSwapFromERC20 { } // MsgSwapFromERC20Response defines the Msg/SwapFromERC20 response type -message MsgSwapFromERC20Response {} \ No newline at end of file +message MsgSwapFromERC20Response {} + +// MsgUpgradeERC20 defines an SDK message for UpgradeERC20 +message MsgUpgradeERC20 { + option (cosmos.msg.v1.signer) = "authority"; + + // implementation is the new erc20 contract address + string implementation = 1; + string authority = 2 [ (cosmos_proto.scalar) = "cosmos.AddressString" ]; +} + +// MsgUpgradeERC20Response defines the Msg/UpgradeERC20 response type +message MsgUpgradeERC20Response {} \ No newline at end of file From 50833ca16c74639054f66a06f76b887cbe2160c4 Mon Sep 17 00:00:00 2001 From: dreamer Date: Mon, 22 Apr 2024 14:08:12 +0800 Subject: [PATCH 6/7] fix test --- modules/token/types/v1/msgs.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/modules/token/types/v1/msgs.go b/modules/token/types/v1/msgs.go index cff0b48e..c89ce5f3 100644 --- a/modules/token/types/v1/msgs.go +++ b/modules/token/types/v1/msgs.go @@ -37,6 +37,7 @@ var ( _ sdk.Msg = &MsgDeployERC20{} _ sdk.Msg = &MsgSwapFromERC20{} _ sdk.Msg = &MsgSwapToERC20{} + _ sdk.Msg = &MsgUpgradeERC20{} regexpERC20Fmt = fmt.Sprintf("^[a-z][a-z0-9/]{%d,%d}$", tokentypes.MinimumSymbolLen-1, tokentypes.MaximumSymbolLen-1) regexpERC20 = regexp.MustCompile(regexpERC20Fmt).MatchString @@ -441,6 +442,24 @@ func (m *MsgSwapToERC20) GetSigners() []sdk.AccAddress { return []sdk.AccAddress{addr} } +// ValidateBasic implements Msg +func (m *MsgUpgradeERC20) ValidateBasic() error { + if _, err := sdk.AccAddressFromBech32(m.Authority); err != nil { + return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "invalid authority address (%s)", err) + } + + if !common.IsHexAddress(m.Implementation) { + return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "expecting a hex address, got %s", m.Implementation) + } + return nil +} + +// GetSigners returns the expected signers for a MsgUpgradeERC20 message +func (m *MsgUpgradeERC20) GetSigners() []sdk.AccAddress { + addr, _ := sdk.AccAddressFromBech32(m.Authority) + return []sdk.AccAddress{addr} +} + // ValidateERC20 validates ERC20 symbol or name func ValidateERC20(params string) error { if !regexpERC20(params) { From 4de9e6f79d84624d768cb7ce8bac7caadfbc0e04 Mon Sep 17 00:00:00 2001 From: dreamer Date: Mon, 22 Apr 2024 14:12:03 +0800 Subject: [PATCH 7/7] add Changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index aafa6fd3..39fdc966 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -49,6 +49,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * [\#405](https://github.com/irisnet/irismod/pull/405) Rolled back the cosmos-sdk version to v0.47.9. * [\#409](https://github.com/irisnet/irismod/pull/409) Add a switch for enabling erc20 swap function. * [\#410](https://github.com/irisnet/irismod/pull/410) Implement upgradeable contract. +* [\#411](https://github.com/irisnet/irismod/pull/411) Implement erc20 upgrade. ### Bug Fixes