From 831440286a82e64db4d0850bf74fffe83e4a472a Mon Sep 17 00:00:00 2001 From: Unique-Divine Date: Mon, 3 Jul 2023 03:53:50 -0500 Subject: [PATCH 1/7] refactor(oracle)!: use typed events for exchange rate changes --- proto/nibiru/oracle/v1/event.proto | 15 +- x/oracle/keeper/keeper.go | 8 +- x/oracle/keeper/msg_server.go | 15 +- x/oracle/keeper/querier_test.go | 8 +- x/oracle/keeper/update_exchange_rates.go | 11 +- x/oracle/types/event.pb.go | 331 +++++++++++++++++++---- x/oracle/types/events.go | 1 - 7 files changed, 310 insertions(+), 79 deletions(-) diff --git a/proto/nibiru/oracle/v1/event.proto b/proto/nibiru/oracle/v1/event.proto index 016308827..d334957c3 100644 --- a/proto/nibiru/oracle/v1/event.proto +++ b/proto/nibiru/oracle/v1/event.proto @@ -8,11 +8,22 @@ import "google/api/annotations.proto"; option go_package = "github.com/NibiruChain/nibiru/x/oracle/types"; // Emitted when a price is posted -message OraclePriceUpdate { +message EventExchangeRateUpdate { string pair = 1; - string price = 2 [ + string exchange_rate = 2 [ (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false ]; int64 timestamp_ms = 3; } + +// Emitted when a valoper delegates oracle voting rights to a feeder address. +message EventDelegateFeederConsent { + // Feeder is the delegate or representative that will be able to send + // vote and prevote transaction messages. + string feeder = 1; + + // Operator is the delegator, a valdiator operator that is delegating + // voting rights. + string operator = 2; +} diff --git a/x/oracle/keeper/keeper.go b/x/oracle/keeper/keeper.go index 16aae7bb4..f218365ad 100644 --- a/x/oracle/keeper/keeper.go +++ b/x/oracle/keeper/keeper.go @@ -199,10 +199,10 @@ func (k Keeper) SetPrice(ctx sdk.Context, pair asset.Pair, price sdk.Dec) { Price: price, TimestampMs: timestampMs, }) - if err := ctx.EventManager().EmitTypedEvent(&types.OraclePriceUpdate{ - Pair: pair.String(), - Price: price, - TimestampMs: timestampMs, + if err := ctx.EventManager().EmitTypedEvent(&types.EventExchangeRateUpdate{ + Pair: pair.String(), + ExchangeRate: price, + TimestampMs: timestampMs, }); err != nil { ctx.Logger().Error("failed to emit OraclePriceUpdate", "pair", pair, "error", err) } diff --git a/x/oracle/keeper/msg_server.go b/x/oracle/keeper/msg_server.go index 1fa2fbbd6..1299d93d6 100644 --- a/x/oracle/keeper/msg_server.go +++ b/x/oracle/keeper/msg_server.go @@ -163,17 +163,10 @@ func (ms msgServer) DelegateFeedConsent(goCtx context.Context, msg *types.MsgDel // Set the delegation ms.Keeper.FeederDelegations.Insert(ctx, operatorAddr, delegateAddr) - ctx.EventManager().EmitEvents(sdk.Events{ - sdk.NewEvent( - types.EventTypeFeedDelegate, - sdk.NewAttribute(types.AttributeKeyFeeder, msg.Delegate), - ), - sdk.NewEvent( - sdk.EventTypeMessage, - sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory), - sdk.NewAttribute(sdk.AttributeKeySender, msg.Operator), - ), + err = ctx.EventManager().EmitTypedEvent(&types.EventDelegateFeederConsent{ + Feeder: msg.Delegate, + Operator: msg.Operator, }) - return &types.MsgDelegateFeedConsentResponse{}, nil + return &types.MsgDelegateFeedConsentResponse{}, err } diff --git a/x/oracle/keeper/querier_test.go b/x/oracle/keeper/querier_test.go index d01a9c328..04444f853 100644 --- a/x/oracle/keeper/querier_test.go +++ b/x/oracle/keeper/querier_test.go @@ -97,10 +97,10 @@ func TestQueryExchangeRateTwap(t *testing.T) { testutilevents.RequireContainsTypedEvent( t, input.Ctx, - &types.OraclePriceUpdate{ - Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD).String(), - Price: rate, - TimestampMs: input.Ctx.BlockTime().UnixMilli()}, + &types.EventExchangeRateUpdate{ + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD).String(), + ExchangeRate: rate, + TimestampMs: input.Ctx.BlockTime().UnixMilli()}, ) ctx := sdk.WrapSDKContext(input.Ctx. diff --git a/x/oracle/keeper/update_exchange_rates.go b/x/oracle/keeper/update_exchange_rates.go index a20268f98..e10791789 100644 --- a/x/oracle/keeper/update_exchange_rates.go +++ b/x/oracle/keeper/update_exchange_rates.go @@ -64,12 +64,11 @@ func (k Keeper) countVotesAndUpdateExchangeRates( k.SetPrice(ctx, pair, exchangeRate) - ctx.EventManager().EmitEvent( - sdk.NewEvent(types.EventTypeExchangeRateUpdate, - sdk.NewAttribute(types.AttributeKeyPair, pair.String()), - sdk.NewAttribute(types.AttributeKeyExchangeRate, exchangeRate.String()), - ), - ) + _ = ctx.EventManager().EmitTypedEvent(&types.EventExchangeRateUpdate{ + Pair: pairStr, + ExchangeRate: exchangeRate, + TimestampMs: ctx.BlockTime().UnixMilli(), + }) } } diff --git a/x/oracle/types/event.pb.go b/x/oracle/types/event.pb.go index 5cd764db0..e450776c2 100644 --- a/x/oracle/types/event.pb.go +++ b/x/oracle/types/event.pb.go @@ -26,24 +26,24 @@ var _ = math.Inf const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // Emitted when a price is posted -type OraclePriceUpdate struct { - Pair string `protobuf:"bytes,1,opt,name=pair,proto3" json:"pair,omitempty"` - Price github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,2,opt,name=price,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"price"` - TimestampMs int64 `protobuf:"varint,3,opt,name=timestamp_ms,json=timestampMs,proto3" json:"timestamp_ms,omitempty"` +type EventExchangeRateUpdate struct { + Pair string `protobuf:"bytes,1,opt,name=pair,proto3" json:"pair,omitempty"` + ExchangeRate github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,2,opt,name=exchange_rate,json=exchangeRate,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"exchange_rate"` + TimestampMs int64 `protobuf:"varint,3,opt,name=timestamp_ms,json=timestampMs,proto3" json:"timestamp_ms,omitempty"` } -func (m *OraclePriceUpdate) Reset() { *m = OraclePriceUpdate{} } -func (m *OraclePriceUpdate) String() string { return proto.CompactTextString(m) } -func (*OraclePriceUpdate) ProtoMessage() {} -func (*OraclePriceUpdate) Descriptor() ([]byte, []int) { +func (m *EventExchangeRateUpdate) Reset() { *m = EventExchangeRateUpdate{} } +func (m *EventExchangeRateUpdate) String() string { return proto.CompactTextString(m) } +func (*EventExchangeRateUpdate) ProtoMessage() {} +func (*EventExchangeRateUpdate) Descriptor() ([]byte, []int) { return fileDescriptor_94ec441b793fc0ea, []int{0} } -func (m *OraclePriceUpdate) XXX_Unmarshal(b []byte) error { +func (m *EventExchangeRateUpdate) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *OraclePriceUpdate) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *EventExchangeRateUpdate) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_OraclePriceUpdate.Marshal(b, m, deterministic) + return xxx_messageInfo_EventExchangeRateUpdate.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -53,61 +53,122 @@ func (m *OraclePriceUpdate) XXX_Marshal(b []byte, deterministic bool) ([]byte, e return b[:n], nil } } -func (m *OraclePriceUpdate) XXX_Merge(src proto.Message) { - xxx_messageInfo_OraclePriceUpdate.Merge(m, src) +func (m *EventExchangeRateUpdate) XXX_Merge(src proto.Message) { + xxx_messageInfo_EventExchangeRateUpdate.Merge(m, src) } -func (m *OraclePriceUpdate) XXX_Size() int { +func (m *EventExchangeRateUpdate) XXX_Size() int { return m.Size() } -func (m *OraclePriceUpdate) XXX_DiscardUnknown() { - xxx_messageInfo_OraclePriceUpdate.DiscardUnknown(m) +func (m *EventExchangeRateUpdate) XXX_DiscardUnknown() { + xxx_messageInfo_EventExchangeRateUpdate.DiscardUnknown(m) } -var xxx_messageInfo_OraclePriceUpdate proto.InternalMessageInfo +var xxx_messageInfo_EventExchangeRateUpdate proto.InternalMessageInfo -func (m *OraclePriceUpdate) GetPair() string { +func (m *EventExchangeRateUpdate) GetPair() string { if m != nil { return m.Pair } return "" } -func (m *OraclePriceUpdate) GetTimestampMs() int64 { +func (m *EventExchangeRateUpdate) GetTimestampMs() int64 { if m != nil { return m.TimestampMs } return 0 } +// Emitted when a valoper delegates oracle voting rights to a feeder address. +type EventDelegateFeederConsent struct { + // Feeder is the delegate or representative that will be able to send + // vote and prevote transaction messages. + Feeder string `protobuf:"bytes,1,opt,name=feeder,proto3" json:"feeder,omitempty"` + // Operator is the delegator, a valdiator operator that is delegating + // voting rights. + Operator string `protobuf:"bytes,2,opt,name=operator,proto3" json:"operator,omitempty"` +} + +func (m *EventDelegateFeederConsent) Reset() { *m = EventDelegateFeederConsent{} } +func (m *EventDelegateFeederConsent) String() string { return proto.CompactTextString(m) } +func (*EventDelegateFeederConsent) ProtoMessage() {} +func (*EventDelegateFeederConsent) Descriptor() ([]byte, []int) { + return fileDescriptor_94ec441b793fc0ea, []int{1} +} +func (m *EventDelegateFeederConsent) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *EventDelegateFeederConsent) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_EventDelegateFeederConsent.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 *EventDelegateFeederConsent) XXX_Merge(src proto.Message) { + xxx_messageInfo_EventDelegateFeederConsent.Merge(m, src) +} +func (m *EventDelegateFeederConsent) XXX_Size() int { + return m.Size() +} +func (m *EventDelegateFeederConsent) XXX_DiscardUnknown() { + xxx_messageInfo_EventDelegateFeederConsent.DiscardUnknown(m) +} + +var xxx_messageInfo_EventDelegateFeederConsent proto.InternalMessageInfo + +func (m *EventDelegateFeederConsent) GetFeeder() string { + if m != nil { + return m.Feeder + } + return "" +} + +func (m *EventDelegateFeederConsent) GetOperator() string { + if m != nil { + return m.Operator + } + return "" +} + func init() { - proto.RegisterType((*OraclePriceUpdate)(nil), "nibiru.oracle.v1.OraclePriceUpdate") + proto.RegisterType((*EventExchangeRateUpdate)(nil), "nibiru.oracle.v1.EventExchangeRateUpdate") + proto.RegisterType((*EventDelegateFeederConsent)(nil), "nibiru.oracle.v1.EventDelegateFeederConsent") } func init() { proto.RegisterFile("nibiru/oracle/v1/event.proto", fileDescriptor_94ec441b793fc0ea) } var fileDescriptor_94ec441b793fc0ea = []byte{ - // 276 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x4c, 0x90, 0xcd, 0x4a, 0x03, 0x31, - 0x14, 0x85, 0x27, 0x56, 0x05, 0x47, 0x17, 0x3a, 0xb8, 0x18, 0x4a, 0x49, 0xab, 0x0b, 0xe9, 0x42, - 0x13, 0x8a, 0x6f, 0x50, 0x8b, 0x3b, 0x7f, 0x18, 0x70, 0xe3, 0x46, 0x32, 0xd3, 0x30, 0x0d, 0x36, - 0xb9, 0x21, 0x49, 0x07, 0x7d, 0x8b, 0x3e, 0x56, 0x97, 0x5d, 0x8a, 0x8b, 0x22, 0x33, 0x2f, 0x22, - 0x93, 0x54, 0xe9, 0x2a, 0x97, 0xfb, 0x9d, 0xdc, 0xc3, 0x39, 0x71, 0x4f, 0x89, 0x5c, 0x98, 0x05, - 0x05, 0xc3, 0x8a, 0x39, 0xa7, 0xd5, 0x88, 0xf2, 0x8a, 0x2b, 0x47, 0xb4, 0x01, 0x07, 0xc9, 0x69, - 0xa0, 0x24, 0x50, 0x52, 0x8d, 0xba, 0xe7, 0x25, 0x94, 0xe0, 0x21, 0x6d, 0xa7, 0xa0, 0xeb, 0xf6, - 0x4a, 0x80, 0x72, 0xce, 0x29, 0xd3, 0x82, 0x32, 0xa5, 0xc0, 0x31, 0x27, 0x40, 0xd9, 0x40, 0x2f, - 0x97, 0x28, 0x3e, 0x7b, 0xf2, 0x17, 0x9e, 0x8d, 0x28, 0xf8, 0x8b, 0x9e, 0x32, 0xc7, 0x93, 0x24, - 0xde, 0xd7, 0x4c, 0x98, 0x14, 0x0d, 0xd0, 0xf0, 0x28, 0xf3, 0x73, 0x32, 0x89, 0x0f, 0x74, 0x2b, - 0x49, 0xf7, 0xda, 0xe5, 0x98, 0xac, 0x36, 0xfd, 0xe8, 0x7b, 0xd3, 0xbf, 0x2a, 0x85, 0x9b, 0x2d, - 0x72, 0x52, 0x80, 0xa4, 0x05, 0x58, 0x09, 0x76, 0xfb, 0xdc, 0xd8, 0xe9, 0x3b, 0x75, 0x9f, 0x9a, - 0x5b, 0x32, 0xe1, 0x45, 0x16, 0x3e, 0x27, 0x17, 0xf1, 0x89, 0x13, 0x92, 0x5b, 0xc7, 0xa4, 0x7e, - 0x93, 0x36, 0xed, 0x0c, 0xd0, 0xb0, 0x93, 0x1d, 0xff, 0xef, 0x1e, 0xec, 0xf8, 0x7e, 0x55, 0x63, - 0xb4, 0xae, 0x31, 0xfa, 0xa9, 0x31, 0x5a, 0x36, 0x38, 0x5a, 0x37, 0x38, 0xfa, 0x6a, 0x70, 0xf4, - 0x7a, 0xbd, 0xe3, 0xf5, 0xe8, 0xd3, 0xdf, 0xcd, 0x98, 0x50, 0x74, 0xdb, 0xd3, 0xc7, 0x5f, 0x53, - 0xde, 0x35, 0x3f, 0xf4, 0x09, 0x6f, 0x7f, 0x03, 0x00, 0x00, 0xff, 0xff, 0xfe, 0x02, 0x4f, 0x68, - 0x47, 0x01, 0x00, 0x00, + // 332 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x4c, 0x91, 0xcf, 0x4e, 0xfa, 0x40, + 0x10, 0xc7, 0xdb, 0x1f, 0xbf, 0x10, 0x5d, 0x31, 0x31, 0x8d, 0x51, 0xd2, 0x90, 0x82, 0x1c, 0x0c, + 0x07, 0xed, 0x86, 0xf8, 0x06, 0xfc, 0xbb, 0x69, 0x4c, 0x8d, 0x17, 0x2f, 0x64, 0x29, 0x63, 0xd9, + 0x48, 0x77, 0x9a, 0xdd, 0x81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, 0x6f, 0x65, 0xf6, + 0x60, 0x0a, 0x89, 0x20, 0x18, 0x00, 0x8c, 0x41, 0x77, 0x51, 0x19, 0x50, 0xe4, 0x5d, 0xb0, 0xf2, + 0xab, 0x2d, 0x14, 0x5a, 0x8b, 0xcc, 0xf3, 0xd9, 0x11, 0x66, 0xa0, 0x05, 0xa1, 0xce, 0x85, 0x46, + 0xfb, 0xbc, 0x33, 0x58, 0x6e, 0x02, 0x77, 0xb5, 0x09, 0xdc, 0x9f, 0x4d, 0xe0, 0x7e, 0x6c, 0x03, + 0x67, 0xb5, 0x0d, 0x9c, 0xaf, 0x6d, 0xe0, 0xbc, 0xdc, 0x1c, 0x2c, 0xf1, 0x60, 0x8f, 0xdc, 0x9d, + 0x08, 0xa9, 0x78, 0x61, 0xc7, 0xe2, 0xcf, 0x10, 0xbb, 0xce, 0xa8, 0x6c, 0x0f, 0x79, 0xf7, 0x1b, + 0x00, 0x00, 0xff, 0xff, 0x9a, 0x6c, 0xc7, 0x14, 0xae, 0x01, 0x00, 0x00, } -func (m *OraclePriceUpdate) Marshal() (dAtA []byte, err error) { +func (m *EventExchangeRateUpdate) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -117,12 +178,12 @@ func (m *OraclePriceUpdate) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *OraclePriceUpdate) MarshalTo(dAtA []byte) (int, error) { +func (m *EventExchangeRateUpdate) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *OraclePriceUpdate) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *EventExchangeRateUpdate) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int @@ -133,9 +194,9 @@ func (m *OraclePriceUpdate) MarshalToSizedBuffer(dAtA []byte) (int, error) { dAtA[i] = 0x18 } { - size := m.Price.Size() + size := m.ExchangeRate.Size() i -= size - if _, err := m.Price.MarshalTo(dAtA[i:]); err != nil { + if _, err := m.ExchangeRate.MarshalTo(dAtA[i:]); err != nil { return 0, err } i = encodeVarintEvent(dAtA, i, uint64(size)) @@ -152,6 +213,43 @@ func (m *OraclePriceUpdate) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +func (m *EventDelegateFeederConsent) 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 *EventDelegateFeederConsent) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *EventDelegateFeederConsent) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Operator) > 0 { + i -= len(m.Operator) + copy(dAtA[i:], m.Operator) + i = encodeVarintEvent(dAtA, i, uint64(len(m.Operator))) + i-- + dAtA[i] = 0x12 + } + if len(m.Feeder) > 0 { + i -= len(m.Feeder) + copy(dAtA[i:], m.Feeder) + i = encodeVarintEvent(dAtA, i, uint64(len(m.Feeder))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + func encodeVarintEvent(dAtA []byte, offset int, v uint64) int { offset -= sovEvent(v) base := offset @@ -163,7 +261,7 @@ func encodeVarintEvent(dAtA []byte, offset int, v uint64) int { dAtA[offset] = uint8(v) return base } -func (m *OraclePriceUpdate) Size() (n int) { +func (m *EventExchangeRateUpdate) Size() (n int) { if m == nil { return 0 } @@ -173,7 +271,7 @@ func (m *OraclePriceUpdate) Size() (n int) { if l > 0 { n += 1 + l + sovEvent(uint64(l)) } - l = m.Price.Size() + l = m.ExchangeRate.Size() n += 1 + l + sovEvent(uint64(l)) if m.TimestampMs != 0 { n += 1 + sovEvent(uint64(m.TimestampMs)) @@ -181,13 +279,30 @@ func (m *OraclePriceUpdate) Size() (n int) { return n } +func (m *EventDelegateFeederConsent) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Feeder) + if l > 0 { + n += 1 + l + sovEvent(uint64(l)) + } + l = len(m.Operator) + if l > 0 { + n += 1 + l + sovEvent(uint64(l)) + } + return n +} + func sovEvent(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } func sozEvent(x uint64) (n int) { return sovEvent(uint64((x << 1) ^ uint64((int64(x) >> 63)))) } -func (m *OraclePriceUpdate) Unmarshal(dAtA []byte) error { +func (m *EventExchangeRateUpdate) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -210,10 +325,10 @@ func (m *OraclePriceUpdate) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: OraclePriceUpdate: wiretype end group for non-group") + return fmt.Errorf("proto: EventExchangeRateUpdate: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: OraclePriceUpdate: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: EventExchangeRateUpdate: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: @@ -250,7 +365,7 @@ func (m *OraclePriceUpdate) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 2: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Price", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field ExchangeRate", wireType) } var stringLen uint64 for shift := uint(0); ; shift += 7 { @@ -278,7 +393,7 @@ func (m *OraclePriceUpdate) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if err := m.Price.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + if err := m.ExchangeRate.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex @@ -322,6 +437,120 @@ func (m *OraclePriceUpdate) Unmarshal(dAtA []byte) error { } return nil } +func (m *EventDelegateFeederConsent) 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 ErrIntOverflowEvent + } + 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: EventDelegateFeederConsent: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: EventDelegateFeederConsent: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Feeder", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEvent + } + 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 ErrInvalidLengthEvent + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthEvent + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Feeder = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Operator", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEvent + } + 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 ErrInvalidLengthEvent + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthEvent + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Operator = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipEvent(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthEvent + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func skipEvent(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 diff --git a/x/oracle/types/events.go b/x/oracle/types/events.go index 91be4c9ab..e49368281 100644 --- a/x/oracle/types/events.go +++ b/x/oracle/types/events.go @@ -5,7 +5,6 @@ const ( EventTypeExchangeRateUpdate = "exchange_rate_update" EventTypePrevote = "prevote" EventTypeVote = "vote" - EventTypeFeedDelegate = "feed_delegate" EventTypeAggregatePrevote = "aggregate_prevote" EventTypeAggregateVote = "aggregate_vote" From acff36eb24750c1f14c837fed2faea81e6dd9fae Mon Sep 17 00:00:00 2001 From: Unique-Divine Date: Mon, 3 Jul 2023 04:16:39 -0500 Subject: [PATCH 2/7] finish the move to typed events --- CHANGELOG.md | 3 +- proto/nibiru/oracle/v1/event.proto | 31 +- x/oracle/keeper/msg_server.go | 37 +- x/oracle/types/event.pb.go | 575 +++++++++++++++++++++++++++-- 4 files changed, 580 insertions(+), 66 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cda633091..b63c4c314 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -56,6 +56,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### State Machine Breaking * [#1473](https://github.com/NibiruChain/nibiru/pull/1473) - refactor(perp)!: rename `OpenPosition` to `MarketOrder` +* [#xxx](https://github.com/NibiruChain/nibiru/pull/xxx) - refactor(oracle)!: Move away from deprecated events to typed events in x/oracle ### Dependencies @@ -607,4 +608,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Testing * [#695](https://github.com/NibiruChain/nibiru/pull/695) Add `OpenPosition` integration tests. -* [#692](https://github.com/NibiruChain/nibiru/pull/692) Add test coverage for Perp MsgServer methods. \ No newline at end of file +* [#692](https://github.com/NibiruChain/nibiru/pull/692) Add test coverage for Perp MsgServer methods. diff --git a/proto/nibiru/oracle/v1/event.proto b/proto/nibiru/oracle/v1/event.proto index d334957c3..c22fe5762 100644 --- a/proto/nibiru/oracle/v1/event.proto +++ b/proto/nibiru/oracle/v1/event.proto @@ -19,11 +19,34 @@ message EventExchangeRateUpdate { // Emitted when a valoper delegates oracle voting rights to a feeder address. message EventDelegateFeederConsent { + // Validator is the Bech32 address that is delegating voting rights. + string validator = 1; + // Feeder is the delegate or representative that will be able to send // vote and prevote transaction messages. - string feeder = 1; + string feeder = 2; +} + +// Emitted by MsgAggregateExchangeVote when an aggregate vote is added to state +message EventAggregateVote { + // Validator is the Bech32 address to which the vote will be credited. + string validator = 1; + + // Feeder is the delegate or representative that will sends vote and prevote + // transaction messages on behalf of the voting validator. + string feeder = 2; + + string exchange_rates = 3 + [ (gogoproto.moretags) = "yaml:\"exchange_rates\"" ]; +} + +// Emitted by MsgAggregateExchangePrevote when an aggregate prevote is added +// to state +message EventAggregatePrevote { + // Validator is the Bech32 address to which the vote will be credited. + string validator = 1; - // Operator is the delegator, a valdiator operator that is delegating - // voting rights. - string operator = 2; + // Feeder is the delegate or representative that will sends vote and prevote + // transaction messages on behalf of the voting validator. + string feeder = 2; } diff --git a/x/oracle/keeper/msg_server.go b/x/oracle/keeper/msg_server.go index 1299d93d6..67f027505 100644 --- a/x/oracle/keeper/msg_server.go +++ b/x/oracle/keeper/msg_server.go @@ -50,19 +50,11 @@ func (ms msgServer) AggregateExchangeRatePrevote( ms.Keeper.Prevotes.Insert(ctx, valAddr, types.NewAggregateExchangeRatePrevote(voteHash, valAddr, uint64(ctx.BlockHeight()))) - ctx.EventManager().EmitEvents(sdk.Events{ - sdk.NewEvent( - types.EventTypeAggregatePrevote, - sdk.NewAttribute(types.AttributeKeyVoter, msg.Validator), - ), - sdk.NewEvent( - sdk.EventTypeMessage, - sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory), - sdk.NewAttribute(sdk.AttributeKeySender, msg.Feeder), - ), + err = ctx.EventManager().EmitTypedEvent(&types.EventAggregatePrevote{ + Validator: msg.Validator, + Feeder: msg.Feeder, }) - - return &types.MsgAggregateExchangeRatePrevoteResponse{}, nil + return &types.MsgAggregateExchangeRatePrevoteResponse{}, err } func (ms msgServer) AggregateExchangeRateVote(goCtx context.Context, msg *types.MsgAggregateExchangeRateVote) (*types.MsgAggregateExchangeRateVoteResponse, error) { @@ -125,20 +117,13 @@ func (ms msgServer) AggregateExchangeRateVote(goCtx context.Context, msg *types. ms.Keeper.Votes.Insert(ctx, valAddr, types.NewAggregateExchangeRateVote(exchangeRateTuples, valAddr)) _ = ms.Keeper.Prevotes.Delete(ctx, valAddr) - ctx.EventManager().EmitEvents(sdk.Events{ - sdk.NewEvent( - types.EventTypeAggregateVote, - sdk.NewAttribute(types.AttributeKeyVoter, msg.Validator), - sdk.NewAttribute(types.AttributeKeyExchangeRates, msg.ExchangeRates), - ), - sdk.NewEvent( - sdk.EventTypeMessage, - sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory), - sdk.NewAttribute(sdk.AttributeKeySender, msg.Feeder), - ), + err = ctx.EventManager().EmitTypedEvent(&types.EventAggregateVote{ + Validator: msg.Validator, + Feeder: msg.Feeder, + ExchangeRates: msg.ExchangeRates, }) - return &types.MsgAggregateExchangeRateVoteResponse{}, nil + return &types.MsgAggregateExchangeRateVoteResponse{}, err } func (ms msgServer) DelegateFeedConsent(goCtx context.Context, msg *types.MsgDelegateFeedConsent) (*types.MsgDelegateFeedConsentResponse, error) { @@ -164,8 +149,8 @@ func (ms msgServer) DelegateFeedConsent(goCtx context.Context, msg *types.MsgDel ms.Keeper.FeederDelegations.Insert(ctx, operatorAddr, delegateAddr) err = ctx.EventManager().EmitTypedEvent(&types.EventDelegateFeederConsent{ - Feeder: msg.Delegate, - Operator: msg.Operator, + Feeder: msg.Delegate, + Validator: msg.Operator, }) return &types.MsgDelegateFeedConsentResponse{}, err diff --git a/x/oracle/types/event.pb.go b/x/oracle/types/event.pb.go index e450776c2..9f0cc70a1 100644 --- a/x/oracle/types/event.pb.go +++ b/x/oracle/types/event.pb.go @@ -81,12 +81,11 @@ func (m *EventExchangeRateUpdate) GetTimestampMs() int64 { // Emitted when a valoper delegates oracle voting rights to a feeder address. type EventDelegateFeederConsent struct { + // Validator is the Bech32 address that is delegating voting rights. + Validator string `protobuf:"bytes,1,opt,name=validator,proto3" json:"validator,omitempty"` // Feeder is the delegate or representative that will be able to send // vote and prevote transaction messages. - Feeder string `protobuf:"bytes,1,opt,name=feeder,proto3" json:"feeder,omitempty"` - // Operator is the delegator, a valdiator operator that is delegating - // voting rights. - Operator string `protobuf:"bytes,2,opt,name=operator,proto3" json:"operator,omitempty"` + Feeder string `protobuf:"bytes,2,opt,name=feeder,proto3" json:"feeder,omitempty"` } func (m *EventDelegateFeederConsent) Reset() { *m = EventDelegateFeederConsent{} } @@ -122,6 +121,13 @@ func (m *EventDelegateFeederConsent) XXX_DiscardUnknown() { var xxx_messageInfo_EventDelegateFeederConsent proto.InternalMessageInfo +func (m *EventDelegateFeederConsent) GetValidator() string { + if m != nil { + return m.Validator + } + return "" +} + func (m *EventDelegateFeederConsent) GetFeeder() string { if m != nil { return m.Feeder @@ -129,9 +135,123 @@ func (m *EventDelegateFeederConsent) GetFeeder() string { return "" } -func (m *EventDelegateFeederConsent) GetOperator() string { +// Emitted by MsgAggregateExchangeVote when an aggregate vote is added to state +type EventAggregateVote struct { + // Validator is the Bech32 address to which the vote will be credited. + Validator string `protobuf:"bytes,1,opt,name=validator,proto3" json:"validator,omitempty"` + // Feeder is the delegate or representative that will sends vote and prevote + // transaction messages on behalf of the voting validator. + Feeder string `protobuf:"bytes,2,opt,name=feeder,proto3" json:"feeder,omitempty"` + ExchangeRates string `protobuf:"bytes,3,opt,name=exchange_rates,json=exchangeRates,proto3" json:"exchange_rates,omitempty" yaml:"exchange_rates"` +} + +func (m *EventAggregateVote) Reset() { *m = EventAggregateVote{} } +func (m *EventAggregateVote) String() string { return proto.CompactTextString(m) } +func (*EventAggregateVote) ProtoMessage() {} +func (*EventAggregateVote) Descriptor() ([]byte, []int) { + return fileDescriptor_94ec441b793fc0ea, []int{2} +} +func (m *EventAggregateVote) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *EventAggregateVote) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_EventAggregateVote.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 *EventAggregateVote) XXX_Merge(src proto.Message) { + xxx_messageInfo_EventAggregateVote.Merge(m, src) +} +func (m *EventAggregateVote) XXX_Size() int { + return m.Size() +} +func (m *EventAggregateVote) XXX_DiscardUnknown() { + xxx_messageInfo_EventAggregateVote.DiscardUnknown(m) +} + +var xxx_messageInfo_EventAggregateVote proto.InternalMessageInfo + +func (m *EventAggregateVote) GetValidator() string { + if m != nil { + return m.Validator + } + return "" +} + +func (m *EventAggregateVote) GetFeeder() string { + if m != nil { + return m.Feeder + } + return "" +} + +func (m *EventAggregateVote) GetExchangeRates() string { if m != nil { - return m.Operator + return m.ExchangeRates + } + return "" +} + +// Emitted by MsgAggregateExchangePrevote when an aggregate prevote is added +// to state +type EventAggregatePrevote struct { + // Validator is the Bech32 address to which the vote will be credited. + Validator string `protobuf:"bytes,1,opt,name=validator,proto3" json:"validator,omitempty"` + // Feeder is the delegate or representative that will sends vote and prevote + // transaction messages on behalf of the voting validator. + Feeder string `protobuf:"bytes,2,opt,name=feeder,proto3" json:"feeder,omitempty"` +} + +func (m *EventAggregatePrevote) Reset() { *m = EventAggregatePrevote{} } +func (m *EventAggregatePrevote) String() string { return proto.CompactTextString(m) } +func (*EventAggregatePrevote) ProtoMessage() {} +func (*EventAggregatePrevote) Descriptor() ([]byte, []int) { + return fileDescriptor_94ec441b793fc0ea, []int{3} +} +func (m *EventAggregatePrevote) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *EventAggregatePrevote) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_EventAggregatePrevote.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 *EventAggregatePrevote) XXX_Merge(src proto.Message) { + xxx_messageInfo_EventAggregatePrevote.Merge(m, src) +} +func (m *EventAggregatePrevote) XXX_Size() int { + return m.Size() +} +func (m *EventAggregatePrevote) XXX_DiscardUnknown() { + xxx_messageInfo_EventAggregatePrevote.DiscardUnknown(m) +} + +var xxx_messageInfo_EventAggregatePrevote proto.InternalMessageInfo + +func (m *EventAggregatePrevote) GetValidator() string { + if m != nil { + return m.Validator + } + return "" +} + +func (m *EventAggregatePrevote) GetFeeder() string { + if m != nil { + return m.Feeder } return "" } @@ -139,33 +259,39 @@ func (m *EventDelegateFeederConsent) GetOperator() string { func init() { proto.RegisterType((*EventExchangeRateUpdate)(nil), "nibiru.oracle.v1.EventExchangeRateUpdate") proto.RegisterType((*EventDelegateFeederConsent)(nil), "nibiru.oracle.v1.EventDelegateFeederConsent") + proto.RegisterType((*EventAggregateVote)(nil), "nibiru.oracle.v1.EventAggregateVote") + proto.RegisterType((*EventAggregatePrevote)(nil), "nibiru.oracle.v1.EventAggregatePrevote") } func init() { proto.RegisterFile("nibiru/oracle/v1/event.proto", fileDescriptor_94ec441b793fc0ea) } var fileDescriptor_94ec441b793fc0ea = []byte{ - // 332 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x4c, 0x91, 0xcf, 0x4e, 0xfa, 0x40, - 0x10, 0xc7, 0xdb, 0x1f, 0xbf, 0x10, 0x5d, 0x31, 0x31, 0x8d, 0x51, 0xd2, 0x90, 0x82, 0x1c, 0x0c, - 0x07, 0xed, 0x86, 0xf8, 0x06, 0xfc, 0xbb, 0x69, 0x4c, 0x8d, 0x17, 0x2f, 0x64, 0x29, 0x63, 0xd9, - 0x48, 0x77, 0x9a, 0xdd, 0x81, 0xe0, 0x5b, 0xf8, 0x12, 0xbe, 0x0b, 0x47, 0x8e, 0xc6, 0x03, 0x31, - 0xf0, 0x22, 0x86, 0x6d, 0x25, 0x9c, 0x76, 0x66, 0x3e, 0x93, 0x9d, 0xef, 0xcc, 0x97, 0xd5, 0x94, - 0x1c, 0x49, 0x3d, 0xe3, 0xa8, 0x45, 0x3c, 0x05, 0x3e, 0x6f, 0x73, 0x98, 0x83, 0xa2, 0x30, 0xd3, - 0x48, 0xe8, 0x9d, 0xe5, 0x34, 0xcc, 0x69, 0x38, 0x6f, 0xfb, 0xe7, 0x09, 0x26, 0x68, 0x21, 0xdf, - 0x45, 0x79, 0x9f, 0x5f, 0x4b, 0x10, 0x93, 0x29, 0x70, 0x91, 0x49, 0x2e, 0x94, 0x42, 0x12, 0x24, - 0x51, 0x99, 0x9c, 0x36, 0x3f, 0x5d, 0x76, 0xd9, 0xdf, 0xfd, 0xda, 0x5f, 0xc4, 0x13, 0xa1, 0x12, - 0x88, 0x04, 0xc1, 0x73, 0x36, 0x16, 0x04, 0x9e, 0xc7, 0xfe, 0x67, 0x42, 0xea, 0xaa, 0xdb, 0x70, - 0x5b, 0xc7, 0x91, 0x8d, 0xbd, 0x27, 0x76, 0x0a, 0x45, 0xe7, 0x50, 0x0b, 0x82, 0xea, 0xbf, 0x1d, - 0xec, 0x84, 0xcb, 0x75, 0xdd, 0xf9, 0x5e, 0xd7, 0xaf, 0x13, 0x49, 0x93, 0xd9, 0x28, 0x8c, 0x31, - 0xe5, 0x31, 0x9a, 0x14, 0x4d, 0xf1, 0xdc, 0x9a, 0xf1, 0x1b, 0xa7, 0xf7, 0x0c, 0x4c, 0xd8, 0x83, - 0x38, 0xaa, 0xc0, 0xc1, 0x38, 0xef, 0x8a, 0x55, 0x48, 0xa6, 0x60, 0x48, 0xa4, 0xd9, 0x30, 0x35, - 0xd5, 0x52, 0xc3, 0x6d, 0x95, 0xa2, 0x93, 0x7d, 0xed, 0xde, 0x34, 0x1f, 0x99, 0x6f, 0x65, 0xf6, - 0x60, 0x0a, 0x89, 0x20, 0x18, 0x00, 0x8c, 0x41, 0x77, 0x51, 0x19, 0x50, 0xe4, 0x5d, 0xb0, 0xf2, - 0xab, 0x2d, 0x14, 0x5a, 0x8b, 0xcc, 0xf3, 0xd9, 0x11, 0x66, 0xa0, 0x05, 0xa1, 0xce, 0x85, 0x46, - 0xfb, 0xbc, 0x33, 0x58, 0x6e, 0x02, 0x77, 0xb5, 0x09, 0xdc, 0x9f, 0x4d, 0xe0, 0x7e, 0x6c, 0x03, - 0x67, 0xb5, 0x0d, 0x9c, 0xaf, 0x6d, 0xe0, 0xbc, 0xdc, 0x1c, 0x2c, 0xf1, 0x60, 0x8f, 0xdc, 0x9d, - 0x08, 0xa9, 0x78, 0x61, 0xc7, 0xe2, 0xcf, 0x10, 0xbb, 0xce, 0xa8, 0x6c, 0x0f, 0x79, 0xf7, 0x1b, - 0x00, 0x00, 0xff, 0xff, 0x9a, 0x6c, 0xc7, 0x14, 0xae, 0x01, 0x00, 0x00, + // 396 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x52, 0xcd, 0xae, 0x12, 0x31, + 0x14, 0x9e, 0x7a, 0xcd, 0x4d, 0xa8, 0xf7, 0x1a, 0xd3, 0x88, 0x22, 0x21, 0x03, 0xce, 0xc2, 0xb0, + 0xd0, 0x69, 0x88, 0x3b, 0x57, 0xca, 0xdf, 0x0e, 0x63, 0xc6, 0xe8, 0xc2, 0x0d, 0x29, 0x33, 0xc7, + 0xd2, 0x38, 0x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, 0x69, 0x5c, 0x75, 0x50, 0xf7, 0x2a, 0x7a, 0xf0, + 0xbf, 0x37, 0x31, 0x41, 0x84, 0x9b, 0xce, 0xe6, 0x10, 0x52, 0xe0, 0xcc, 0xc2, 0x18, 0x20, 0x01, + 0x3d, 0x50, 0xd2, 0x80, 0xb4, 0xa4, 0x85, 0x6b, 0x05, 0x4b, 0x45, 0xc2, 0xac, 0x3a, 0xda, 0xbd, + 0x6b, 0x90, 0x27, 0xf8, 0xfa, 0xab, 0xa3, 0x97, 0x66, 0xa3, 0xea, 0x16, 0x7c, 0x47, 0x98, 0x38, + 0xd1, 0x77, 0x9c, 0x6b, 0xa7, 0xfa, 0x59, 0x59, 0xb8, 0x4c, 0x8c, 0xbc, 0xc5, 0x0f, 0xcf, 0x06, + 0x53, 0xfe, 0xa2, 0xd6, 0x7f, 0xf6, 0x77, 0xdb, 0xae, 0xaf, 0x58, 0x96, 0xbe, 0x09, 0xce, 0xf1, + 0x20, 0xba, 0x3d, 0x1d, 0x82, 0x09, 0x26, 0xb8, 0x7e, 0xee, 0xe6, 0x83, 0x86, 0xe2, 0x62, 0x43, + 0xfd, 0xf1, 0x7a, 0xe7, 0xa3, 0xcd, 0xce, 0x47, 0x7f, 0x76, 0x3e, 0xfa, 0xb1, 0xf7, 0xbd, 0xcd, + 0xde, 0xf7, 0x7e, 0xed, 0x7d, 0xef, 0xcb, 0xcb, 0x93, 0x25, 0xbd, 0x77, 0x21, 0x1a, 0xcc, 0x99, + 0x90, 0xb4, 0x8a, 0xdb, 0xf2, 0x18, 0x38, 0xb7, 0xae, 0xd9, 0xb5, 0x0b, 0xca, 0xeb, 0x7f, 0x01, + 0x00, 0x00, 0xff, 0xff, 0xc8, 0x26, 0xa5, 0x2c, 0x8e, 0x02, 0x00, 0x00, } func (m *EventExchangeRateUpdate) Marshal() (dAtA []byte, err error) { @@ -233,18 +359,99 @@ func (m *EventDelegateFeederConsent) MarshalToSizedBuffer(dAtA []byte) (int, err _ = i var l int _ = l - if len(m.Operator) > 0 { - i -= len(m.Operator) - copy(dAtA[i:], m.Operator) - i = encodeVarintEvent(dAtA, i, uint64(len(m.Operator))) + if len(m.Feeder) > 0 { + i -= len(m.Feeder) + copy(dAtA[i:], m.Feeder) + i = encodeVarintEvent(dAtA, i, uint64(len(m.Feeder))) + i-- + dAtA[i] = 0x12 + } + if len(m.Validator) > 0 { + i -= len(m.Validator) + copy(dAtA[i:], m.Validator) + i = encodeVarintEvent(dAtA, i, uint64(len(m.Validator))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *EventAggregateVote) 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 *EventAggregateVote) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *EventAggregateVote) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.ExchangeRates) > 0 { + i -= len(m.ExchangeRates) + copy(dAtA[i:], m.ExchangeRates) + i = encodeVarintEvent(dAtA, i, uint64(len(m.ExchangeRates))) + i-- + dAtA[i] = 0x1a + } + if len(m.Feeder) > 0 { + i -= len(m.Feeder) + copy(dAtA[i:], m.Feeder) + i = encodeVarintEvent(dAtA, i, uint64(len(m.Feeder))) i-- dAtA[i] = 0x12 } + if len(m.Validator) > 0 { + i -= len(m.Validator) + copy(dAtA[i:], m.Validator) + i = encodeVarintEvent(dAtA, i, uint64(len(m.Validator))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *EventAggregatePrevote) 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 *EventAggregatePrevote) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *EventAggregatePrevote) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l if len(m.Feeder) > 0 { i -= len(m.Feeder) copy(dAtA[i:], m.Feeder) i = encodeVarintEvent(dAtA, i, uint64(len(m.Feeder))) i-- + dAtA[i] = 0x12 + } + if len(m.Validator) > 0 { + i -= len(m.Validator) + copy(dAtA[i:], m.Validator) + i = encodeVarintEvent(dAtA, i, uint64(len(m.Validator))) + i-- dAtA[i] = 0xa } return len(dAtA) - i, nil @@ -285,11 +492,49 @@ func (m *EventDelegateFeederConsent) Size() (n int) { } var l int _ = l + l = len(m.Validator) + if l > 0 { + n += 1 + l + sovEvent(uint64(l)) + } + l = len(m.Feeder) + if l > 0 { + n += 1 + l + sovEvent(uint64(l)) + } + return n +} + +func (m *EventAggregateVote) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Validator) + if l > 0 { + n += 1 + l + sovEvent(uint64(l)) + } l = len(m.Feeder) if l > 0 { n += 1 + l + sovEvent(uint64(l)) } - l = len(m.Operator) + l = len(m.ExchangeRates) + if l > 0 { + n += 1 + l + sovEvent(uint64(l)) + } + return n +} + +func (m *EventAggregatePrevote) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Validator) + if l > 0 { + n += 1 + l + sovEvent(uint64(l)) + } + l = len(m.Feeder) if l > 0 { n += 1 + l + sovEvent(uint64(l)) } @@ -467,6 +712,152 @@ func (m *EventDelegateFeederConsent) Unmarshal(dAtA []byte) error { } switch fieldNum { case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Validator", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEvent + } + 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 ErrInvalidLengthEvent + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthEvent + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Validator = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Feeder", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEvent + } + 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 ErrInvalidLengthEvent + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthEvent + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Feeder = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipEvent(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthEvent + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *EventAggregateVote) 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 ErrIntOverflowEvent + } + 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: EventAggregateVote: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: EventAggregateVote: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Validator", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEvent + } + 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 ErrInvalidLengthEvent + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthEvent + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Validator = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field Feeder", wireType) } @@ -498,9 +889,123 @@ func (m *EventDelegateFeederConsent) Unmarshal(dAtA []byte) error { } m.Feeder = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ExchangeRates", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEvent + } + 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 ErrInvalidLengthEvent + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthEvent + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ExchangeRates = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipEvent(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthEvent + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *EventAggregatePrevote) 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 ErrIntOverflowEvent + } + 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: EventAggregatePrevote: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: EventAggregatePrevote: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Validator", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEvent + } + 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 ErrInvalidLengthEvent + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthEvent + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Validator = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex case 2: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Operator", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Feeder", wireType) } var stringLen uint64 for shift := uint(0); ; shift += 7 { @@ -528,7 +1033,7 @@ func (m *EventDelegateFeederConsent) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Operator = string(dAtA[iNdEx:postIndex]) + m.Feeder = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex default: iNdEx = preIndex From 784c2f3daa6be2064eab80d88ac3fd5a3b531185 Mon Sep 17 00:00:00 2001 From: Unique-Divine Date: Mon, 3 Jul 2023 04:18:35 -0500 Subject: [PATCH 3/7] changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b63c4c314..ff14eeebc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -56,7 +56,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### State Machine Breaking * [#1473](https://github.com/NibiruChain/nibiru/pull/1473) - refactor(perp)!: rename `OpenPosition` to `MarketOrder` -* [#xxx](https://github.com/NibiruChain/nibiru/pull/xxx) - refactor(oracle)!: Move away from deprecated events to typed events in x/oracle +* [#1477](https://github.com/NibiruChain/nibiru/pull/1477) - refactor(oracle)!: Move away from deprecated events to typed events in x/oracle ### Dependencies From 6997f466172ddeb535b60f9b18103fb75d0ebce1 Mon Sep 17 00:00:00 2001 From: Unique-Divine Date: Mon, 3 Jul 2023 04:21:46 -0500 Subject: [PATCH 4/7] refactor(oracle): rm unused constants file --- x/oracle/types/events.go | 19 ------------------- 1 file changed, 19 deletions(-) delete mode 100644 x/oracle/types/events.go diff --git a/x/oracle/types/events.go b/x/oracle/types/events.go deleted file mode 100644 index e49368281..000000000 --- a/x/oracle/types/events.go +++ /dev/null @@ -1,19 +0,0 @@ -package types - -// Oracle module event types -const ( - EventTypeExchangeRateUpdate = "exchange_rate_update" - EventTypePrevote = "prevote" - EventTypeVote = "vote" - EventTypeAggregatePrevote = "aggregate_prevote" - EventTypeAggregateVote = "aggregate_vote" - - AttributeKeyPair = "pair" - AttributeKeyVoter = "voter" - AttributeKeyExchangeRate = "exchange_rate" - AttributeKeyExchangeRates = "exchange_rates" - AttributeKeyOperator = "operator" - AttributeKeyFeeder = "feeder" - - AttributeValueCategory = ModuleName -) From 2fd0e070b2c987b62c52a525948641864326e455 Mon Sep 17 00:00:00 2001 From: Unique-Divine Date: Mon, 3 Jul 2023 10:58:34 -0500 Subject: [PATCH 5/7] refactor(oracle)!: use ExchangeRateTuples instead of strings in event --- proto/nibiru/oracle/v1/event.proto | 9 +- x/oracle/keeper/keeper.go | 6 +- x/oracle/keeper/msg_server.go | 26 +++-- x/oracle/keeper/querier_test.go | 6 +- x/oracle/keeper/update_exchange_rates.go | 6 +- x/oracle/types/event.pb.go | 122 +++++++++++++---------- x/oracle/types/vote.go | 2 +- x/oracle/types/vote_test.go | 2 +- 8 files changed, 103 insertions(+), 76 deletions(-) diff --git a/proto/nibiru/oracle/v1/event.proto b/proto/nibiru/oracle/v1/event.proto index c22fe5762..7a08ac7d3 100644 --- a/proto/nibiru/oracle/v1/event.proto +++ b/proto/nibiru/oracle/v1/event.proto @@ -2,6 +2,7 @@ syntax = "proto3"; package nibiru.oracle.v1; +import "nibiru/oracle/v1/oracle.proto"; import "gogoproto/gogo.proto"; import "google/api/annotations.proto"; @@ -10,7 +11,7 @@ option go_package = "github.com/NibiruChain/nibiru/x/oracle/types"; // Emitted when a price is posted message EventExchangeRateUpdate { string pair = 1; - string exchange_rate = 2 [ + string price = 2 [ (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false ]; @@ -36,8 +37,10 @@ message EventAggregateVote { // transaction messages on behalf of the voting validator. string feeder = 2; - string exchange_rates = 3 - [ (gogoproto.moretags) = "yaml:\"exchange_rates\"" ]; + repeated ExchangeRateTuple prices = 3 [ + (gogoproto.castrepeated) = "ExchangeRateTuples", + (gogoproto.nullable) = false + ]; } // Emitted by MsgAggregateExchangePrevote when an aggregate prevote is added diff --git a/x/oracle/keeper/keeper.go b/x/oracle/keeper/keeper.go index f218365ad..e4941dc4c 100644 --- a/x/oracle/keeper/keeper.go +++ b/x/oracle/keeper/keeper.go @@ -200,9 +200,9 @@ func (k Keeper) SetPrice(ctx sdk.Context, pair asset.Pair, price sdk.Dec) { TimestampMs: timestampMs, }) if err := ctx.EventManager().EmitTypedEvent(&types.EventExchangeRateUpdate{ - Pair: pair.String(), - ExchangeRate: price, - TimestampMs: timestampMs, + Pair: pair.String(), + Price: price, + TimestampMs: timestampMs, }); err != nil { ctx.Logger().Error("failed to emit OraclePriceUpdate", "pair", pair, "error", err) } diff --git a/x/oracle/keeper/msg_server.go b/x/oracle/keeper/msg_server.go index 67f027505..7bed77107 100644 --- a/x/oracle/keeper/msg_server.go +++ b/x/oracle/keeper/msg_server.go @@ -57,7 +57,9 @@ func (ms msgServer) AggregateExchangeRatePrevote( return &types.MsgAggregateExchangeRatePrevoteResponse{}, err } -func (ms msgServer) AggregateExchangeRateVote(goCtx context.Context, msg *types.MsgAggregateExchangeRateVote) (*types.MsgAggregateExchangeRateVoteResponse, error) { +func (ms msgServer) AggregateExchangeRateVote( + goCtx context.Context, msg *types.MsgAggregateExchangeRateVote, +) (msgResp *types.MsgAggregateExchangeRateVoteResponse, err error) { ctx := sdk.UnwrapSDKContext(goCtx) valAddr, err := sdk.ValAddressFromBech32(msg.Validator) @@ -110,23 +112,33 @@ func (ms msgServer) AggregateExchangeRateVote(goCtx context.Context, msg *types. // Verify an exchange rate with aggregate prevote hash hash := types.GetAggregateVoteHash(msg.Salt, msg.ExchangeRates, valAddr) if aggregatePrevote.Hash != hash.String() { - return nil, sdkerrors.Wrapf(types.ErrVerificationFailed, "must be given %s not %s", aggregatePrevote.Hash, hash) + return nil, sdkerrors.Wrapf( + types.ErrVerificationFailed, "must be given %s not %s", aggregatePrevote.Hash, hash, + ) } // Move aggregate prevote to aggregate vote with given exchange rates - ms.Keeper.Votes.Insert(ctx, valAddr, types.NewAggregateExchangeRateVote(exchangeRateTuples, valAddr)) + ms.Keeper.Votes.Insert( + ctx, valAddr, types.NewAggregateExchangeRateVote(exchangeRateTuples, valAddr), + ) _ = ms.Keeper.Prevotes.Delete(ctx, valAddr) + priceTuples, err := types.NewExchangeRateTuplesFromString(msg.ExchangeRates) + if err != nil { + return + } err = ctx.EventManager().EmitTypedEvent(&types.EventAggregateVote{ - Validator: msg.Validator, - Feeder: msg.Feeder, - ExchangeRates: msg.ExchangeRates, + Validator: msg.Validator, + Feeder: msg.Feeder, + Prices: priceTuples, }) return &types.MsgAggregateExchangeRateVoteResponse{}, err } -func (ms msgServer) DelegateFeedConsent(goCtx context.Context, msg *types.MsgDelegateFeedConsent) (*types.MsgDelegateFeedConsentResponse, error) { +func (ms msgServer) DelegateFeedConsent( + goCtx context.Context, msg *types.MsgDelegateFeedConsent, +) (*types.MsgDelegateFeedConsentResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) operatorAddr, err := sdk.ValAddressFromBech32(msg.Operator) diff --git a/x/oracle/keeper/querier_test.go b/x/oracle/keeper/querier_test.go index 04444f853..bd02565e8 100644 --- a/x/oracle/keeper/querier_test.go +++ b/x/oracle/keeper/querier_test.go @@ -98,9 +98,9 @@ func TestQueryExchangeRateTwap(t *testing.T) { t, input.Ctx, &types.EventExchangeRateUpdate{ - Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD).String(), - ExchangeRate: rate, - TimestampMs: input.Ctx.BlockTime().UnixMilli()}, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD).String(), + Price: rate, + TimestampMs: input.Ctx.BlockTime().UnixMilli()}, ) ctx := sdk.WrapSDKContext(input.Ctx. diff --git a/x/oracle/keeper/update_exchange_rates.go b/x/oracle/keeper/update_exchange_rates.go index e10791789..ce5381e0d 100644 --- a/x/oracle/keeper/update_exchange_rates.go +++ b/x/oracle/keeper/update_exchange_rates.go @@ -65,9 +65,9 @@ func (k Keeper) countVotesAndUpdateExchangeRates( k.SetPrice(ctx, pair, exchangeRate) _ = ctx.EventManager().EmitTypedEvent(&types.EventExchangeRateUpdate{ - Pair: pairStr, - ExchangeRate: exchangeRate, - TimestampMs: ctx.BlockTime().UnixMilli(), + Pair: pairStr, + Price: exchangeRate, + TimestampMs: ctx.BlockTime().UnixMilli(), }) } } diff --git a/x/oracle/types/event.pb.go b/x/oracle/types/event.pb.go index 9f0cc70a1..7735b2769 100644 --- a/x/oracle/types/event.pb.go +++ b/x/oracle/types/event.pb.go @@ -27,9 +27,9 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // Emitted when a price is posted type EventExchangeRateUpdate struct { - Pair string `protobuf:"bytes,1,opt,name=pair,proto3" json:"pair,omitempty"` - ExchangeRate github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,2,opt,name=exchange_rate,json=exchangeRate,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"exchange_rate"` - TimestampMs int64 `protobuf:"varint,3,opt,name=timestamp_ms,json=timestampMs,proto3" json:"timestamp_ms,omitempty"` + Pair string `protobuf:"bytes,1,opt,name=pair,proto3" json:"pair,omitempty"` + Price github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,2,opt,name=price,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"price"` + TimestampMs int64 `protobuf:"varint,3,opt,name=timestamp_ms,json=timestampMs,proto3" json:"timestamp_ms,omitempty"` } func (m *EventExchangeRateUpdate) Reset() { *m = EventExchangeRateUpdate{} } @@ -141,8 +141,8 @@ type EventAggregateVote struct { Validator string `protobuf:"bytes,1,opt,name=validator,proto3" json:"validator,omitempty"` // Feeder is the delegate or representative that will sends vote and prevote // transaction messages on behalf of the voting validator. - Feeder string `protobuf:"bytes,2,opt,name=feeder,proto3" json:"feeder,omitempty"` - ExchangeRates string `protobuf:"bytes,3,opt,name=exchange_rates,json=exchangeRates,proto3" json:"exchange_rates,omitempty" yaml:"exchange_rates"` + Feeder string `protobuf:"bytes,2,opt,name=feeder,proto3" json:"feeder,omitempty"` + Prices ExchangeRateTuples `protobuf:"bytes,3,rep,name=prices,proto3,castrepeated=ExchangeRateTuples" json:"prices"` } func (m *EventAggregateVote) Reset() { *m = EventAggregateVote{} } @@ -192,11 +192,11 @@ func (m *EventAggregateVote) GetFeeder() string { return "" } -func (m *EventAggregateVote) GetExchangeRates() string { +func (m *EventAggregateVote) GetPrices() ExchangeRateTuples { if m != nil { - return m.ExchangeRates + return m.Prices } - return "" + return nil } // Emitted by MsgAggregateExchangePrevote when an aggregate prevote is added @@ -266,32 +266,33 @@ func init() { func init() { proto.RegisterFile("nibiru/oracle/v1/event.proto", fileDescriptor_94ec441b793fc0ea) } var fileDescriptor_94ec441b793fc0ea = []byte{ - // 396 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x52, 0xcd, 0xae, 0x12, 0x31, - 0x14, 0x9e, 0x7a, 0xcd, 0x4d, 0xa8, 0xf7, 0x1a, 0xd3, 0x88, 0x22, 0x21, 0x03, 0xce, 0xc2, 0xb0, - 0xd0, 0x69, 0x88, 0x3b, 0x57, 0xca, 0xdf, 0x0e, 0x63, 0xc6, 0xe8, 0xc2, 0x0d, 0x29, 0x33, 0xc7, - 0xd2, 0x38, 0xd3, 0x4e, 0xda, 0x32, 0x81, 0x77, 0x70, 0xe1, 0x4b, 0xf8, 0x2e, 0x2c, 0x59, 0x1a, - 0x17, 0xc4, 0xc0, 0x1b, 0xf8, 0x04, 0x86, 0xce, 0xe0, 0x85, 0x2d, 0xab, 0x9e, 0x9e, 0xef, 0xcb, - 0xd7, 0xaf, 0xe7, 0x7c, 0xb8, 0x25, 0xc5, 0x4c, 0xe8, 0x05, 0x55, 0x9a, 0xc5, 0x29, 0xd0, 0xa2, - 0x47, 0xa1, 0x00, 0x69, 0xc3, 0x5c, 0x2b, 0xab, 0xc8, 0xa3, 0x12, 0x0d, 0x4b, 0x34, 0x2c, 0x7a, - 0xcd, 0xc7, 0x5c, 0x71, 0xe5, 0x40, 0x7a, 0xa8, 0x4a, 0x5e, 0xb3, 0xc5, 0x95, 0xe2, 0x29, 0x50, - 0x96, 0x0b, 0xca, 0xa4, 0x54, 0x96, 0x59, 0xa1, 0xa4, 0x29, 0xd1, 0xe0, 0x27, 0xc2, 0x4f, 0x47, - 0x07, 0xd5, 0xd1, 0x32, 0x9e, 0x33, 0xc9, 0x21, 0x62, 0x16, 0x3e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f1, 0x7a, 0xe7, 0xa3, 0xcd, 0xce, 0x47, 0x7f, 0x76, 0x3e, 0xfa, 0xb1, 0xf7, 0xbd, 0xcd, - 0xde, 0xf7, 0x7e, 0xed, 0x7d, 0xef, 0xcb, 0xcb, 0x93, 0x25, 0xbd, 0x77, 0x21, 0x1a, 0xcc, 0x99, - 0x90, 0xb4, 0x8a, 0xdb, 0xf2, 0x18, 0x38, 0xb7, 0xae, 0xd9, 0xb5, 0x0b, 0xca, 0xeb, 0x7f, 0x01, - 0x00, 0x00, 0xff, 0xff, 0xc8, 0x26, 0xa5, 0x2c, 0x8e, 0x02, 0x00, 0x00, + // 407 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x52, 0xcd, 0x8e, 0xd3, 0x30, + 0x10, 0x8e, 0x29, 0x54, 0x5a, 0x2f, 0x07, 0x64, 0xf1, 0x53, 0x45, 0x25, 0x5d, 0x82, 0x84, 0x7a, + 0x00, 0x5b, 0x0b, 0x4f, 0x40, 0xb7, 0xbb, 0xb7, 0x45, 0x28, 0xe2, 0x47, 0xe2, 0x82, 0xdc, 0x64, + 0x70, 0x2d, 0x12, 0xdb, 0xb2, 0xdd, 0x68, 0x79, 0x0b, 0x4e, 0xbc, 0x00, 0x37, 0x9e, 0x64, 0x8f, + 0x7b, 0x44, 0x1c, 0x0a, 0x6a, 0x5f, 0x04, 0xc5, 0x49, 0xa1, 0xd0, 0x5b, 0x4f, 0x1e, 0x7f, 0xdf, + 0xcc, 0xe7, 0xcf, 0x33, 0x83, 0x87, 0x4a, 0xce, 0xa4, 0x5d, 0x30, 0x6d, 0x79, 0x5e, 0x02, 0xab, + 0x8f, 0x19, 0xd4, 0xa0, 0x3c, 0x35, 0x56, 0x7b, 0x4d, 0x6e, 0xb5, 0x2c, 0x6d, 0x59, 0x5a, 0x1f, + 0xc7, 0xf7, 0x77, 0xf2, 0x3b, 0x2e, 0x14, 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 0xbc, 0xc5, 0xfd, + 0xf0, 0x99, 0xc6, 0x7d, 0x6f, 0x7c, 0xf8, 0xf4, 0x21, 0xfd, 0x7f, 0x5e, 0x74, 0xbb, 0xa7, 0xaf, + 0x16, 0xa6, 0x84, 0x49, 0xdc, 0xf4, 0xeb, 0xdb, 0xcf, 0x11, 0xd9, 0xa1, 0x5c, 0xd6, 0xc9, 0xa5, + 0xe7, 0xf8, 0xce, 0xbf, 0x26, 0x5f, 0x5a, 0xa8, 0xf7, 0xf6, 0x39, 0x39, 0xbb, 0x5c, 0x25, 0xe8, + 0x6a, 0x95, 0xa0, 0x5f, 0xab, 0x04, 0x7d, 0x5e, 0x27, 0xd1, 0xd5, 0x3a, 0x89, 0xbe, 0xaf, 0x93, + 0xe8, 0xdd, 0xe3, 0xad, 0xa1, 0xbd, 0x08, 0xde, 0x4f, 0xe6, 0x5c, 0x2a, 0xd6, 0x6d, 0xd9, 0xc5, + 0x66, 0xcf, 0xc2, 0xf8, 0x66, 0xfd, 0xb0, 0x30, 0xcf, 0x7e, 0x07, 0x00, 0x00, 0xff, 0xff, 0xb2, + 0x0f, 0xc9, 0xbf, 0xb5, 0x02, 0x00, 0x00, } func (m *EventExchangeRateUpdate) Marshal() (dAtA []byte, err error) { @@ -320,9 +321,9 @@ func (m *EventExchangeRateUpdate) MarshalToSizedBuffer(dAtA []byte) (int, error) dAtA[i] = 0x18 } { - size := m.ExchangeRate.Size() + size := m.Price.Size() i -= size - if _, err := m.ExchangeRate.MarshalTo(dAtA[i:]); err != nil { + if _, err := m.Price.MarshalTo(dAtA[i:]); err != nil { return 0, err } i = encodeVarintEvent(dAtA, i, uint64(size)) @@ -396,12 +397,19 @@ func (m *EventAggregateVote) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if len(m.ExchangeRates) > 0 { - i -= len(m.ExchangeRates) - copy(dAtA[i:], m.ExchangeRates) - i = encodeVarintEvent(dAtA, i, uint64(len(m.ExchangeRates))) - i-- - dAtA[i] = 0x1a + if len(m.Prices) > 0 { + for iNdEx := len(m.Prices) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Prices[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintEvent(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } } if len(m.Feeder) > 0 { i -= len(m.Feeder) @@ -478,7 +486,7 @@ func (m *EventExchangeRateUpdate) Size() (n int) { if l > 0 { n += 1 + l + sovEvent(uint64(l)) } - l = m.ExchangeRate.Size() + l = m.Price.Size() n += 1 + l + sovEvent(uint64(l)) if m.TimestampMs != 0 { n += 1 + sovEvent(uint64(m.TimestampMs)) @@ -517,9 +525,11 @@ func (m *EventAggregateVote) Size() (n int) { if l > 0 { n += 1 + l + sovEvent(uint64(l)) } - l = len(m.ExchangeRates) - if l > 0 { - n += 1 + l + sovEvent(uint64(l)) + if len(m.Prices) > 0 { + for _, e := range m.Prices { + l = e.Size() + n += 1 + l + sovEvent(uint64(l)) + } } return n } @@ -610,7 +620,7 @@ func (m *EventExchangeRateUpdate) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 2: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ExchangeRate", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Price", wireType) } var stringLen uint64 for shift := uint(0); ; shift += 7 { @@ -638,7 +648,7 @@ func (m *EventExchangeRateUpdate) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if err := m.ExchangeRate.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + if err := m.Price.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex @@ -891,9 +901,9 @@ func (m *EventAggregateVote) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 3: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ExchangeRates", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Prices", wireType) } - var stringLen uint64 + var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowEvent @@ -903,23 +913,25 @@ func (m *EventAggregateVote) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - stringLen |= uint64(b&0x7F) << shift + msglen |= int(b&0x7F) << shift if b < 0x80 { break } } - intStringLen := int(stringLen) - if intStringLen < 0 { + if msglen < 0 { return ErrInvalidLengthEvent } - postIndex := iNdEx + intStringLen + postIndex := iNdEx + msglen if postIndex < 0 { return ErrInvalidLengthEvent } if postIndex > l { return io.ErrUnexpectedEOF } - m.ExchangeRates = string(dAtA[iNdEx:postIndex]) + m.Prices = append(m.Prices, ExchangeRateTuple{}) + if err := m.Prices[len(m.Prices)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } iNdEx = postIndex default: iNdEx = preIndex diff --git a/x/oracle/types/vote.go b/x/oracle/types/vote.go index 341cc267f..a82e6d351 100644 --- a/x/oracle/types/vote.go +++ b/x/oracle/types/vote.go @@ -83,7 +83,7 @@ func (m ExchangeRateTuple) ToString() (string, error) { func NewExchangeRateTupleFromString(s string) (ExchangeRateTuple, error) { // strip parentheses if len(s) <= 2 { - return ExchangeRateTuple{}, fmt.Errorf("invalid string length") + return ExchangeRateTuple{}, fmt.Errorf("invalid string length: %v", len(s)) } if s[0] != ExchangeRateTupleStringPrefix || s[len(s)-1] != ExchangeRateTupleStringSuffix { diff --git a/x/oracle/types/vote_test.go b/x/oracle/types/vote_test.go index d6bb130c5..1480d750b 100644 --- a/x/oracle/types/vote_test.go +++ b/x/oracle/types/vote_test.go @@ -10,7 +10,7 @@ import ( "github.com/NibiruChain/nibiru/x/oracle/types" ) -func TestParseExchangeRateTuples(t *testing.T) { +func TestExchangeRateTuples_ToString(t *testing.T) { t.Run("inverse", func(t *testing.T) { tuples := types.ExchangeRateTuples{ { From 6dfa3f4feb857ff565b46eaca5fa6c8f63d4ea97 Mon Sep 17 00:00:00 2001 From: Unique-Divine Date: Mon, 3 Jul 2023 11:04:46 -0500 Subject: [PATCH 6/7] small typo in comments --- proto/nibiru/oracle/v1/event.proto | 4 ++-- x/oracle/types/event.pb.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/proto/nibiru/oracle/v1/event.proto b/proto/nibiru/oracle/v1/event.proto index 7a08ac7d3..7d34302f7 100644 --- a/proto/nibiru/oracle/v1/event.proto +++ b/proto/nibiru/oracle/v1/event.proto @@ -33,7 +33,7 @@ message EventAggregateVote { // Validator is the Bech32 address to which the vote will be credited. string validator = 1; - // Feeder is the delegate or representative that will sends vote and prevote + // Feeder is the delegate or representative that will send vote and prevote // transaction messages on behalf of the voting validator. string feeder = 2; @@ -49,7 +49,7 @@ message EventAggregatePrevote { // Validator is the Bech32 address to which the vote will be credited. string validator = 1; - // Feeder is the delegate or representative that will sends vote and prevote + // Feeder is the delegate or representative that will send vote and prevote // transaction messages on behalf of the voting validator. string feeder = 2; } diff --git a/x/oracle/types/event.pb.go b/x/oracle/types/event.pb.go index 7735b2769..23cd87277 100644 --- a/x/oracle/types/event.pb.go +++ b/x/oracle/types/event.pb.go @@ -139,7 +139,7 @@ func (m *EventDelegateFeederConsent) GetFeeder() string { type EventAggregateVote struct { // Validator is the Bech32 address to which the vote will be credited. Validator string `protobuf:"bytes,1,opt,name=validator,proto3" json:"validator,omitempty"` - // Feeder is the delegate or representative that will sends vote and prevote + // Feeder is the delegate or representative that will send vote and prevote // transaction messages on behalf of the voting validator. Feeder string `protobuf:"bytes,2,opt,name=feeder,proto3" json:"feeder,omitempty"` Prices ExchangeRateTuples `protobuf:"bytes,3,rep,name=prices,proto3,castrepeated=ExchangeRateTuples" json:"prices"` @@ -204,7 +204,7 @@ func (m *EventAggregateVote) GetPrices() ExchangeRateTuples { type EventAggregatePrevote struct { // Validator is the Bech32 address to which the vote will be credited. Validator string `protobuf:"bytes,1,opt,name=validator,proto3" json:"validator,omitempty"` - // Feeder is the delegate or representative that will sends vote and prevote + // Feeder is the delegate or representative that will send vote and prevote // transaction messages on behalf of the voting validator. Feeder string `protobuf:"bytes,2,opt,name=feeder,proto3" json:"feeder,omitempty"` } From 22e3827e922f020ef86ad3c980c7ff2b87434990 Mon Sep 17 00:00:00 2001 From: Unique-Divine Date: Mon, 3 Jul 2023 11:09:32 -0500 Subject: [PATCH 7/7] refactor(oracle)!: prefer "Price" to "ExchangeRate" in events --- proto/nibiru/oracle/v1/event.proto | 2 +- x/oracle/keeper/keeper.go | 2 +- x/oracle/keeper/querier_test.go | 2 +- x/oracle/keeper/update_exchange_rates.go | 2 +- x/oracle/types/event.pb.go | 100 +++++++++++------------ 5 files changed, 54 insertions(+), 54 deletions(-) diff --git a/proto/nibiru/oracle/v1/event.proto b/proto/nibiru/oracle/v1/event.proto index 7d34302f7..73acb862f 100644 --- a/proto/nibiru/oracle/v1/event.proto +++ b/proto/nibiru/oracle/v1/event.proto @@ -9,7 +9,7 @@ import "google/api/annotations.proto"; option go_package = "github.com/NibiruChain/nibiru/x/oracle/types"; // Emitted when a price is posted -message EventExchangeRateUpdate { +message EventPriceUpdate { string pair = 1; string price = 2 [ (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", diff --git a/x/oracle/keeper/keeper.go b/x/oracle/keeper/keeper.go index 9babce5a1..f23b6ad7e 100644 --- a/x/oracle/keeper/keeper.go +++ b/x/oracle/keeper/keeper.go @@ -180,7 +180,7 @@ func (k Keeper) SetPrice(ctx sdk.Context, pair asset.Pair, price sdk.Dec) { Price: price, TimestampMs: timestampMs, }) - if err := ctx.EventManager().EmitTypedEvent(&types.EventExchangeRateUpdate{ + if err := ctx.EventManager().EmitTypedEvent(&types.EventPriceUpdate{ Pair: pair.String(), Price: price, TimestampMs: timestampMs, diff --git a/x/oracle/keeper/querier_test.go b/x/oracle/keeper/querier_test.go index bd02565e8..a520a9a1d 100644 --- a/x/oracle/keeper/querier_test.go +++ b/x/oracle/keeper/querier_test.go @@ -97,7 +97,7 @@ func TestQueryExchangeRateTwap(t *testing.T) { testutilevents.RequireContainsTypedEvent( t, input.Ctx, - &types.EventExchangeRateUpdate{ + &types.EventPriceUpdate{ Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD).String(), Price: rate, TimestampMs: input.Ctx.BlockTime().UnixMilli()}, diff --git a/x/oracle/keeper/update_exchange_rates.go b/x/oracle/keeper/update_exchange_rates.go index ce5381e0d..429ff7b85 100644 --- a/x/oracle/keeper/update_exchange_rates.go +++ b/x/oracle/keeper/update_exchange_rates.go @@ -64,7 +64,7 @@ func (k Keeper) countVotesAndUpdateExchangeRates( k.SetPrice(ctx, pair, exchangeRate) - _ = ctx.EventManager().EmitTypedEvent(&types.EventExchangeRateUpdate{ + _ = ctx.EventManager().EmitTypedEvent(&types.EventPriceUpdate{ Pair: pairStr, Price: exchangeRate, TimestampMs: ctx.BlockTime().UnixMilli(), diff --git a/x/oracle/types/event.pb.go b/x/oracle/types/event.pb.go index 23cd87277..085a6c8ef 100644 --- a/x/oracle/types/event.pb.go +++ b/x/oracle/types/event.pb.go @@ -26,24 +26,24 @@ var _ = math.Inf const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // Emitted when a price is posted -type EventExchangeRateUpdate struct { +type EventPriceUpdate struct { Pair string `protobuf:"bytes,1,opt,name=pair,proto3" json:"pair,omitempty"` Price github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,2,opt,name=price,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"price"` TimestampMs int64 `protobuf:"varint,3,opt,name=timestamp_ms,json=timestampMs,proto3" json:"timestamp_ms,omitempty"` } -func (m *EventExchangeRateUpdate) Reset() { *m = EventExchangeRateUpdate{} } -func (m *EventExchangeRateUpdate) String() string { return proto.CompactTextString(m) } -func (*EventExchangeRateUpdate) ProtoMessage() {} -func (*EventExchangeRateUpdate) Descriptor() ([]byte, []int) { +func (m *EventPriceUpdate) Reset() { *m = EventPriceUpdate{} } +func (m *EventPriceUpdate) String() string { return proto.CompactTextString(m) } +func (*EventPriceUpdate) ProtoMessage() {} +func (*EventPriceUpdate) Descriptor() ([]byte, []int) { return fileDescriptor_94ec441b793fc0ea, []int{0} } -func (m *EventExchangeRateUpdate) XXX_Unmarshal(b []byte) error { +func (m *EventPriceUpdate) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *EventExchangeRateUpdate) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *EventPriceUpdate) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_EventExchangeRateUpdate.Marshal(b, m, deterministic) + return xxx_messageInfo_EventPriceUpdate.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -53,26 +53,26 @@ func (m *EventExchangeRateUpdate) XXX_Marshal(b []byte, deterministic bool) ([]b return b[:n], nil } } -func (m *EventExchangeRateUpdate) XXX_Merge(src proto.Message) { - xxx_messageInfo_EventExchangeRateUpdate.Merge(m, src) +func (m *EventPriceUpdate) XXX_Merge(src proto.Message) { + xxx_messageInfo_EventPriceUpdate.Merge(m, src) } -func (m *EventExchangeRateUpdate) XXX_Size() int { +func (m *EventPriceUpdate) XXX_Size() int { return m.Size() } -func (m *EventExchangeRateUpdate) XXX_DiscardUnknown() { - xxx_messageInfo_EventExchangeRateUpdate.DiscardUnknown(m) +func (m *EventPriceUpdate) XXX_DiscardUnknown() { + xxx_messageInfo_EventPriceUpdate.DiscardUnknown(m) } -var xxx_messageInfo_EventExchangeRateUpdate proto.InternalMessageInfo +var xxx_messageInfo_EventPriceUpdate proto.InternalMessageInfo -func (m *EventExchangeRateUpdate) GetPair() string { +func (m *EventPriceUpdate) GetPair() string { if m != nil { return m.Pair } return "" } -func (m *EventExchangeRateUpdate) GetTimestampMs() int64 { +func (m *EventPriceUpdate) GetTimestampMs() int64 { if m != nil { return m.TimestampMs } @@ -257,7 +257,7 @@ func (m *EventAggregatePrevote) GetFeeder() string { } func init() { - proto.RegisterType((*EventExchangeRateUpdate)(nil), "nibiru.oracle.v1.EventExchangeRateUpdate") + proto.RegisterType((*EventPriceUpdate)(nil), "nibiru.oracle.v1.EventPriceUpdate") proto.RegisterType((*EventDelegateFeederConsent)(nil), "nibiru.oracle.v1.EventDelegateFeederConsent") proto.RegisterType((*EventAggregateVote)(nil), "nibiru.oracle.v1.EventAggregateVote") proto.RegisterType((*EventAggregatePrevote)(nil), "nibiru.oracle.v1.EventAggregatePrevote") @@ -267,35 +267,35 @@ func init() { proto.RegisterFile("nibiru/oracle/v1/event.proto", fileDescriptor_ var fileDescriptor_94ec441b793fc0ea = []byte{ // 407 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x52, 0xcd, 0x8e, 0xd3, 0x30, - 0x10, 0x8e, 0x29, 0x54, 0x5a, 0x2f, 0x07, 0x64, 0xf1, 0x53, 0x45, 0x25, 0x5d, 0x82, 0x84, 0x7a, - 0x00, 0x5b, 0x0b, 0x4f, 0x40, 0xb7, 0xbb, 0xb7, 0x45, 0x28, 0xe2, 0x47, 0xe2, 0x82, 0xdc, 0x64, - 0x70, 0x2d, 0x12, 0xdb, 0xb2, 0xdd, 0x68, 0x79, 0x0b, 0x4e, 0xbc, 0x00, 0x37, 0x9e, 0x64, 0x8f, - 0x7b, 0x44, 0x1c, 0x0a, 0x6a, 0x5f, 0x04, 0xc5, 0x49, 0xa1, 0xd0, 0x5b, 0x4f, 0x1e, 0x7f, 0xdf, - 0xcc, 0xe7, 0xcf, 0x33, 0x83, 0x87, 0x4a, 0xce, 0xa4, 0x5d, 0x30, 0x6d, 0x79, 0x5e, 0x02, 0xab, - 0x8f, 0x19, 0xd4, 0xa0, 0x3c, 0x35, 0x56, 0x7b, 0x4d, 0x6e, 0xb5, 0x2c, 0x6d, 0x59, 0x5a, 0x1f, - 0xc7, 0xf7, 0x77, 0xf2, 0x3b, 0x2e, 0x14, 0xc4, 0xb7, 0x85, 0x16, 0x3a, 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0xa8, 0x79, 0x29, 0x0b, 0xee, 0xf5, 0x96, 0xef, 0x8f, 0x40, 0xee, 0xe1, + 0xfe, 0xfb, 0xd0, 0xde, 0x52, 0x66, 0xdd, 0x5b, 0xfa, 0x05, 0x61, 0x12, 0x42, 0x9f, 0x0b, 0x61, + 0x43, 0xea, 0x6b, 0xed, 0x61, 0xbf, 0x30, 0xf2, 0x06, 0xf7, 0xc3, 0xcf, 0x34, 0xf4, 0xbd, 0xf1, + 0xe1, 0xd3, 0x87, 0xf4, 0xff, 0x41, 0xd1, 0xb3, 0xab, 0x7c, 0xce, 0x95, 0x80, 0x8c, 0x7b, 0x78, + 0xb9, 0x30, 0x25, 0x4c, 0xe2, 0xe6, 0xbe, 0xbe, 0xfe, 0x18, 0x91, 0x1d, 0xcb, 0x65, 0x5d, 0x5c, + 0x7a, 0x81, 0xef, 0xfe, 0x0b, 0x79, 0x69, 0xa1, 0xde, 0x9b, 0x73, 0x72, 0x7e, 0xbd, 0x4e, 0xd0, + 0x72, 0x9d, 0xa0, 0x9f, 0xeb, 0x04, 0x7d, 0xde, 0x24, 0xd1, 0x72, 0x93, 0x44, 0xdf, 0x36, 0x49, + 0xf4, 0xf6, 0xf1, 0x5f, 0x43, 0x7b, 0x11, 0xd8, 0x4f, 0xe7, 0x5c, 0x2a, 0xd6, 0xad, 0xd7, 0xd5, + 0x76, 0xc1, 0xc2, 0xf8, 0x66, 0xfd, 0xb0, 0x29, 0xcf, 0x7e, 0x05, 0x00, 0x00, 0xff, 0xff, 0x3b, + 0xea, 0x2b, 0x3c, 0xae, 0x02, 0x00, 0x00, } -func (m *EventExchangeRateUpdate) Marshal() (dAtA []byte, err error) { +func (m *EventPriceUpdate) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -305,12 +305,12 @@ func (m *EventExchangeRateUpdate) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *EventExchangeRateUpdate) MarshalTo(dAtA []byte) (int, error) { +func (m *EventPriceUpdate) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *EventExchangeRateUpdate) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *EventPriceUpdate) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int @@ -476,7 +476,7 @@ func encodeVarintEvent(dAtA []byte, offset int, v uint64) int { dAtA[offset] = uint8(v) return base } -func (m *EventExchangeRateUpdate) Size() (n int) { +func (m *EventPriceUpdate) Size() (n int) { if m == nil { return 0 } @@ -557,7 +557,7 @@ func sovEvent(x uint64) (n int) { func sozEvent(x uint64) (n int) { return sovEvent(uint64((x << 1) ^ uint64((int64(x) >> 63)))) } -func (m *EventExchangeRateUpdate) Unmarshal(dAtA []byte) error { +func (m *EventPriceUpdate) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -580,10 +580,10 @@ func (m *EventExchangeRateUpdate) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: EventExchangeRateUpdate: wiretype end group for non-group") + return fmt.Errorf("proto: EventPriceUpdate: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: EventExchangeRateUpdate: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: EventPriceUpdate: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: