From d865c259ab4993bd276b87e1620af055d1f3facb Mon Sep 17 00:00:00 2001 From: Oleg Nikonychev Date: Fri, 28 Jun 2024 16:48:07 +0400 Subject: [PATCH 1/2] feat(evm): tx for creating fun token from coin --- proto/eth/evm/v1/events.proto | 5 + proto/eth/evm/v1/tx.proto | 23 ++ x/evm/events.pb.go | 272 ++++++++++++++-- x/evm/keeper/funtoken_state.go | 6 +- x/evm/keeper/msg_fun_token.go | 37 +++ x/evm/msg.go | 13 + x/evm/tx.pb.go | 568 +++++++++++++++++++++++++++++---- 7 files changed, 836 insertions(+), 88 deletions(-) create mode 100644 x/evm/keeper/msg_fun_token.go diff --git a/proto/eth/evm/v1/events.proto b/proto/eth/evm/v1/events.proto index 853c3eaf8..af9c4e329 100644 --- a/proto/eth/evm/v1/events.proto +++ b/proto/eth/evm/v1/events.proto @@ -43,3 +43,8 @@ message EventBlockBloom { // bloom is the bloom filter of the block string bloom = 1; } + +message EventCreateFunTokenFromCoin { + string denom = 1; + string contract_address = 2; +} diff --git a/proto/eth/evm/v1/tx.proto b/proto/eth/evm/v1/tx.proto index 0cadc1866..cbdfcb78f 100644 --- a/proto/eth/evm/v1/tx.proto +++ b/proto/eth/evm/v1/tx.proto @@ -20,6 +20,9 @@ service Msg { // UpdateParams defined a governance operation for updating the x/evm module parameters. // The authority is hard-coded to the Cosmos SDK x/gov module account rpc UpdateParams(MsgUpdateParams) returns (MsgUpdateParamsResponse); + + // CreateFunTokenFromCoin registers existing cosmos coin as an evm erc-20 fungible token contract. + rpc CreateFunTokenFromCoin(MsgCreateFunTokenFromCoin) returns (MsgCreateFunTokenFromCoinResponse); } // MsgEthereumTx encapsulates an Ethereum transaction as an SDK message. @@ -176,3 +179,23 @@ message MsgUpdateParams { // MsgUpdateParamsResponse defines the response structure for executing a // MsgUpdateParams message. message MsgUpdateParamsResponse {} + + +// MsgCreateFunTokenFromCoin: sdk.Msg that registers cosmos denom as an evm erc-20 contract. +// A denom has the form "tf/[creatorAddr]/[subdenom]". +// - Denoms become unique x/bank tokens, so the creator-subdenom pair that +// defines a denom cannot be reused. +// - The resulting denom's admin is originally set to be the creator, but the +// admin can be changed later. +message MsgCreateFunTokenFromCoin { + string sender = 1 [ (gogoproto.moretags) = "yaml:\"sender\"" ]; + // cosmos denom. Ex: ibc/abc123def + string denom = 2 [ (gogoproto.moretags) = "yaml:\"denom\"" ]; +} + +// MsgCreateFunTokenFromCoinResponse is the return value of MsgCreateFunTokenFromCoin +message MsgCreateFunTokenFromCoinResponse { + // NewContractAddress: erc-20 contract address. Ex: 0x123abc456 + string new_contract_address = 1 + [ (gogoproto.moretags) = "yaml:\"new_contract_address\"" ]; +} diff --git a/x/evm/events.pb.go b/x/evm/events.pb.go index d7e35e49a..bc08804b8 100644 --- a/x/evm/events.pb.go +++ b/x/evm/events.pb.go @@ -278,40 +278,96 @@ func (m *EventBlockBloom) GetBloom() string { return "" } +type EventCreateFunTokenFromCoin struct { + Denom string `protobuf:"bytes,1,opt,name=denom,proto3" json:"denom,omitempty"` + ContractAddress string `protobuf:"bytes,2,opt,name=contract_address,json=contractAddress,proto3" json:"contract_address,omitempty"` +} + +func (m *EventCreateFunTokenFromCoin) Reset() { *m = EventCreateFunTokenFromCoin{} } +func (m *EventCreateFunTokenFromCoin) String() string { return proto.CompactTextString(m) } +func (*EventCreateFunTokenFromCoin) ProtoMessage() {} +func (*EventCreateFunTokenFromCoin) Descriptor() ([]byte, []int) { + return fileDescriptor_f8bc26b53c788f17, []int{4} +} +func (m *EventCreateFunTokenFromCoin) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *EventCreateFunTokenFromCoin) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_EventCreateFunTokenFromCoin.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 *EventCreateFunTokenFromCoin) XXX_Merge(src proto.Message) { + xxx_messageInfo_EventCreateFunTokenFromCoin.Merge(m, src) +} +func (m *EventCreateFunTokenFromCoin) XXX_Size() int { + return m.Size() +} +func (m *EventCreateFunTokenFromCoin) XXX_DiscardUnknown() { + xxx_messageInfo_EventCreateFunTokenFromCoin.DiscardUnknown(m) +} + +var xxx_messageInfo_EventCreateFunTokenFromCoin proto.InternalMessageInfo + +func (m *EventCreateFunTokenFromCoin) GetDenom() string { + if m != nil { + return m.Denom + } + return "" +} + +func (m *EventCreateFunTokenFromCoin) GetContractAddress() string { + if m != nil { + return m.ContractAddress + } + return "" +} + func init() { proto.RegisterType((*EventEthereumTx)(nil), "eth.evm.v1.EventEthereumTx") proto.RegisterType((*EventTxLog)(nil), "eth.evm.v1.EventTxLog") proto.RegisterType((*EventMessage)(nil), "eth.evm.v1.EventMessage") proto.RegisterType((*EventBlockBloom)(nil), "eth.evm.v1.EventBlockBloom") + proto.RegisterType((*EventCreateFunTokenFromCoin)(nil), "eth.evm.v1.EventCreateFunTokenFromCoin") } func init() { proto.RegisterFile("eth/evm/v1/events.proto", fileDescriptor_f8bc26b53c788f17) } var fileDescriptor_f8bc26b53c788f17 = []byte{ - // 363 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x44, 0x91, 0xc1, 0x6a, 0xdb, 0x40, - 0x10, 0x86, 0xad, 0xda, 0x96, 0xeb, 0x6d, 0x4b, 0x61, 0x29, 0xb5, 0x0a, 0x45, 0x18, 0x95, 0xd2, - 0x9e, 0x24, 0x4c, 0xcf, 0xbd, 0x38, 0x38, 0xe4, 0x90, 0xe4, 0x10, 0x14, 0x02, 0xb9, 0x88, 0x95, - 0x35, 0xd1, 0x2e, 0x91, 0xb4, 0x42, 0x3b, 0x12, 0xeb, 0xb7, 0xc8, 0x63, 0x05, 0x72, 0xf1, 0x31, - 0xc7, 0x60, 0xbf, 0x48, 0xd8, 0x95, 0x42, 0x6e, 0xf3, 0xff, 0x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0x06, 0xdc, 0x2b, 0xe3, 0x2b, 0xa8, 0x32, 0x68, 0x06, 0xdc, 0x41, 0x0d, 0xc1, 0xb8, 0xab, - 0x61, 0xe0, 0x75, 0x51, 0xc7, 0xbb, 0x1a, 0x82, 0x3f, 0xc3, 0x32, 0xd7, 0x85, 0xdc, 0xde, 0xaf, - 0x0b, 0x29, 0x4b, 0xb3, 0x99, 0xd4, 0x14, 0x43, 0x74, 0x2f, 0xd6, 0xff, 0x1f, 0x0f, 0xbe, 0xb3, - 0x3f, 0xf8, 0xce, 0xcb, 0xc1, 0x77, 0x1e, 0x8e, 0xfe, 0x68, 0x7f, 0xf4, 0x47, 0xcf, 0x47, 0x7f, - 0x74, 0xfb, 0x2b, 0x17, 0xc8, 0xdb, 0x34, 0xdc, 0xca, 0x32, 0xba, 0x14, 0xa9, 0x68, 0xda, 0x13, - 0xce, 0x44, 0x15, 0x55, 0xb6, 0x8e, 0xb4, 0xb9, 0x68, 0xea, 0xda, 0x43, 0xfe, 0x7b, 0x0d, 0x00, - 0x00, 0xff, 0xff, 0xba, 0x7a, 0xfa, 0x28, 0xe3, 0x01, 0x00, 0x00, + // 414 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x44, 0x92, 0xc1, 0x6e, 0xd4, 0x30, + 0x10, 0x86, 0x37, 0xb4, 0xdd, 0xa5, 0x06, 0x54, 0x64, 0x21, 0x1a, 0x04, 0x8a, 0xaa, 0x20, 0x04, + 0x5c, 0x36, 0xaa, 0x38, 0x73, 0x60, 0x57, 0x5d, 0x71, 0x00, 0x0e, 0x28, 0x08, 0x89, 0x03, 0x91, + 0x37, 0x1e, 0x62, 0xab, 0x89, 0x1d, 0xd9, 0x93, 0xc8, 0x7d, 0x0b, 0x1e, 0x0b, 0x89, 0x4b, 0x8f, + 0x1c, 0xd1, 0xee, 0x8b, 0x54, 0x76, 0x5c, 0xf5, 0x36, 0xff, 0x37, 0xf3, 0x4f, 0xf2, 0x5b, 0x43, + 0x4e, 0x01, 0x45, 0x01, 0x63, 0x57, 0x8c, 0xe7, 0x05, 0x8c, 0xa0, 0xd0, 0x2e, 0x7b, 0xa3, 0x51, + 0x53, 0x02, 0x28, 0x96, 0x30, 0x76, 0xcb, 0xf1, 0x3c, 0xff, 0x9b, 0x90, 0x93, 0x0b, 0xdf, 0xbc, + 0x40, 0x01, 0x06, 0x86, 0xae, 0x74, 0xf4, 0x29, 0x99, 0xb3, 0x4e, 0x0f, 0x0a, 0xd3, 0xe4, 0x2c, + 0x79, 0x73, 0xfc, 0x35, 0x2a, 0xfa, 0x8c, 0xdc, 0x07, 0x14, 0x95, 0x60, 0x56, 0xa4, 0xf7, 0x42, + 0x67, 0x01, 0x28, 0x3e, 0x32, 0x2b, 0xe8, 0x13, 0x72, 0x24, 0x15, 0x07, 0x97, 0x1e, 0x04, 0x3e, + 0x09, 0x6f, 0x68, 0x98, 0xad, 0x06, 0x0b, 0x3c, 0x3d, 0x9c, 0x0c, 0x0d, 0xb3, 0xdf, 0x2c, 0x70, + 0x4a, 0xc9, 0x61, 0xd8, 0x73, 0x14, 0x70, 0xa8, 0xe9, 0x0b, 0x72, 0x6c, 0xa0, 0x96, 0xbd, 0x04, + 0x85, 0xe9, 0x3c, 0x34, 0xee, 0x00, 0xcd, 0xc9, 0x23, 0xff, 0x75, 0x74, 0xd5, 0x2f, 0x26, 0x5b, + 0xe0, 0xe9, 0x22, 0x4c, 0x3c, 0x00, 0x14, 0xa5, 0xdb, 0x04, 0x94, 0xbf, 0x22, 0x24, 0x84, 0x29, + 0xdd, 0x27, 0xdd, 0xd0, 0x53, 0xb2, 0x40, 0x57, 0xb5, 0xba, 0xb1, 0x69, 0x72, 0x76, 0xe0, 0x83, + 0xa0, 0xe7, 0x36, 0xff, 0x4e, 0x1e, 0x86, 0xb1, 0xcf, 0x60, 0x2d, 0x6b, 0xc0, 0x07, 0xee, 0x34, + 0x1f, 0x5a, 0xb8, 0x0d, 0x3c, 0x29, 0xcf, 0x2d, 0x28, 0x0e, 0x26, 0xc6, 0x8d, 0x2a, 0x2e, 0xc6, + 0xab, 0x1e, 0x62, 0xde, 0x39, 0xba, 0xf2, 0xaa, 0x87, 0xfc, 0x75, 0x7c, 0xcc, 0x55, 0xab, 0xeb, + 0xcb, 0x55, 0xab, 0x75, 0xe7, 0x5f, 0x66, 0xeb, 0x8b, 0xb8, 0x7a, 0x12, 0xf9, 0x4f, 0xf2, 0x3c, + 0x0c, 0xae, 0x0d, 0x30, 0x84, 0xcd, 0xa0, 0x4a, 0x7d, 0x09, 0x6a, 0x63, 0x74, 0xb7, 0xd6, 0x52, + 0x79, 0x13, 0x07, 0x75, 0x67, 0x0a, 0x82, 0xbe, 0x25, 0x8f, 0x6b, 0xad, 0xd0, 0xb0, 0x1a, 0x2b, + 0xc6, 0xb9, 0x01, 0x6b, 0xe3, 0x8f, 0x9d, 0xdc, 0xf2, 0x0f, 0x13, 0x5e, 0xbd, 0xff, 0xb3, 0xcb, + 0x92, 0xeb, 0x5d, 0x96, 0xfc, 0xdf, 0x65, 0xc9, 0xef, 0x7d, 0x36, 0xbb, 0xde, 0x67, 0xb3, 0x7f, + 0xfb, 0x6c, 0xf6, 0xe3, 0x65, 0x23, 0x51, 0x0c, 0xdb, 0x65, 0xad, 0xbb, 0xe2, 0x8b, 0xdc, 0x4a, + 0x33, 0xac, 0x05, 0x93, 0xaa, 0x50, 0xa1, 0x2e, 0x9c, 0xbf, 0x98, 0xed, 0x3c, 0x1c, 0xca, 0xbb, + 0x9b, 0x00, 0x00, 0x00, 0xff, 0xff, 0x80, 0xd3, 0x1f, 0x8c, 0x43, 0x02, 0x00, 0x00, } func (m *EventEthereumTx) Marshal() (dAtA []byte, err error) { @@ -492,6 +548,43 @@ func (m *EventBlockBloom) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +func (m *EventCreateFunTokenFromCoin) 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 *EventCreateFunTokenFromCoin) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *EventCreateFunTokenFromCoin) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.ContractAddress) > 0 { + i -= len(m.ContractAddress) + copy(dAtA[i:], m.ContractAddress) + i = encodeVarintEvents(dAtA, i, uint64(len(m.ContractAddress))) + i-- + dAtA[i] = 0x12 + } + if len(m.Denom) > 0 { + i -= len(m.Denom) + copy(dAtA[i:], m.Denom) + i = encodeVarintEvents(dAtA, i, uint64(len(m.Denom))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + func encodeVarintEvents(dAtA []byte, offset int, v uint64) int { offset -= sovEvents(v) base := offset @@ -589,6 +682,23 @@ func (m *EventBlockBloom) Size() (n int) { return n } +func (m *EventCreateFunTokenFromCoin) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Denom) + if l > 0 { + n += 1 + l + sovEvents(uint64(l)) + } + l = len(m.ContractAddress) + if l > 0 { + n += 1 + l + sovEvents(uint64(l)) + } + return n +} + func sovEvents(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -1179,6 +1289,120 @@ func (m *EventBlockBloom) Unmarshal(dAtA []byte) error { } return nil } +func (m *EventCreateFunTokenFromCoin) 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 ErrIntOverflowEvents + } + 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: EventCreateFunTokenFromCoin: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: EventCreateFunTokenFromCoin: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Denom", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEvents + } + 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 ErrInvalidLengthEvents + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthEvents + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Denom = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ContractAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEvents + } + 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 ErrInvalidLengthEvents + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthEvents + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ContractAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipEvents(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthEvents + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func skipEvents(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 diff --git a/x/evm/keeper/funtoken_state.go b/x/evm/keeper/funtoken_state.go index c713c1fc3..daf6afce5 100644 --- a/x/evm/keeper/funtoken_state.go +++ b/x/evm/keeper/funtoken_state.go @@ -80,10 +80,10 @@ type IndexesFunToken struct { func (fun FunTokenState) SafeInsert( ctx sdk.Context, erc20 gethcommon.Address, bankDenom string, isMadeFromCoin bool, ) error { - funtoken := evm.NewFunToken(erc20, bankDenom, isMadeFromCoin) - if err := funtoken.Validate(); err != nil { + funToken := evm.NewFunToken(erc20, bankDenom, isMadeFromCoin) + if err := funToken.Validate(); err != nil { return err } - fun.Insert(ctx, funtoken.ID(), funtoken) + fun.Insert(ctx, funToken.ID(), funToken) return nil } diff --git a/x/evm/keeper/msg_fun_token.go b/x/evm/keeper/msg_fun_token.go new file mode 100644 index 000000000..62bbf499c --- /dev/null +++ b/x/evm/keeper/msg_fun_token.go @@ -0,0 +1,37 @@ +package keeper + +import ( + "context" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/ethereum/go-ethereum/common" + + "github.com/NibiruChain/nibiru/eth/crypto/ethsecp256k1" + "github.com/NibiruChain/nibiru/x/evm" +) + +// CreateFunTokenFromCoin registers existing cosmos coin as an evm erc-20 fungible token contract +func (k *Keeper) CreateFunTokenFromCoin( + goCtx context.Context, msg *evm.MsgCreateFunTokenFromCoin, +) (*evm.MsgCreateFunTokenFromCoinResponse, error) { + if err := msg.ValidateBasic(); err != nil { + return nil, err + } + priv, err := ethsecp256k1.GenerateKey() + if err != nil { + return nil, err + } + newContractAddress := common.BytesToAddress(priv.PubKey().Address().Bytes()) + ctx := sdk.UnwrapSDKContext(goCtx) + err = k.FunTokens.SafeInsert(ctx, newContractAddress, msg.Denom, true) + if err != nil { + return nil, err + } + + _ = ctx.EventManager().EmitTypedEvent(&evm.EventCreateFunTokenFromCoin{ + Denom: msg.Denom, + ContractAddress: newContractAddress.String(), + }) + + return &evm.MsgCreateFunTokenFromCoinResponse{NewContractAddress: newContractAddress.String()}, nil +} diff --git a/x/evm/msg.go b/x/evm/msg.go index d67ba6a97..6e86f8f0e 100644 --- a/x/evm/msg.go +++ b/x/evm/msg.go @@ -33,6 +33,7 @@ var ( _ sdk.Tx = &MsgEthereumTx{} _ ante.GasTx = &MsgEthereumTx{} _ sdk.Msg = &MsgUpdateParams{} + _ sdk.Msg = &MsgCreateFunTokenFromCoin{} _ codectypes.UnpackInterfacesMessage = MsgEthereumTx{} ) @@ -472,3 +473,15 @@ func BinSearch( } return hi, nil } + +func (msg *MsgCreateFunTokenFromCoin) ValidateBasic() error { + if err := sdk.ValidateDenom(msg.Denom); err != nil { + return errValidateFunToken(err.Error()) + } + return nil +} + +func (msg *MsgCreateFunTokenFromCoin) GetSigners() []sdk.AccAddress { + sender, _ := sdk.AccAddressFromBech32(msg.Sender) + return []sdk.AccAddress{sender} +} diff --git a/x/evm/tx.pb.go b/x/evm/tx.pb.go index b86d83cfa..30c45473c 100644 --- a/x/evm/tx.pb.go +++ b/x/evm/tx.pb.go @@ -440,6 +440,111 @@ func (m *MsgUpdateParamsResponse) XXX_DiscardUnknown() { var xxx_messageInfo_MsgUpdateParamsResponse proto.InternalMessageInfo +// MsgCreateFunTokenFromCoin: sdk.Msg that registers cosmos denom as an evm erc-20 contract. +// A denom has the form "tf/[creatorAddr]/[subdenom]". +// - Denoms become unique x/bank tokens, so the creator-subdenom pair that +// defines a denom cannot be reused. +// - The resulting denom's admin is originally set to be the creator, but the +// admin can be changed later. +type MsgCreateFunTokenFromCoin struct { + Sender string `protobuf:"bytes,1,opt,name=sender,proto3" json:"sender,omitempty" yaml:"sender"` + // cosmos denom. Ex: ibc/abc123def + Denom string `protobuf:"bytes,2,opt,name=denom,proto3" json:"denom,omitempty" yaml:"denom"` +} + +func (m *MsgCreateFunTokenFromCoin) Reset() { *m = MsgCreateFunTokenFromCoin{} } +func (m *MsgCreateFunTokenFromCoin) String() string { return proto.CompactTextString(m) } +func (*MsgCreateFunTokenFromCoin) ProtoMessage() {} +func (*MsgCreateFunTokenFromCoin) Descriptor() ([]byte, []int) { + return fileDescriptor_82a0bfe4f0bab953, []int{8} +} +func (m *MsgCreateFunTokenFromCoin) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgCreateFunTokenFromCoin) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgCreateFunTokenFromCoin.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 *MsgCreateFunTokenFromCoin) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgCreateFunTokenFromCoin.Merge(m, src) +} +func (m *MsgCreateFunTokenFromCoin) XXX_Size() int { + return m.Size() +} +func (m *MsgCreateFunTokenFromCoin) XXX_DiscardUnknown() { + xxx_messageInfo_MsgCreateFunTokenFromCoin.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgCreateFunTokenFromCoin proto.InternalMessageInfo + +func (m *MsgCreateFunTokenFromCoin) GetSender() string { + if m != nil { + return m.Sender + } + return "" +} + +func (m *MsgCreateFunTokenFromCoin) GetDenom() string { + if m != nil { + return m.Denom + } + return "" +} + +// MsgCreateFunTokenFromCoinResponse is the return value of MsgCreateFunTokenFromCoin +type MsgCreateFunTokenFromCoinResponse struct { + // NewContractAddress: erc-20 contract address. Ex: 0x123abc456 + NewContractAddress string `protobuf:"bytes,1,opt,name=new_contract_address,json=newContractAddress,proto3" json:"new_contract_address,omitempty" yaml:"new_contract_address"` +} + +func (m *MsgCreateFunTokenFromCoinResponse) Reset() { *m = MsgCreateFunTokenFromCoinResponse{} } +func (m *MsgCreateFunTokenFromCoinResponse) String() string { return proto.CompactTextString(m) } +func (*MsgCreateFunTokenFromCoinResponse) ProtoMessage() {} +func (*MsgCreateFunTokenFromCoinResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_82a0bfe4f0bab953, []int{9} +} +func (m *MsgCreateFunTokenFromCoinResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgCreateFunTokenFromCoinResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgCreateFunTokenFromCoinResponse.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 *MsgCreateFunTokenFromCoinResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgCreateFunTokenFromCoinResponse.Merge(m, src) +} +func (m *MsgCreateFunTokenFromCoinResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgCreateFunTokenFromCoinResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgCreateFunTokenFromCoinResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgCreateFunTokenFromCoinResponse proto.InternalMessageInfo + +func (m *MsgCreateFunTokenFromCoinResponse) GetNewContractAddress() string { + if m != nil { + return m.NewContractAddress + } + return "" +} + func init() { proto.RegisterType((*MsgEthereumTx)(nil), "eth.evm.v1.MsgEthereumTx") proto.RegisterType((*LegacyTx)(nil), "eth.evm.v1.LegacyTx") @@ -449,72 +554,82 @@ func init() { proto.RegisterType((*MsgEthereumTxResponse)(nil), "eth.evm.v1.MsgEthereumTxResponse") proto.RegisterType((*MsgUpdateParams)(nil), "eth.evm.v1.MsgUpdateParams") proto.RegisterType((*MsgUpdateParamsResponse)(nil), "eth.evm.v1.MsgUpdateParamsResponse") + proto.RegisterType((*MsgCreateFunTokenFromCoin)(nil), "eth.evm.v1.MsgCreateFunTokenFromCoin") + proto.RegisterType((*MsgCreateFunTokenFromCoinResponse)(nil), "eth.evm.v1.MsgCreateFunTokenFromCoinResponse") } func init() { proto.RegisterFile("eth/evm/v1/tx.proto", fileDescriptor_82a0bfe4f0bab953) } var fileDescriptor_82a0bfe4f0bab953 = []byte{ - // 956 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xbc, 0x95, 0xbf, 0x6f, 0x23, 0x45, - 0x14, 0xc7, 0xbd, 0xf6, 0xfa, 0xd7, 0xd8, 0xe4, 0xd0, 0x90, 0x53, 0xd6, 0xe6, 0xe4, 0x35, 0x9b, - 0xc6, 0x42, 0xca, 0x2e, 0x17, 0x24, 0xa4, 0x8b, 0x44, 0x11, 0x5f, 0x72, 0xe8, 0x50, 0x02, 0xd1, - 0xe2, 0x34, 0x34, 0xd6, 0x64, 0x3d, 0x19, 0x8f, 0xf0, 0xee, 0xac, 0x76, 0xc6, 0x96, 0x4d, 0x79, - 0x15, 0x12, 0x05, 0x20, 0x7a, 0x44, 0x4d, 0x45, 0x71, 0x05, 0xff, 0x01, 0x27, 0xaa, 0x13, 0x34, - 0x88, 0xc2, 0x20, 0x07, 0x09, 0x29, 0x25, 0x05, 0x35, 0x9a, 0x99, 0x75, 0x6c, 0xdf, 0xc9, 0x01, - 0x22, 0x74, 0xdd, 0xbc, 0x79, 0x3f, 0xe6, 0xcd, 0xf7, 0xb3, 0xfb, 0x06, 0xbc, 0x82, 0x45, 0xdf, - 0xc3, 0xa3, 0xd0, 0x1b, 0xdd, 0xf5, 0xc4, 0xd8, 0x8d, 0x13, 0x26, 0x18, 0x04, 0x58, 0xf4, 0x5d, - 0x3c, 0x0a, 0xdd, 0xd1, 0xdd, 0xfa, 0x56, 0xc0, 0x78, 0xc8, 0xb8, 0x17, 0x72, 0x22, 0x63, 0x42, - 0x4e, 0x74, 0x50, 0xbd, 0xa6, 0x1d, 0x5d, 0x65, 0x79, 0xda, 0x48, 0x5d, 0x9b, 0x4b, 0x45, 0x65, - 0x99, 0x74, 0x97, 0x30, 0xc2, 0x74, 0xb4, 0x5c, 0xa5, 0xbb, 0x77, 0x08, 0x63, 0x64, 0x80, 0x3d, - 0x14, 0x53, 0x0f, 0x45, 0x11, 0x13, 0x48, 0x50, 0x16, 0xcd, 0x2b, 0xd5, 0x52, 0xaf, 0xb2, 0xce, - 0x86, 0xe7, 0x1e, 0x8a, 0x26, 0xda, 0xe5, 0x7c, 0x66, 0x80, 0x97, 0x8e, 0x39, 0x39, 0x14, 0x7d, - 0x9c, 0xe0, 0x61, 0xd8, 0x19, 0xc3, 0x16, 0x30, 0x7b, 0x48, 0x20, 0xcb, 0x68, 0x1a, 0xad, 0xca, - 0xee, 0xa6, 0xab, 0x73, 0xdd, 0x79, 0xae, 0xbb, 0x1f, 0x4d, 0x7c, 0x15, 0x01, 0x6b, 0xc0, 0xe4, - 0xf4, 0x63, 0x6c, 0x65, 0x9b, 0x46, 0xcb, 0x68, 0xe7, 0x2f, 0xa7, 0xb6, 0xb1, 0xe3, 0xab, 0x2d, - 0x68, 0x03, 0xb3, 0x8f, 0x78, 0xdf, 0xca, 0x35, 0x8d, 0x56, 0xb9, 0x5d, 0xf9, 0x73, 0x6a, 0x17, - 0x93, 0x41, 0xbc, 0xe7, 0xec, 0x38, 0xbe, 0x72, 0x40, 0x08, 0xcc, 0xf3, 0x84, 0x85, 0x96, 0x29, - 0x03, 0x7c, 0xb5, 0xde, 0x33, 0x3f, 0xf9, 0xda, 0xce, 0x38, 0x5f, 0x64, 0x41, 0xe9, 0x08, 0x13, - 0x14, 0x4c, 0x3a, 0x63, 0xb8, 0x09, 0xf2, 0x11, 0x8b, 0x02, 0xac, 0xba, 0x31, 0x7d, 0x6d, 0xc0, - 0xb7, 0x40, 0x99, 0x20, 0xa9, 0x19, 0x0d, 0xf4, 0xe9, 0xe5, 0x76, 0xed, 0x97, 0xa9, 0x7d, 0x5b, - 0xcb, 0xc7, 0x7b, 0x1f, 0xb9, 0x94, 0x79, 0x21, 0x12, 0x7d, 0xf7, 0x61, 0x24, 0xfc, 0x12, 0x41, - 0xfc, 0x44, 0x86, 0xc2, 0x06, 0xc8, 0x11, 0xc4, 0x55, 0x53, 0x66, 0xbb, 0x3a, 0x9b, 0xda, 0xa5, - 0x77, 0x10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f, 0x34, 0x32, 0x1f, 0x6e, 0x13, 0x2a, 0xfa, 0xc3, 0x33, 0x37, 0x60, 0xa1, 0xf7, 0x9e, - 0xea, 0x48, 0xcd, 0x86, 0x79, 0x77, 0x63, 0xd9, 0xdf, 0x59, 0x41, 0x3d, 0xd4, 0x6f, 0xfe, 0x1d, - 0x00, 0x00, 0xff, 0xff, 0x10, 0x4e, 0x86, 0x00, 0x93, 0x08, 0x00, 0x00, + // 1086 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xbc, 0x56, 0xcd, 0x6f, 0xe3, 0x44, + 0x14, 0xaf, 0x13, 0xe7, 0x6b, 0x92, 0xfd, 0xc0, 0x74, 0xa9, 0x93, 0x5d, 0xc5, 0x59, 0x57, 0xa0, + 0x80, 0x54, 0x9b, 0x2d, 0x12, 0xd2, 0x56, 0xe2, 0xd0, 0xf4, 0x03, 0x2d, 0x6a, 0xa1, 0x98, 0xf4, + 0xc2, 0x25, 0x9a, 0xda, 0x53, 0xc7, 0xda, 0x78, 0xc6, 0xf2, 0x4c, 0xb2, 0x09, 0xc7, 0x3d, 0x21, + 0x71, 0x00, 0xc4, 0x1d, 0x71, 0xe6, 0xc4, 0x61, 0x25, 0xf8, 0x13, 0x56, 0x9c, 0x56, 0x70, 0x41, + 0x1c, 0x0c, 0x6a, 0x91, 0x90, 0x7a, 0xec, 0x81, 0x33, 0x9a, 0x19, 0xe7, 0xab, 0xbb, 0x29, 0xcb, + 0x0a, 0x71, 0x9b, 0xf7, 0xde, 0xef, 0xbd, 0x79, 0xf3, 0xfb, 0x8d, 0xdf, 0x18, 0xbc, 0x8c, 0x58, + 0xd7, 0x46, 0x83, 0xd0, 0x1e, 0xdc, 0xb1, 0xd9, 0xd0, 0x8a, 0x62, 0xc2, 0x88, 0x06, 0x10, 0xeb, + 0x5a, 0x68, 0x10, 0x5a, 0x83, 0x3b, 0xb5, 0x15, 0x97, 0xd0, 0x90, 0x50, 0x3b, 0xa4, 0x3e, 0xc7, + 0x84, 0xd4, 0x97, 0xa0, 0x5a, 0x55, 0x06, 0x3a, 0xc2, 0xb2, 0xa5, 0x91, 0x86, 0x96, 0x67, 0x8a, + 0xf2, 0x32, 0xa9, 0xd7, 0x27, 0x3e, 0x91, 0x68, 0xbe, 0x4a, 0xbd, 0xb7, 0x7c, 0x42, 0xfc, 0x1e, + 0xb2, 0x61, 0x14, 0xd8, 0x10, 0x63, 0xc2, 0x20, 0x0b, 0x08, 0x1e, 0x57, 0xaa, 0xa6, 0x51, 0x61, + 0x1d, 0xf5, 0x8f, 0x6d, 0x88, 0x47, 0x32, 0x64, 0x7e, 0xae, 0x80, 0x2b, 0xfb, 0xd4, 0xdf, 0x61, + 0x5d, 0x14, 0xa3, 0x7e, 0xd8, 0x1e, 0x6a, 0x4d, 0xa0, 0x7a, 0x90, 0x41, 0x5d, 0x69, 0x28, 0xcd, + 0xf2, 0xfa, 0xb2, 0x25, 0x73, 0xad, 0x71, 0xae, 0xb5, 0x89, 0x47, 0x8e, 0x40, 0x68, 0x55, 0xa0, + 0xd2, 0xe0, 0x13, 0xa4, 0x67, 0x1a, 0x4a, 0x53, 0x69, 0xe5, 0xce, 0x12, 0x43, 0x59, 0x73, 0x84, + 0x4b, 0x33, 0x80, 0xda, 0x85, 0xb4, 0xab, 0x67, 0x1b, 0x4a, 0xb3, 0xd4, 0x2a, 0x9f, 0x27, 0x46, + 0x21, 0xee, 0x45, 0x1b, 0xe6, 0x9a, 0xe9, 0x88, 0x80, 0xa6, 0x01, 0xf5, 0x38, 0x26, 0xa1, 0xae, + 0x72, 0x80, 0x23, 0xd6, 0x1b, 0xea, 0xa7, 0xdf, 0x18, 0x4b, 0xe6, 0x97, 0x19, 0x50, 0xdc, 0x43, + 0x3e, 0x74, 0x47, 0xed, 0xa1, 0xb6, 0x0c, 0x72, 0x98, 0x60, 0x17, 0x89, 0x6e, 0x54, 0x47, 0x1a, + 0xda, 0xd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f, 0x64, 0xb9, 0x24, 0xb4, + 0xdf, 0x17, 0x0c, 0x88, 0x99, 0x3b, 0x66, 0x63, 0xc8, 0xf9, 0x38, 0xca, 0x8b, 0x1f, 0xa0, 0xb7, + 0xfe, 0x0e, 0x00, 0x00, 0xff, 0xff, 0xe7, 0xe6, 0x4b, 0x0b, 0xeb, 0x09, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -534,6 +649,8 @@ type MsgClient interface { // UpdateParams defined a governance operation for updating the x/evm module parameters. // The authority is hard-coded to the Cosmos SDK x/gov module account UpdateParams(ctx context.Context, in *MsgUpdateParams, opts ...grpc.CallOption) (*MsgUpdateParamsResponse, error) + // CreateFunTokenFromCoin registers existing cosmos coin as an evm erc-20 fungible token contract. + CreateFunTokenFromCoin(ctx context.Context, in *MsgCreateFunTokenFromCoin, opts ...grpc.CallOption) (*MsgCreateFunTokenFromCoinResponse, error) } type msgClient struct { @@ -562,6 +679,15 @@ func (c *msgClient) UpdateParams(ctx context.Context, in *MsgUpdateParams, opts return out, nil } +func (c *msgClient) CreateFunTokenFromCoin(ctx context.Context, in *MsgCreateFunTokenFromCoin, opts ...grpc.CallOption) (*MsgCreateFunTokenFromCoinResponse, error) { + out := new(MsgCreateFunTokenFromCoinResponse) + err := c.cc.Invoke(ctx, "/eth.evm.v1.Msg/CreateFunTokenFromCoin", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // MsgServer is the server API for Msg service. type MsgServer interface { // EthereumTx defines a method submitting Ethereum transactions. @@ -569,6 +695,8 @@ type MsgServer interface { // UpdateParams defined a governance operation for updating the x/evm module parameters. // The authority is hard-coded to the Cosmos SDK x/gov module account UpdateParams(context.Context, *MsgUpdateParams) (*MsgUpdateParamsResponse, error) + // CreateFunTokenFromCoin registers existing cosmos coin as an evm erc-20 fungible token contract. + CreateFunTokenFromCoin(context.Context, *MsgCreateFunTokenFromCoin) (*MsgCreateFunTokenFromCoinResponse, error) } // UnimplementedMsgServer can be embedded to have forward compatible implementations. @@ -581,6 +709,9 @@ func (*UnimplementedMsgServer) EthereumTx(ctx context.Context, req *MsgEthereumT func (*UnimplementedMsgServer) UpdateParams(ctx context.Context, req *MsgUpdateParams) (*MsgUpdateParamsResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method UpdateParams not implemented") } +func (*UnimplementedMsgServer) CreateFunTokenFromCoin(ctx context.Context, req *MsgCreateFunTokenFromCoin) (*MsgCreateFunTokenFromCoinResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method CreateFunTokenFromCoin not implemented") +} func RegisterMsgServer(s grpc1.Server, srv MsgServer) { s.RegisterService(&_Msg_serviceDesc, srv) @@ -622,6 +753,24 @@ func _Msg_UpdateParams_Handler(srv interface{}, ctx context.Context, dec func(in return interceptor(ctx, in, info, handler) } +func _Msg_CreateFunTokenFromCoin_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgCreateFunTokenFromCoin) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).CreateFunTokenFromCoin(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/eth.evm.v1.Msg/CreateFunTokenFromCoin", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).CreateFunTokenFromCoin(ctx, req.(*MsgCreateFunTokenFromCoin)) + } + return interceptor(ctx, in, info, handler) +} + var _Msg_serviceDesc = grpc.ServiceDesc{ ServiceName: "eth.evm.v1.Msg", HandlerType: (*MsgServer)(nil), @@ -634,6 +783,10 @@ var _Msg_serviceDesc = grpc.ServiceDesc{ MethodName: "UpdateParams", Handler: _Msg_UpdateParams_Handler, }, + { + MethodName: "CreateFunTokenFromCoin", + Handler: _Msg_CreateFunTokenFromCoin_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "eth/evm/v1/tx.proto", @@ -1183,6 +1336,73 @@ func (m *MsgUpdateParamsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) return len(dAtA) - i, nil } +func (m *MsgCreateFunTokenFromCoin) 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 *MsgCreateFunTokenFromCoin) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgCreateFunTokenFromCoin) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Denom) > 0 { + i -= len(m.Denom) + copy(dAtA[i:], m.Denom) + i = encodeVarintTx(dAtA, i, uint64(len(m.Denom))) + i-- + dAtA[i] = 0x12 + } + if len(m.Sender) > 0 { + i -= len(m.Sender) + copy(dAtA[i:], m.Sender) + i = encodeVarintTx(dAtA, i, uint64(len(m.Sender))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgCreateFunTokenFromCoinResponse) 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 *MsgCreateFunTokenFromCoinResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgCreateFunTokenFromCoinResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.NewContractAddress) > 0 { + i -= len(m.NewContractAddress) + copy(dAtA[i:], m.NewContractAddress) + i = encodeVarintTx(dAtA, i, uint64(len(m.NewContractAddress))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + func encodeVarintTx(dAtA []byte, offset int, v uint64) int { offset -= sovTx(v) base := offset @@ -1434,6 +1654,36 @@ func (m *MsgUpdateParamsResponse) Size() (n int) { return n } +func (m *MsgCreateFunTokenFromCoin) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Sender) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.Denom) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *MsgCreateFunTokenFromCoinResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.NewContractAddress) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + return n +} + func sovTx(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -3177,6 +3427,202 @@ func (m *MsgUpdateParamsResponse) Unmarshal(dAtA []byte) error { } return nil } +func (m *MsgCreateFunTokenFromCoin) 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: MsgCreateFunTokenFromCoin: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgCreateFunTokenFromCoin: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Sender", 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.Sender = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Denom", 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.Denom = 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 *MsgCreateFunTokenFromCoinResponse) 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: MsgCreateFunTokenFromCoinResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgCreateFunTokenFromCoinResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field NewContractAddress", 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.NewContractAddress = 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 skipTx(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 From 193196906ee23d2d7916e4d0e9373e3d8e749f5f Mon Sep 17 00:00:00 2001 From: Oleg Nikonychev Date: Fri, 28 Jun 2024 20:14:38 +0400 Subject: [PATCH 2/2] test(evm): test for creating fun token from coin --- CHANGELOG.md | 1 + proto/eth/evm/v1/events.proto | 1 + proto/eth/evm/v1/tx.proto | 7 +- x/evm/events.pb.go | 106 +++++++++++++++++++++-------- x/evm/keeper/msg_fun_token.go | 1 + x/evm/keeper/msg_fun_token_test.go | 62 +++++++++++++++++ x/evm/msg.go | 4 ++ x/evm/tx.pb.go | 7 +- 8 files changed, 150 insertions(+), 39 deletions(-) create mode 100644 x/evm/keeper/msg_fun_token_test.go diff --git a/CHANGELOG.md b/CHANGELOG.md index 5694d65ed..7aa3945a7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -77,6 +77,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - [#1917](https://github.com/NibiruChain/nibiru/pull/1917) - test(e2e-evm): TypeScript support. Type generation from compiled contracts. Formatter for TS code. - [#1922](https://github.com/NibiruChain/nibiru/pull/1922) - feat(evm): tracer option is read from the config. - [#1936](https://github.com/NibiruChain/nibiru/pull/1936) - feat(evm): EVM fungible token protobufs and encoding tests +- [#1946](https://github.com/NibiruChain/nibiru/pull/1946) - feat(evm): tx for creating fun token from coin #### Dapp modules: perp, spot, oracle, etc diff --git a/proto/eth/evm/v1/events.proto b/proto/eth/evm/v1/events.proto index af9c4e329..7def34b4c 100644 --- a/proto/eth/evm/v1/events.proto +++ b/proto/eth/evm/v1/events.proto @@ -47,4 +47,5 @@ message EventBlockBloom { message EventCreateFunTokenFromCoin { string denom = 1; string contract_address = 2; + string creator = 3; } diff --git a/proto/eth/evm/v1/tx.proto b/proto/eth/evm/v1/tx.proto index cbdfcb78f..5a6da4aec 100644 --- a/proto/eth/evm/v1/tx.proto +++ b/proto/eth/evm/v1/tx.proto @@ -181,12 +181,7 @@ message MsgUpdateParams { message MsgUpdateParamsResponse {} -// MsgCreateFunTokenFromCoin: sdk.Msg that registers cosmos denom as an evm erc-20 contract. -// A denom has the form "tf/[creatorAddr]/[subdenom]". -// - Denoms become unique x/bank tokens, so the creator-subdenom pair that -// defines a denom cannot be reused. -// - The resulting denom's admin is originally set to be the creator, but the -// admin can be changed later. +// MsgCreateFunTokenFromCoin: sdk.Msg that registers cosmos denom as an evm erc-20 contract message MsgCreateFunTokenFromCoin { string sender = 1 [ (gogoproto.moretags) = "yaml:\"sender\"" ]; // cosmos denom. Ex: ibc/abc123def diff --git a/x/evm/events.pb.go b/x/evm/events.pb.go index bc08804b8..0a2d7294d 100644 --- a/x/evm/events.pb.go +++ b/x/evm/events.pb.go @@ -281,6 +281,7 @@ func (m *EventBlockBloom) GetBloom() string { type EventCreateFunTokenFromCoin struct { Denom string `protobuf:"bytes,1,opt,name=denom,proto3" json:"denom,omitempty"` ContractAddress string `protobuf:"bytes,2,opt,name=contract_address,json=contractAddress,proto3" json:"contract_address,omitempty"` + Creator string `protobuf:"bytes,3,opt,name=creator,proto3" json:"creator,omitempty"` } func (m *EventCreateFunTokenFromCoin) Reset() { *m = EventCreateFunTokenFromCoin{} } @@ -330,6 +331,13 @@ func (m *EventCreateFunTokenFromCoin) GetContractAddress() string { return "" } +func (m *EventCreateFunTokenFromCoin) GetCreator() string { + if m != nil { + return m.Creator + } + return "" +} + func init() { proto.RegisterType((*EventEthereumTx)(nil), "eth.evm.v1.EventEthereumTx") proto.RegisterType((*EventTxLog)(nil), "eth.evm.v1.EventTxLog") @@ -341,33 +349,34 @@ func init() { func init() { proto.RegisterFile("eth/evm/v1/events.proto", fileDescriptor_f8bc26b53c788f17) } var fileDescriptor_f8bc26b53c788f17 = []byte{ - // 414 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x44, 0x92, 0xc1, 0x6e, 0xd4, 0x30, - 0x10, 0x86, 0x37, 0xb4, 0xdd, 0xa5, 0x06, 0x54, 0x64, 0x21, 0x1a, 0x04, 0x8a, 0xaa, 0x20, 0x04, - 0x5c, 0x36, 0xaa, 0x38, 0x73, 0x60, 0x57, 0x5d, 0x71, 0x00, 0x0e, 0x28, 0x08, 0x89, 0x03, 0x91, - 0x37, 0x1e, 0x62, 0xab, 0x89, 0x1d, 0xd9, 0x93, 0xc8, 0x7d, 0x0b, 0x1e, 0x0b, 0x89, 0x4b, 0x8f, - 0x1c, 0xd1, 0xee, 0x8b, 0x54, 0x76, 0x5c, 0xf5, 0x36, 0xff, 0x37, 0xf3, 0x4f, 0xf2, 0x5b, 0x43, - 0x4e, 0x01, 0x45, 0x01, 0x63, 0x57, 0x8c, 0xe7, 0x05, 0x8c, 0xa0, 0xd0, 0x2e, 0x7b, 0xa3, 0x51, - 0x53, 0x02, 0x28, 0x96, 0x30, 0x76, 0xcb, 0xf1, 0x3c, 0xff, 0x9b, 0x90, 0x93, 0x0b, 0xdf, 0xbc, - 0x40, 0x01, 0x06, 0x86, 0xae, 0x74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 0x4f, 0xf2, 0x3c, - 0x0c, 0xae, 0x0d, 0x30, 0x84, 0xcd, 0xa0, 0x4a, 0x7d, 0x09, 0x6a, 0x63, 0x74, 0xb7, 0xd6, 0x52, - 0x79, 0x13, 0x07, 0x75, 0x67, 0x0a, 0x82, 0xbe, 0x25, 0x8f, 0x6b, 0xad, 0xd0, 0xb0, 0x1a, 0x2b, - 0xc6, 0xb9, 0x01, 0x6b, 0xe3, 0x8f, 0x9d, 0xdc, 0xf2, 0x0f, 0x13, 0x5e, 0xbd, 0xff, 0xb3, 0xcb, - 0x92, 0xeb, 0x5d, 0x96, 0xfc, 0xdf, 0x65, 0xc9, 0xef, 0x7d, 0x36, 0xbb, 0xde, 0x67, 0xb3, 0x7f, - 0xfb, 0x6c, 0xf6, 0xe3, 0x65, 0x23, 0x51, 0x0c, 0xdb, 0x65, 0xad, 0xbb, 0xe2, 0x8b, 0xdc, 0x4a, - 0x33, 0xac, 0x05, 0x93, 0xaa, 0x50, 0xa1, 0x2e, 0x9c, 0xbf, 0x98, 0xed, 0x3c, 0x1c, 0xca, 0xbb, - 0x9b, 0x00, 0x00, 0x00, 0xff, 0xff, 0x80, 0xd3, 0x1f, 0x8c, 0x43, 0x02, 0x00, 0x00, + // 423 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x44, 0x92, 0x41, 0x8b, 0xd4, 0x30, + 0x14, 0xc7, 0xa7, 0xee, 0xee, 0x8c, 0x1b, 0x95, 0x95, 0x20, 0x6e, 0x45, 0x29, 0x4b, 0x45, 0xd4, + 0xcb, 0x94, 0xc5, 0xb3, 0x07, 0x67, 0xd8, 0xc1, 0x83, 0x7a, 0x90, 0x8a, 0xe0, 0xa5, 0x64, 0x9a, + 0x67, 0x13, 0xb6, 0x4d, 0x4a, 0xf2, 0x5a, 0xb2, 0xdf, 0xc2, 0x8f, 0x25, 0x78, 0xd9, 0xa3, 0x47, + 0x99, 0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, 0x06, 0x6b, 0x59, 0x03, 0x3e, 0x70, 0xa7, 0xf9, + 0xd0, 0xc2, 0x21, 0xf0, 0xa4, 0x3c, 0xb7, 0xa0, 0x38, 0x98, 0x18, 0x37, 0xaa, 0x68, 0x8c, 0x37, + 0x3d, 0xc4, 0xbc, 0x73, 0x74, 0xe5, 0x4d, 0x0f, 0xf9, 0xeb, 0xf8, 0x98, 0xab, 0x56, 0xd7, 0xd7, + 0xab, 0x56, 0xeb, 0xce, 0xbf, 0xcc, 0xd6, 0x17, 0xd1, 0x7a, 0x12, 0xb9, 0x23, 0xcf, 0xc3, 0xe0, + 0xda, 0x00, 0x43, 0xd8, 0x0c, 0xaa, 0xd4, 0xd7, 0xa0, 0x36, 0x46, 0x77, 0x6b, 0x2d, 0x95, 0x5f, + 0xe2, 0xa0, 0xee, 0x96, 0x82, 0xa0, 0x6f, 0xc9, 0xe3, 0x5a, 0x2b, 0x34, 0xac, 0xc6, 0x8a, 0x71, + 0x6e, 0xc0, 0xda, 0x78, 0xb1, 0xb3, 0x03, 0xff, 0x30, 0x61, 0x9a, 0x92, 0x45, 0xed, 0xad, 0xb5, + 0x89, 0x37, 0x3c, 0xc8, 0xd5, 0xfb, 0xdf, 0xbb, 0x2c, 0xb9, 0xdd, 0x65, 0xc9, 0xbf, 0x5d, 0x96, + 0xfc, 0xda, 0x67, 0xb3, 0xdb, 0x7d, 0x36, 0xfb, 0xbb, 0xcf, 0x66, 0x3f, 0x5e, 0x36, 0x12, 0xc5, + 0xb0, 0x5d, 0xd6, 0xba, 0x2b, 0xbe, 0xc8, 0xad, 0x34, 0xc3, 0x5a, 0x30, 0xa9, 0x0a, 0x15, 0xea, + 0xc2, 0xf9, 0xbf, 0xb4, 0x9d, 0x87, 0x2f, 0xf4, 0xee, 0x7f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x49, + 0x85, 0xed, 0x77, 0x5d, 0x02, 0x00, 0x00, } func (m *EventEthereumTx) Marshal() (dAtA []byte, err error) { @@ -568,6 +577,13 @@ func (m *EventCreateFunTokenFromCoin) MarshalToSizedBuffer(dAtA []byte) (int, er _ = i var l int _ = l + if len(m.Creator) > 0 { + i -= len(m.Creator) + copy(dAtA[i:], m.Creator) + i = encodeVarintEvents(dAtA, i, uint64(len(m.Creator))) + i-- + dAtA[i] = 0x1a + } if len(m.ContractAddress) > 0 { i -= len(m.ContractAddress) copy(dAtA[i:], m.ContractAddress) @@ -696,6 +712,10 @@ func (m *EventCreateFunTokenFromCoin) Size() (n int) { if l > 0 { n += 1 + l + sovEvents(uint64(l)) } + l = len(m.Creator) + if l > 0 { + n += 1 + l + sovEvents(uint64(l)) + } return n } @@ -1382,6 +1402,38 @@ func (m *EventCreateFunTokenFromCoin) Unmarshal(dAtA []byte) error { } m.ContractAddress = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Creator", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEvents + } + 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 ErrInvalidLengthEvents + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthEvents + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Creator = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipEvents(dAtA[iNdEx:]) diff --git a/x/evm/keeper/msg_fun_token.go b/x/evm/keeper/msg_fun_token.go index 62bbf499c..18ba86565 100644 --- a/x/evm/keeper/msg_fun_token.go +++ b/x/evm/keeper/msg_fun_token.go @@ -29,6 +29,7 @@ func (k *Keeper) CreateFunTokenFromCoin( } _ = ctx.EventManager().EmitTypedEvent(&evm.EventCreateFunTokenFromCoin{ + Creator: msg.Sender, Denom: msg.Denom, ContractAddress: newContractAddress.String(), }) diff --git a/x/evm/keeper/msg_fun_token_test.go b/x/evm/keeper/msg_fun_token_test.go new file mode 100644 index 000000000..23a52708e --- /dev/null +++ b/x/evm/keeper/msg_fun_token_test.go @@ -0,0 +1,62 @@ +package keeper_test + +import ( + testutilevents "github.com/NibiruChain/nibiru/x/common/testutil" + "github.com/NibiruChain/nibiru/x/evm" + "github.com/NibiruChain/nibiru/x/evm/evmtest" +) + +func (s *KeeperSuite) TestMsgCreateFunTokenFromCoin() { + testCases := []struct { + name string + denom string + sender string + wantErr string + }{ + { + name: "happy: proper coin name", + denom: "tf/creator/usdt", + sender: "nibi1zaavvzxez0elundtn32qnk9lkm8kmcsz44g7xl", + wantErr: "", + }, + { + name: "sad: empty coin name", + denom: "", + sender: "nibi1zaavvzxez0elundtn32qnk9lkm8kmcsz44g7xl", + wantErr: "invalid denom", + }, + { + name: "sad: invalid sender", + denom: "tf/creator/usdt", + sender: "12345", + wantErr: "invalid sender", + }, + } + + for _, tc := range testCases { + s.Run(tc.name, func() { + deps := evmtest.NewTestDeps() + resp, err := deps.Chain.EvmKeeper.CreateFunTokenFromCoin( + deps.GoCtx(), &evm.MsgCreateFunTokenFromCoin{ + Denom: tc.denom, + Sender: tc.sender, + }, + ) + if tc.wantErr != "" { + s.Require().ErrorContains(err, tc.wantErr) + return + } + s.Assert().NoError(err) + s.Require().NotNil(resp) + testutilevents.RequireContainsTypedEvent( + s.T(), + deps.Ctx, + &evm.EventCreateFunTokenFromCoin{ + Creator: tc.sender, + Denom: tc.denom, + ContractAddress: resp.NewContractAddress, + }, + ) + }) + } +} diff --git a/x/evm/msg.go b/x/evm/msg.go index 6e86f8f0e..92db9224c 100644 --- a/x/evm/msg.go +++ b/x/evm/msg.go @@ -475,6 +475,10 @@ func BinSearch( } func (msg *MsgCreateFunTokenFromCoin) ValidateBasic() error { + _, err := sdk.AccAddressFromBech32(msg.Sender) + if err != nil { + return fmt.Errorf("invalid sender: %s", msg.Sender) + } if err := sdk.ValidateDenom(msg.Denom); err != nil { return errValidateFunToken(err.Error()) } diff --git a/x/evm/tx.pb.go b/x/evm/tx.pb.go index 30c45473c..2d3f6f964 100644 --- a/x/evm/tx.pb.go +++ b/x/evm/tx.pb.go @@ -440,12 +440,7 @@ func (m *MsgUpdateParamsResponse) XXX_DiscardUnknown() { var xxx_messageInfo_MsgUpdateParamsResponse proto.InternalMessageInfo -// MsgCreateFunTokenFromCoin: sdk.Msg that registers cosmos denom as an evm erc-20 contract. -// A denom has the form "tf/[creatorAddr]/[subdenom]". -// - Denoms become unique x/bank tokens, so the creator-subdenom pair that -// defines a denom cannot be reused. -// - The resulting denom's admin is originally set to be the creator, but the -// admin can be changed later. +// MsgCreateFunTokenFromCoin: sdk.Msg that registers cosmos denom as an evm erc-20 contract type MsgCreateFunTokenFromCoin struct { Sender string `protobuf:"bytes,1,opt,name=sender,proto3" json:"sender,omitempty" yaml:"sender"` // cosmos denom. Ex: ibc/abc123def