From b6b40db32b02ed03d1029f9b7f214679a8b9c2ac Mon Sep 17 00:00:00 2001 From: Xiaoyu Chen Date: Fri, 20 May 2022 15:55:08 -0700 Subject: [PATCH 1/5] wip --- go.mod | 1 + proto/dex/genesis.proto | 5 +- proto/dex/{twap.proto => price.proto} | 8 +- proto/dex/query.proto | 19 +- x/dex/genesis.go | 6 - x/dex/types/genesis.pb.go | 109 ++--- x/dex/types/price.pb.go | 475 ++++++++++++++++++++++ x/dex/types/query.pb.go | 377 ++++++++++-------- x/dex/types/query.pb.gw.go | 70 ++-- x/dex/types/twap.pb.go | 548 -------------------------- 10 files changed, 778 insertions(+), 840 deletions(-) rename proto/dex/{twap.proto => price.proto} (65%) create mode 100644 x/dex/types/price.pb.go delete mode 100644 x/dex/types/twap.pb.go diff --git a/go.mod b/go.mod index e5bb1ab4ae..c88a7184d5 100644 --- a/go.mod +++ b/go.mod @@ -31,6 +31,7 @@ require ( github.com/99designs/keyring v1.1.6 // indirect github.com/ChainSafe/go-schnorrkel v0.0.0-20200405005733-88cbf1b4c40d // indirect github.com/CosmWasm/wasmvm v1.0.0 // indirect + github.com/DataDog/zstd v1.4.5 // indirect github.com/Workiva/go-datastructures v1.0.53 // indirect github.com/armon/go-metrics v0.3.10 // indirect github.com/beorn7/perks v1.0.1 // indirect diff --git a/proto/dex/genesis.proto b/proto/dex/genesis.proto index d4a1866125..4864dd1948 100644 --- a/proto/dex/genesis.proto +++ b/proto/dex/genesis.proto @@ -5,7 +5,7 @@ import "gogoproto/gogo.proto"; import "dex/params.proto"; import "dex/long_book.proto"; import "dex/short_book.proto"; -import "dex/twap.proto"; +import "dex/price.proto"; // this line is used by starport scaffolding # genesis/proto/import option go_package = "github.com/sei-protocol/sei-chain/x/dex/types"; @@ -15,7 +15,6 @@ message GenesisState { Params params = 1 [(gogoproto.nullable) = false]; repeated LongBook longBookList = 2 [(gogoproto.nullable) = false]; repeated ShortBook shortBookList = 3 [(gogoproto.nullable) = false]; - repeated Twap twapList = 4; - uint64 lastEpoch = 5; + uint64 lastEpoch = 4; // this line is used by starport scaffolding # genesis/proto/state } diff --git a/proto/dex/twap.proto b/proto/dex/price.proto similarity index 65% rename from proto/dex/twap.proto rename to proto/dex/price.proto index d59a3b3729..a52ad67e3d 100644 --- a/proto/dex/twap.proto +++ b/proto/dex/price.proto @@ -3,11 +3,11 @@ package seiprotocol.seichain.dex; option go_package = "github.com/sei-protocol/sei-chain/x/dex/types"; -message Twap { +message Price { - uint64 lastEpoch = 1; - repeated uint64 prices = 2; - uint64 twapPrice = 3; + uint64 epoch = 1; + uint64 oraclePrice = 2; + uint64 exchangePrice = 3; string priceDenom = 4; string assetDenom = 5; } diff --git a/proto/dex/query.proto b/proto/dex/query.proto index fae51f9448..65470efe42 100644 --- a/proto/dex/query.proto +++ b/proto/dex/query.proto @@ -8,8 +8,8 @@ import "dex/params.proto"; import "dex/long_book.proto"; import "dex/short_book.proto"; import "dex/settlement.proto"; -import "dex/twap.proto"; import "dex/enums.proto"; +import "dex/price.proto"; // this line is used by starport scaffolding # 1 option go_package = "github.com/sei-protocol/sei-chain/x/dex/types"; @@ -44,9 +44,9 @@ service Query { option (google.api.http).get = "/sei-protocol/seichain/dex/settlement"; } -// Queries a list of GetTwap items. - rpc GetTwap(QueryGetTwapRequest) returns (QueryGetTwapResponse) { - option (google.api.http).get = "/sei-protocol/seichain/dex/get_twap/{priceDenom}/{assetDenom}"; +// Queries a list of GetPrice items. + rpc GetPrice(QueryGetPriceRequest) returns (QueryGetPriceResponse) { + option (google.api.http).get = "/sei-protocol/seichain/dex/get_price/{priceDenom}/{assetDenom}/{epoch}"; } // this line is used by starport scaffolding # 2 @@ -127,14 +127,15 @@ message QueryAllSettlementsResponse { cosmos.base.query.v1beta1.PageResponse pagination = 2; } -message QueryGetTwapRequest { - Denom priceDenom = 1; - Denom assetDenom = 2; +message QueryGetPriceRequest { + string priceDenom = 1; + string assetDenom = 2; string contractAddr = 3; + uint64 epoch = 4; } -message QueryGetTwapResponse { - Twap twaps = 1; +message QueryGetPriceResponse { + Price price = 1; } // this line is used by starport scaffolding # 3 diff --git a/x/dex/genesis.go b/x/dex/genesis.go index ac47abe982..87a974b899 100644 --- a/x/dex/genesis.go +++ b/x/dex/genesis.go @@ -22,12 +22,6 @@ func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState) // this line is used by starport scaffolding # genesis/module/init k.SetParams(ctx, genState.Params) - for _, twap := range genState.TwapList { - twap.LastEpoch = 0 - twap.TwapPrice = twap.Prices[0] - k.SetTwap(ctx, *twap, "genesis") - } - k.SetEpoch(ctx, genState.LastEpoch) } diff --git a/x/dex/types/genesis.pb.go b/x/dex/types/genesis.pb.go index 0a94c875c2..9667c60a44 100644 --- a/x/dex/types/genesis.pb.go +++ b/x/dex/types/genesis.pb.go @@ -28,8 +28,7 @@ type GenesisState struct { Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` LongBookList []LongBook `protobuf:"bytes,2,rep,name=longBookList,proto3" json:"longBookList"` ShortBookList []ShortBook `protobuf:"bytes,3,rep,name=shortBookList,proto3" json:"shortBookList"` - TwapList []*Twap `protobuf:"bytes,4,rep,name=twapList,proto3" json:"twapList,omitempty"` - LastEpoch uint64 `protobuf:"varint,5,opt,name=lastEpoch,proto3" json:"lastEpoch,omitempty"` + LastEpoch uint64 `protobuf:"varint,4,opt,name=lastEpoch,proto3" json:"lastEpoch,omitempty"` } func (m *GenesisState) Reset() { *m = GenesisState{} } @@ -86,13 +85,6 @@ func (m *GenesisState) GetShortBookList() []ShortBook { return nil } -func (m *GenesisState) GetTwapList() []*Twap { - if m != nil { - return m.TwapList - } - return nil -} - func (m *GenesisState) GetLastEpoch() uint64 { if m != nil { return m.LastEpoch @@ -107,28 +99,27 @@ func init() { func init() { proto.RegisterFile("dex/genesis.proto", fileDescriptor_a803aaabd08db59d) } var fileDescriptor_a803aaabd08db59d = []byte{ - // 326 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0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6a, 0x92, 0x74, 0x00, 0xc6, - 0x3d, 0xa1, 0x74, 0x50, 0x08, 0x8b, 0xcd, 0x4a, 0xbb, 0x91, 0x4f, 0xe9, 0x39, 0xb7, 0xe3, 0x1c, - 0x4c, 0xe3, 0x47, 0x74, 0x6a, 0x4f, 0xd8, 0xe3, 0x8a, 0x16, 0x77, 0x93, 0x8f, 0x1b, 0xec, 0xec, - 0x8e, 0x77, 0x38, 0x8f, 0xef, 0xd0, 0xb1, 0xb9, 0xde, 0xb2, 0x4a, 0x96, 0x45, 0xf2, 0x59, 0xcf, - 0x0b, 0x26, 0xfb, 0x7b, 0x3f, 0xbe, 0x42, 0x27, 0x13, 0xa6, 0xf4, 0x83, 0x84, 0x38, 0x0d, 0x8e, - 0x42, 0xbf, 0x59, 0xea, 0xff, 0x09, 0x9d, 0xee, 0x6a, 0x43, 0xfc, 0xf5, 0x86, 0xf8, 0x3f, 0x1b, - 0xe2, 0x7f, 0x6c, 0x89, 0xb7, 0xde, 0x12, 0xef, 0x6b, 0x4b, 0xbc, 0x97, 0x56, 0x22, 0x74, 0xfa, - 0x36, 0xa4, 0x31, 0x4c, 0x23, 0xc5, 0x45, 0x6b, 0xb7, 0xcc, 0x16, 0x76, 0x5b, 0xb4, 0x8c, 0xec, - 0xbf, 0xbc, 0x4b, 0xae, 0x86, 0x65, 0xdb, 0xbf, 0xfd, 0x0d, 0x00, 0x00, 0xff, 0xff, 0x87, 0x21, - 0x64, 0x44, 0x2b, 0x02, 0x00, 0x00, + // 309 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x90, 0xb1, 0x4e, 0xf3, 0x30, + 0x14, 0x85, 0xe3, 0xb6, 0xaa, 0xf4, 0xbb, 0xfd, 0x05, 0x84, 0x0e, 0x51, 0x85, 0x4c, 0x54, 0x96, + 0x2e, 0x75, 0xa4, 0xb2, 0x33, 0x54, 0x42, 0x5d, 0x22, 0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0x68, + 0x37, 0xbc, 0xd3, 0xbc, 0x7d, 0x85, 0xff, 0xa5, 0x81, 0x90, 0xf7, 0x39, 0x44, 0x89, 0xd3, 0x73, + 0xd1, 0xb4, 0xb7, 0xfa, 0x15, 0x16, 0xcb, 0x7d, 0x45, 0xd0, 0xa1, 0x22, 0xe8, 0xab, 0x22, 0xe8, + 0xbd, 0x26, 0xd6, 0xa1, 0x26, 0xd6, 0x47, 0x4d, 0xac, 0xa7, 0x59, 0xcc, 0x65, 0xf2, 0x12, 0xd2, + 0x08, 0x76, 0x9e, 0x60, 0x7c, 0x76, 0x3c, 0xae, 0x3f, 0xf4, 0x75, 0xaf, 0xf4, 0xd4, 0xe3, 0xca, + 0xd7, 0x9c, 0x89, 0xb0, 0xaf, 0xf7, 0xb7, 0xdf, 0x01, 0x00, 0x00, 0xff, 0xff, 0x7f, 0xfd, 0x77, + 0x48, 0xf0, 0x01, 0x00, 0x00, } func (m *GenesisState) Marshal() (dAtA []byte, err error) { @@ -154,21 +145,7 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { if m.LastEpoch != 0 { i = encodeVarintGenesis(dAtA, i, uint64(m.LastEpoch)) i-- - dAtA[i] = 0x28 - } - if len(m.TwapList) > 0 { - for iNdEx := len(m.TwapList) - 1; iNdEx >= 0; iNdEx-- { - { - size, err := m.TwapList[iNdEx].MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintGenesis(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x22 - } + dAtA[i] = 0x20 } if len(m.ShortBookList) > 0 { for iNdEx := len(m.ShortBookList) - 1; iNdEx >= 0; iNdEx-- { @@ -242,12 +219,6 @@ func (m *GenesisState) Size() (n int) { n += 1 + l + sovGenesis(uint64(l)) } } - if len(m.TwapList) > 0 { - for _, e := range m.TwapList { - l = e.Size() - n += 1 + l + sovGenesis(uint64(l)) - } - } if m.LastEpoch != 0 { n += 1 + sovGenesis(uint64(m.LastEpoch)) } @@ -391,40 +362,6 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { } iNdEx = postIndex case 4: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field TwapList", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGenesis - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthGenesis - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthGenesis - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.TwapList = append(m.TwapList, &Twap{}) - if err := m.TwapList[len(m.TwapList)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 5: if wireType != 0 { return fmt.Errorf("proto: wrong wireType = %d for field LastEpoch", wireType) } diff --git a/x/dex/types/price.pb.go b/x/dex/types/price.pb.go new file mode 100644 index 0000000000..f124301e05 --- /dev/null +++ b/x/dex/types/price.pb.go @@ -0,0 +1,475 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: dex/price.proto + +package types + +import ( + fmt "fmt" + proto "github.com/gogo/protobuf/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +type Price struct { + Epoch uint64 `protobuf:"varint,1,opt,name=epoch,proto3" json:"epoch,omitempty"` + OraclePrice uint64 `protobuf:"varint,2,opt,name=oraclePrice,proto3" json:"oraclePrice,omitempty"` + ExchangePrice uint64 `protobuf:"varint,3,opt,name=exchangePrice,proto3" json:"exchangePrice,omitempty"` + PriceDenom string `protobuf:"bytes,4,opt,name=priceDenom,proto3" json:"priceDenom,omitempty"` + AssetDenom string `protobuf:"bytes,5,opt,name=assetDenom,proto3" json:"assetDenom,omitempty"` +} + +func (m *Price) Reset() { *m = Price{} } +func (m *Price) String() string { return proto.CompactTextString(m) } +func (*Price) ProtoMessage() {} +func (*Price) Descriptor() ([]byte, []int) { + return fileDescriptor_bd5d1c9d490efb8c, []int{0} +} +func (m *Price) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Price) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Price.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 *Price) XXX_Merge(src proto.Message) { + xxx_messageInfo_Price.Merge(m, src) +} +func (m *Price) XXX_Size() int { + return m.Size() +} +func (m *Price) XXX_DiscardUnknown() { + xxx_messageInfo_Price.DiscardUnknown(m) +} + +var xxx_messageInfo_Price proto.InternalMessageInfo + +func (m *Price) GetEpoch() uint64 { + if m != nil { + return m.Epoch + } + return 0 +} + +func (m *Price) GetOraclePrice() uint64 { + if m != nil { + return m.OraclePrice + } + return 0 +} + +func (m *Price) GetExchangePrice() uint64 { + if m != nil { + return m.ExchangePrice + } + return 0 +} + +func (m *Price) GetPriceDenom() string { + if m != nil { + return m.PriceDenom + } + return "" +} + +func (m *Price) GetAssetDenom() string { + if m != nil { + return m.AssetDenom + } + return "" +} + +func init() { + proto.RegisterType((*Price)(nil), "seiprotocol.seichain.dex.Price") +} + +func init() { proto.RegisterFile("dex/price.proto", fileDescriptor_bd5d1c9d490efb8c) } + +var fileDescriptor_bd5d1c9d490efb8c = []byte{ + // 225 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x4f, 0x49, 0xad, 0xd0, + 0x2f, 0x28, 0xca, 0x4c, 0x4e, 0xd5, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x92, 0x28, 0x4e, 0xcd, + 0x04, 0xb3, 0x92, 0xf3, 0x73, 0xf4, 0x8a, 0x53, 0x33, 0x93, 0x33, 0x12, 0x33, 0xf3, 0xf4, 0x52, + 0x52, 0x2b, 0x94, 0x96, 0x32, 0x72, 0xb1, 0x06, 0x80, 0x54, 0x0a, 0x89, 0x70, 0xb1, 0xa6, 0x16, + 0xe4, 0x27, 0x67, 0x48, 0x30, 0x2a, 0x30, 0x6a, 0xb0, 0x04, 0x41, 0x38, 0x42, 0x0a, 0x5c, 0xdc, + 0xf9, 0x45, 0x89, 0xc9, 0x39, 0xa9, 0x60, 0x45, 0x12, 0x4c, 0x60, 0x39, 0x64, 0x21, 0x21, 0x15, + 0x2e, 0xde, 0xd4, 0x8a, 0xe4, 0x8c, 0xc4, 0xbc, 0x74, 0xa8, 0x1a, 0x66, 0xb0, 0x1a, 0x54, 0x41, + 0x21, 0x39, 0x2e, 0x2e, 0xb0, 0x83, 0x5c, 0x52, 0xf3, 0xf2, 0x73, 0x25, 0x58, 0x14, 0x18, 0x35, + 0x38, 0x83, 0x90, 0x44, 0x40, 0xf2, 0x89, 0xc5, 0xc5, 0xa9, 0x25, 0x10, 0x79, 0x56, 0x88, 0x3c, + 0x42, 0xc4, 0xc9, 0xfd, 0xc4, 0x23, 0x39, 0xc6, 0x0b, 0x8f, 0xe4, 0x18, 0x1f, 0x3c, 0x92, 0x63, + 0x9c, 0xf0, 0x58, 0x8e, 0xe1, 0xc2, 0x63, 0x39, 0x86, 0x1b, 0x8f, 0xe5, 0x18, 0xa2, 0x74, 0xd3, + 0x33, 0x4b, 0x32, 0x4a, 0x93, 0xf4, 0x92, 0xf3, 0x73, 0xf5, 0x8b, 0x53, 0x33, 0x75, 0x61, 0xfe, + 0x04, 0x73, 0xc0, 0x1e, 0xd5, 0xaf, 0xd0, 0x07, 0x05, 0x48, 0x49, 0x65, 0x41, 0x6a, 0x71, 0x12, + 0x1b, 0x58, 0xde, 0x18, 0x10, 0x00, 0x00, 0xff, 0xff, 0x82, 0x27, 0xad, 0xb3, 0x24, 0x01, 0x00, + 0x00, +} + +func (m *Price) 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 *Price) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Price) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.AssetDenom) > 0 { + i -= len(m.AssetDenom) + copy(dAtA[i:], m.AssetDenom) + i = encodeVarintPrice(dAtA, i, uint64(len(m.AssetDenom))) + i-- + dAtA[i] = 0x2a + } + if len(m.PriceDenom) > 0 { + i -= len(m.PriceDenom) + copy(dAtA[i:], m.PriceDenom) + i = encodeVarintPrice(dAtA, i, uint64(len(m.PriceDenom))) + i-- + dAtA[i] = 0x22 + } + if m.ExchangePrice != 0 { + i = encodeVarintPrice(dAtA, i, uint64(m.ExchangePrice)) + i-- + dAtA[i] = 0x18 + } + if m.OraclePrice != 0 { + i = encodeVarintPrice(dAtA, i, uint64(m.OraclePrice)) + i-- + dAtA[i] = 0x10 + } + if m.Epoch != 0 { + i = encodeVarintPrice(dAtA, i, uint64(m.Epoch)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func encodeVarintPrice(dAtA []byte, offset int, v uint64) int { + offset -= sovPrice(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *Price) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Epoch != 0 { + n += 1 + sovPrice(uint64(m.Epoch)) + } + if m.OraclePrice != 0 { + n += 1 + sovPrice(uint64(m.OraclePrice)) + } + if m.ExchangePrice != 0 { + n += 1 + sovPrice(uint64(m.ExchangePrice)) + } + l = len(m.PriceDenom) + if l > 0 { + n += 1 + l + sovPrice(uint64(l)) + } + l = len(m.AssetDenom) + if l > 0 { + n += 1 + l + sovPrice(uint64(l)) + } + return n +} + +func sovPrice(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozPrice(x uint64) (n int) { + return sovPrice(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *Price) 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 ErrIntOverflowPrice + } + 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: Price: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Price: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Epoch", wireType) + } + m.Epoch = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPrice + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Epoch |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field OraclePrice", wireType) + } + m.OraclePrice = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPrice + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.OraclePrice |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field ExchangePrice", wireType) + } + m.ExchangePrice = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPrice + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.ExchangePrice |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field PriceDenom", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPrice + } + 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 ErrInvalidLengthPrice + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthPrice + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.PriceDenom = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field AssetDenom", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPrice + } + 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 ErrInvalidLengthPrice + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthPrice + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.AssetDenom = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipPrice(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthPrice + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipPrice(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowPrice + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowPrice + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowPrice + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthPrice + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupPrice + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthPrice + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthPrice = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowPrice = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupPrice = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/dex/types/query.pb.go b/x/dex/types/query.pb.go index bd6fc10e5c..8289b99708 100644 --- a/x/dex/types/query.pb.go +++ b/x/dex/types/query.pb.go @@ -785,24 +785,25 @@ func (m *QueryAllSettlementsResponse) GetPagination() *query.PageResponse { return nil } -type QueryGetTwapRequest struct { - PriceDenom Denom `protobuf:"varint,1,opt,name=priceDenom,proto3,enum=seiprotocol.seichain.dex.Denom" json:"priceDenom,omitempty"` - AssetDenom Denom `protobuf:"varint,2,opt,name=assetDenom,proto3,enum=seiprotocol.seichain.dex.Denom" json:"assetDenom,omitempty"` +type QueryGetPriceRequest struct { + PriceDenom string `protobuf:"bytes,1,opt,name=priceDenom,proto3" json:"priceDenom,omitempty"` + AssetDenom string `protobuf:"bytes,2,opt,name=assetDenom,proto3" json:"assetDenom,omitempty"` ContractAddr string `protobuf:"bytes,3,opt,name=contractAddr,proto3" json:"contractAddr,omitempty"` + Epoch uint64 `protobuf:"varint,4,opt,name=epoch,proto3" json:"epoch,omitempty"` } -func (m *QueryGetTwapRequest) Reset() { *m = QueryGetTwapRequest{} } -func (m *QueryGetTwapRequest) String() string { return proto.CompactTextString(m) } -func (*QueryGetTwapRequest) ProtoMessage() {} -func (*QueryGetTwapRequest) Descriptor() ([]byte, []int) { +func (m *QueryGetPriceRequest) Reset() { *m = QueryGetPriceRequest{} } +func (m *QueryGetPriceRequest) String() string { return proto.CompactTextString(m) } +func (*QueryGetPriceRequest) ProtoMessage() {} +func (*QueryGetPriceRequest) Descriptor() ([]byte, []int) { return fileDescriptor_d8e98105e6e08a59, []int{14} } -func (m *QueryGetTwapRequest) XXX_Unmarshal(b []byte) error { +func (m *QueryGetPriceRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *QueryGetTwapRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *QueryGetPriceRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_QueryGetTwapRequest.Marshal(b, m, deterministic) + return xxx_messageInfo_QueryGetPriceRequest.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -812,55 +813,62 @@ func (m *QueryGetTwapRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, return b[:n], nil } } -func (m *QueryGetTwapRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_QueryGetTwapRequest.Merge(m, src) +func (m *QueryGetPriceRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryGetPriceRequest.Merge(m, src) } -func (m *QueryGetTwapRequest) XXX_Size() int { +func (m *QueryGetPriceRequest) XXX_Size() int { return m.Size() } -func (m *QueryGetTwapRequest) XXX_DiscardUnknown() { - xxx_messageInfo_QueryGetTwapRequest.DiscardUnknown(m) +func (m *QueryGetPriceRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryGetPriceRequest.DiscardUnknown(m) } -var xxx_messageInfo_QueryGetTwapRequest proto.InternalMessageInfo +var xxx_messageInfo_QueryGetPriceRequest proto.InternalMessageInfo -func (m *QueryGetTwapRequest) GetPriceDenom() Denom { +func (m *QueryGetPriceRequest) GetPriceDenom() string { if m != nil { return m.PriceDenom } - return Denom_SEI + return "" } -func (m *QueryGetTwapRequest) GetAssetDenom() Denom { +func (m *QueryGetPriceRequest) GetAssetDenom() string { if m != nil { return m.AssetDenom } - return Denom_SEI + return "" } -func (m *QueryGetTwapRequest) GetContractAddr() string { +func (m *QueryGetPriceRequest) GetContractAddr() string { if m != nil { return m.ContractAddr } return "" } -type QueryGetTwapResponse struct { - Twaps *Twap `protobuf:"bytes,1,opt,name=twaps,proto3" json:"twaps,omitempty"` +func (m *QueryGetPriceRequest) GetEpoch() uint64 { + if m != nil { + return m.Epoch + } + return 0 +} + +type QueryGetPriceResponse struct { + Price *Price `protobuf:"bytes,1,opt,name=price,proto3" json:"price,omitempty"` } -func (m *QueryGetTwapResponse) Reset() { *m = QueryGetTwapResponse{} } -func (m *QueryGetTwapResponse) String() string { return proto.CompactTextString(m) } -func (*QueryGetTwapResponse) ProtoMessage() {} -func (*QueryGetTwapResponse) Descriptor() ([]byte, []int) { +func (m *QueryGetPriceResponse) Reset() { *m = QueryGetPriceResponse{} } +func (m *QueryGetPriceResponse) String() string { return proto.CompactTextString(m) } +func (*QueryGetPriceResponse) ProtoMessage() {} +func (*QueryGetPriceResponse) Descriptor() ([]byte, []int) { return fileDescriptor_d8e98105e6e08a59, []int{15} } -func (m *QueryGetTwapResponse) XXX_Unmarshal(b []byte) error { +func (m *QueryGetPriceResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *QueryGetTwapResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *QueryGetPriceResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_QueryGetTwapResponse.Marshal(b, m, deterministic) + return xxx_messageInfo_QueryGetPriceResponse.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -870,21 +878,21 @@ func (m *QueryGetTwapResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte return b[:n], nil } } -func (m *QueryGetTwapResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_QueryGetTwapResponse.Merge(m, src) +func (m *QueryGetPriceResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryGetPriceResponse.Merge(m, src) } -func (m *QueryGetTwapResponse) XXX_Size() int { +func (m *QueryGetPriceResponse) XXX_Size() int { return m.Size() } -func (m *QueryGetTwapResponse) XXX_DiscardUnknown() { - xxx_messageInfo_QueryGetTwapResponse.DiscardUnknown(m) +func (m *QueryGetPriceResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryGetPriceResponse.DiscardUnknown(m) } -var xxx_messageInfo_QueryGetTwapResponse proto.InternalMessageInfo +var xxx_messageInfo_QueryGetPriceResponse proto.InternalMessageInfo -func (m *QueryGetTwapResponse) GetTwaps() *Twap { +func (m *QueryGetPriceResponse) GetPrice() *Price { if m != nil { - return m.Twaps + return m.Price } return nil } @@ -904,74 +912,74 @@ func init() { proto.RegisterType((*QueryGetSettlementsResponse)(nil), "seiprotocol.seichain.dex.QueryGetSettlementsResponse") proto.RegisterType((*QueryAllSettlementsRequest)(nil), "seiprotocol.seichain.dex.QueryAllSettlementsRequest") proto.RegisterType((*QueryAllSettlementsResponse)(nil), "seiprotocol.seichain.dex.QueryAllSettlementsResponse") - proto.RegisterType((*QueryGetTwapRequest)(nil), "seiprotocol.seichain.dex.QueryGetTwapRequest") - proto.RegisterType((*QueryGetTwapResponse)(nil), "seiprotocol.seichain.dex.QueryGetTwapResponse") + proto.RegisterType((*QueryGetPriceRequest)(nil), "seiprotocol.seichain.dex.QueryGetPriceRequest") + proto.RegisterType((*QueryGetPriceResponse)(nil), "seiprotocol.seichain.dex.QueryGetPriceResponse") } func init() { proto.RegisterFile("dex/query.proto", fileDescriptor_d8e98105e6e08a59) } var fileDescriptor_d8e98105e6e08a59 = []byte{ - // 950 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe4, 0x57, 0xcd, 0x4f, 0x1b, 0x47, - 0x14, 0xf7, 0xd8, 0x40, 0xcb, 0x18, 0xd1, 0x6a, 0xb0, 0x54, 0x77, 0x5b, 0x19, 0x77, 0x11, 0x85, - 0x56, 0xf5, 0xae, 0x30, 0xf4, 0xd8, 0x22, 0x10, 0xad, 0x7b, 0x80, 0x96, 0xba, 0x85, 0x56, 0x95, - 0x1a, 0xb2, 0x5e, 0x8f, 0xd6, 0x2b, 0xd6, 0x3b, 0x8b, 0x77, 0x1c, 0x40, 0x88, 0x4b, 0x2e, 0xc9, - 0x11, 0x29, 0x7f, 0x45, 0xa4, 0x44, 0x39, 0xe5, 0x94, 0x73, 0x24, 0xa4, 0x1c, 0x82, 0x94, 0x0f, - 0xe5, 0x14, 0x45, 0xc0, 0x1f, 0x12, 0xed, 0xec, 0xec, 0x87, 0x59, 0xaf, 0x3f, 0xc0, 0x87, 0x7c, - 0xdc, 0xec, 0xb7, 0xef, 0x37, 0xef, 0xfd, 0x7e, 0xef, 0xe7, 0x9d, 0x67, 0xf8, 0x59, 0x15, 0xef, - 0xc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57, 0x81, 0xf1, 0x9a, 0x41, 0xd3, 0x9d, - 0x78, 0xf9, 0x38, 0xf4, 0x00, 0xc0, 0x4f, 0xf8, 0xfb, 0x0d, 0x15, 0xba, 0x3b, 0x24, 0xf4, 0x12, - 0x17, 0xa4, 0x5e, 0xd3, 0x79, 0x67, 0xbf, 0xb0, 0xce, 0x16, 0xd1, 0x4f, 0x1d, 0x3a, 0xd3, 0x30, - 0xdd, 0x72, 0x5e, 0x97, 0xf1, 0x02, 0x2f, 0x97, 0x8e, 0x4f, 0x73, 0xe0, 0xe4, 0x34, 0x07, 0xde, - 0x9c, 0xe6, 0xc0, 0xd1, 0x59, 0x2e, 0x71, 0x72, 0x96, 0x4b, 0xbc, 0x3a, 0xcb, 0x25, 0xfe, 0x2b, - 0x68, 0x3a, 0xad, 0x35, 0x2b, 0x92, 0x4a, 0xea, 0x91, 0x12, 0x05, 0xb7, 0xc6, 0x1e, 0xab, 0x42, - 0xf7, 0x2d, 0x6c, 0x57, 0x46, 0xd8, 0xf3, 0xf9, 0xb7, 0x01, 0x00, 0x00, 0xff, 0xff, 0x53, 0x51, - 0x3f, 0x93, 0x6e, 0x10, 0x00, 0x00, + // 957 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe4, 0x57, 0x4d, 0x6f, 0xeb, 0x44, + 0x14, 0xcd, 0x24, 0x69, 0xf5, 0xde, 0xe4, 0xe9, 0x81, 0xa6, 0x41, 0x04, 0x83, 0xdc, 0xe0, 0xaa, + 0xb4, 0x20, 0x62, 0xab, 0x29, 0xdd, 0x82, 0x5a, 0x55, 0x4d, 0x17, 0xb4, 0x84, 0xa0, 0x16, 0x84, + 0x04, 0xc5, 0x71, 0x46, 0x8e, 0x55, 0xc7, 0xe3, 0xc6, 0x13, 0xd4, 0xaa, 0xca, 0x86, 0x0d, 0x2c, + 0x2b, 0xf1, 0x2b, 0x90, 0x60, 0xc9, 0x8a, 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, 0xfd, 0x04, 0xe0, 0x93, 0xb0, 0xaa, 0x3f, 0xa5, 0x29, 0x24, 0x9f, 0x99, 0x59, + 0xda, 0xb5, 0xab, 0x1c, 0x33, 0x66, 0x75, 0x74, 0x38, 0x5f, 0x66, 0xe8, 0x5b, 0x00, 0x9f, 0xc6, + 0x8e, 0x48, 0x9f, 0xd3, 0x5b, 0x53, 0xf4, 0x97, 0xb8, 0x12, 0xa4, 0xad, 0x19, 0x51, 0x82, 0x57, + 0x85, 0xf1, 0x5a, 0x43, 0xab, 0xe3, 0x78, 0x85, 0x38, 0xf4, 0x03, 0x80, 0x8f, 0x82, 0x13, 0x0e, + 0xa9, 0x93, 0x2d, 0x12, 0x3f, 0x9c, 0x25, 0x6d, 0xea, 0x7c, 0xd1, 0xdc, 0x21, 0x6b, 0x6e, 0x1f, + 0xed, 0x8d, 0x69, 0xce, 0xc4, 0xf4, 0x84, 0xa9, 0x3b, 0xce, 0x3e, 0xec, 0x88, 0xee, 0xef, 0xd4, + 0xae, 0x6f, 0x65, 0x70, 0x73, 0x2b, 0x83, 0xbf, 0x6e, 0x65, 0x70, 0x75, 0x27, 0x67, 0x6e, 0xee, + 0xe4, 0xcc, 0x1f, 0x77, 0x72, 0xe6, 0xe3, 0x8a, 0x69, 0xd1, 0x76, 0xaf, 0xa9, 0x1a, 0xa4, 0x93, + 0xa8, 0x55, 0xe1, 0xc5, 0xce, 0x59, 0x39, 0x7a, 0xe1, 0x62, 0xaf, 0xb9, 0xc8, 0xd6, 0x37, 0xff, + 0x0e, 0x00, 0x00, 0xff, 0xff, 0x57, 0x6a, 0xd2, 0x61, 0x52, 0x10, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -997,8 +1005,8 @@ type QueryClient interface { // Queries a list of ShortBook items. ShortBookAll(ctx context.Context, in *QueryAllShortBookRequest, opts ...grpc.CallOption) (*QueryAllShortBookResponse, error) SettlementsAll(ctx context.Context, in *QueryAllSettlementsRequest, opts ...grpc.CallOption) (*QueryAllSettlementsResponse, error) - // Queries a list of GetTwap items. - GetTwap(ctx context.Context, in *QueryGetTwapRequest, opts ...grpc.CallOption) (*QueryGetTwapResponse, error) + // Queries a list of GetPrice items. + GetPrice(ctx context.Context, in *QueryGetPriceRequest, opts ...grpc.CallOption) (*QueryGetPriceResponse, error) } type queryClient struct { @@ -1063,9 +1071,9 @@ func (c *queryClient) SettlementsAll(ctx context.Context, in *QueryAllSettlement return out, nil } -func (c *queryClient) GetTwap(ctx context.Context, in *QueryGetTwapRequest, opts ...grpc.CallOption) (*QueryGetTwapResponse, error) { - out := new(QueryGetTwapResponse) - err := c.cc.Invoke(ctx, "/seiprotocol.seichain.dex.Query/GetTwap", in, out, opts...) +func (c *queryClient) GetPrice(ctx context.Context, in *QueryGetPriceRequest, opts ...grpc.CallOption) (*QueryGetPriceResponse, error) { + out := new(QueryGetPriceResponse) + err := c.cc.Invoke(ctx, "/seiprotocol.seichain.dex.Query/GetPrice", in, out, opts...) if err != nil { return nil, err } @@ -1085,8 +1093,8 @@ type QueryServer interface { // Queries a list of ShortBook items. ShortBookAll(context.Context, *QueryAllShortBookRequest) (*QueryAllShortBookResponse, error) SettlementsAll(context.Context, *QueryAllSettlementsRequest) (*QueryAllSettlementsResponse, error) - // Queries a list of GetTwap items. - GetTwap(context.Context, *QueryGetTwapRequest) (*QueryGetTwapResponse, error) + // Queries a list of GetPrice items. + GetPrice(context.Context, *QueryGetPriceRequest) (*QueryGetPriceResponse, error) } // UnimplementedQueryServer can be embedded to have forward compatible implementations. @@ -1111,8 +1119,8 @@ func (*UnimplementedQueryServer) ShortBookAll(ctx context.Context, req *QueryAll func (*UnimplementedQueryServer) SettlementsAll(ctx context.Context, req *QueryAllSettlementsRequest) (*QueryAllSettlementsResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method SettlementsAll not implemented") } -func (*UnimplementedQueryServer) GetTwap(ctx context.Context, req *QueryGetTwapRequest) (*QueryGetTwapResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method GetTwap not implemented") +func (*UnimplementedQueryServer) GetPrice(ctx context.Context, req *QueryGetPriceRequest) (*QueryGetPriceResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetPrice not implemented") } func RegisterQueryServer(s grpc1.Server, srv QueryServer) { @@ -1227,20 +1235,20 @@ func _Query_SettlementsAll_Handler(srv interface{}, ctx context.Context, dec fun return interceptor(ctx, in, info, handler) } -func _Query_GetTwap_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(QueryGetTwapRequest) +func _Query_GetPrice_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryGetPriceRequest) if err := dec(in); err != nil { return nil, err } if interceptor == nil { - return srv.(QueryServer).GetTwap(ctx, in) + return srv.(QueryServer).GetPrice(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/seiprotocol.seichain.dex.Query/GetTwap", + FullMethod: "/seiprotocol.seichain.dex.Query/GetPrice", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(QueryServer).GetTwap(ctx, req.(*QueryGetTwapRequest)) + return srv.(QueryServer).GetPrice(ctx, req.(*QueryGetPriceRequest)) } return interceptor(ctx, in, info, handler) } @@ -1274,8 +1282,8 @@ var _Query_serviceDesc = grpc.ServiceDesc{ Handler: _Query_SettlementsAll_Handler, }, { - MethodName: "GetTwap", - Handler: _Query_GetTwap_Handler, + MethodName: "GetPrice", + Handler: _Query_GetPrice_Handler, }, }, Streams: []grpc.StreamDesc{}, @@ -1862,7 +1870,7 @@ func (m *QueryAllSettlementsResponse) MarshalToSizedBuffer(dAtA []byte) (int, er return len(dAtA) - i, nil } -func (m *QueryGetTwapRequest) Marshal() (dAtA []byte, err error) { +func (m *QueryGetPriceRequest) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -1872,16 +1880,21 @@ func (m *QueryGetTwapRequest) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *QueryGetTwapRequest) MarshalTo(dAtA []byte) (int, error) { +func (m *QueryGetPriceRequest) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *QueryGetTwapRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *QueryGetPriceRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int _ = l + if m.Epoch != 0 { + i = encodeVarintQuery(dAtA, i, uint64(m.Epoch)) + i-- + dAtA[i] = 0x20 + } if len(m.ContractAddr) > 0 { i -= len(m.ContractAddr) copy(dAtA[i:], m.ContractAddr) @@ -1889,20 +1902,24 @@ func (m *QueryGetTwapRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { i-- dAtA[i] = 0x1a } - if m.AssetDenom != 0 { - i = encodeVarintQuery(dAtA, i, uint64(m.AssetDenom)) + if len(m.AssetDenom) > 0 { + i -= len(m.AssetDenom) + copy(dAtA[i:], m.AssetDenom) + i = encodeVarintQuery(dAtA, i, uint64(len(m.AssetDenom))) i-- - dAtA[i] = 0x10 + dAtA[i] = 0x12 } - if m.PriceDenom != 0 { - i = encodeVarintQuery(dAtA, i, uint64(m.PriceDenom)) + if len(m.PriceDenom) > 0 { + i -= len(m.PriceDenom) + copy(dAtA[i:], m.PriceDenom) + i = encodeVarintQuery(dAtA, i, uint64(len(m.PriceDenom))) i-- - dAtA[i] = 0x8 + dAtA[i] = 0xa } return len(dAtA) - i, nil } -func (m *QueryGetTwapResponse) Marshal() (dAtA []byte, err error) { +func (m *QueryGetPriceResponse) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -1912,19 +1929,19 @@ func (m *QueryGetTwapResponse) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *QueryGetTwapResponse) MarshalTo(dAtA []byte) (int, error) { +func (m *QueryGetPriceResponse) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *QueryGetTwapResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *QueryGetPriceResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int _ = l - if m.Twaps != nil { + if m.Price != nil { { - size, err := m.Twaps.MarshalToSizedBuffer(dAtA[:i]) + size, err := m.Price.MarshalToSizedBuffer(dAtA[:i]) if err != nil { return 0, err } @@ -2185,33 +2202,38 @@ func (m *QueryAllSettlementsResponse) Size() (n int) { return n } -func (m *QueryGetTwapRequest) Size() (n int) { +func (m *QueryGetPriceRequest) Size() (n int) { if m == nil { return 0 } var l int _ = l - if m.PriceDenom != 0 { - n += 1 + sovQuery(uint64(m.PriceDenom)) + l = len(m.PriceDenom) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) } - if m.AssetDenom != 0 { - n += 1 + sovQuery(uint64(m.AssetDenom)) + l = len(m.AssetDenom) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) } l = len(m.ContractAddr) if l > 0 { n += 1 + l + sovQuery(uint64(l)) } + if m.Epoch != 0 { + n += 1 + sovQuery(uint64(m.Epoch)) + } return n } -func (m *QueryGetTwapResponse) Size() (n int) { +func (m *QueryGetPriceResponse) Size() (n int) { if m == nil { return 0 } var l int _ = l - if m.Twaps != nil { - l = m.Twaps.Size() + if m.Price != nil { + l = m.Price.Size() n += 1 + l + sovQuery(uint64(l)) } return n @@ -3806,7 +3828,7 @@ func (m *QueryAllSettlementsResponse) Unmarshal(dAtA []byte) error { } return nil } -func (m *QueryGetTwapRequest) Unmarshal(dAtA []byte) error { +func (m *QueryGetPriceRequest) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -3829,17 +3851,17 @@ func (m *QueryGetTwapRequest) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: QueryGetTwapRequest: wiretype end group for non-group") + return fmt.Errorf("proto: QueryGetPriceRequest: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: QueryGetTwapRequest: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: QueryGetPriceRequest: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: - if wireType != 0 { + if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field PriceDenom", wireType) } - m.PriceDenom = 0 + var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowQuery @@ -3849,16 +3871,29 @@ func (m *QueryGetTwapRequest) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.PriceDenom |= Denom(b&0x7F) << shift + stringLen |= uint64(b&0x7F) << shift if b < 0x80 { break } } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.PriceDenom = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex case 2: - if wireType != 0 { + if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field AssetDenom", wireType) } - m.AssetDenom = 0 + var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowQuery @@ -3868,11 +3903,24 @@ func (m *QueryGetTwapRequest) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.AssetDenom |= Denom(b&0x7F) << shift + stringLen |= uint64(b&0x7F) << shift if b < 0x80 { break } } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.AssetDenom = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex case 3: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field ContractAddr", wireType) @@ -3905,6 +3953,25 @@ func (m *QueryGetTwapRequest) Unmarshal(dAtA []byte) error { } m.ContractAddr = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex + case 4: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Epoch", wireType) + } + m.Epoch = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Epoch |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } default: iNdEx = preIndex skippy, err := skipQuery(dAtA[iNdEx:]) @@ -3926,7 +3993,7 @@ func (m *QueryGetTwapRequest) Unmarshal(dAtA []byte) error { } return nil } -func (m *QueryGetTwapResponse) Unmarshal(dAtA []byte) error { +func (m *QueryGetPriceResponse) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -3949,15 +4016,15 @@ func (m *QueryGetTwapResponse) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: QueryGetTwapResponse: wiretype end group for non-group") + return fmt.Errorf("proto: QueryGetPriceResponse: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: QueryGetTwapResponse: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: QueryGetPriceResponse: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Twaps", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Price", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -3984,10 +4051,10 @@ func (m *QueryGetTwapResponse) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if m.Twaps == nil { - m.Twaps = &Twap{} + if m.Price == nil { + m.Price = &Price{} } - if err := m.Twaps.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + if err := m.Price.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex diff --git a/x/dex/types/query.pb.gw.go b/x/dex/types/query.pb.gw.go index 72a078cbd9..613ae97a3f 100644 --- a/x/dex/types/query.pb.gw.go +++ b/x/dex/types/query.pb.gw.go @@ -600,16 +600,15 @@ func local_request_Query_SettlementsAll_0(ctx context.Context, marshaler runtime } var ( - filter_Query_GetTwap_0 = &utilities.DoubleArray{Encoding: map[string]int{"priceDenom": 0, "assetDenom": 1}, Base: []int{1, 1, 2, 0, 0}, Check: []int{0, 1, 1, 2, 3}} + filter_Query_GetPrice_0 = &utilities.DoubleArray{Encoding: map[string]int{"priceDenom": 0, "assetDenom": 1, "epoch": 2}, Base: []int{1, 1, 2, 3, 0, 0, 0}, Check: []int{0, 1, 1, 1, 2, 3, 4}} ) -func request_Query_GetTwap_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq QueryGetTwapRequest +func request_Query_GetPrice_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryGetPriceRequest var metadata runtime.ServerMetadata var ( val string - e int32 ok bool err error _ = err @@ -620,46 +619,52 @@ func request_Query_GetTwap_0(ctx context.Context, marshaler runtime.Marshaler, c return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "priceDenom") } - e, err = runtime.Enum(val, Denom_value) + protoReq.PriceDenom, err = runtime.String(val) if err != nil { return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "priceDenom", err) } - protoReq.PriceDenom = Denom(e) - val, ok = pathParams["assetDenom"] if !ok { return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "assetDenom") } - e, err = runtime.Enum(val, Denom_value) + protoReq.AssetDenom, err = runtime.String(val) if err != nil { return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "assetDenom", err) } - protoReq.AssetDenom = Denom(e) + val, ok = pathParams["epoch"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "epoch") + } + + protoReq.Epoch, err = runtime.Uint64(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "epoch", err) + } if err := req.ParseForm(); err != nil { return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) } - if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_GetTwap_0); err != nil { + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_GetPrice_0); err != nil { return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) } - msg, err := client.GetTwap(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + msg, err := client.GetPrice(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) return msg, metadata, err } -func local_request_Query_GetTwap_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq QueryGetTwapRequest +func local_request_Query_GetPrice_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryGetPriceRequest var metadata runtime.ServerMetadata var ( val string - e int32 ok bool err error _ = err @@ -670,35 +675,42 @@ func local_request_Query_GetTwap_0(ctx context.Context, marshaler runtime.Marsha return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "priceDenom") } - e, err = runtime.Enum(val, Denom_value) + protoReq.PriceDenom, err = runtime.String(val) if err != nil { return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "priceDenom", err) } - protoReq.PriceDenom = Denom(e) - val, ok = pathParams["assetDenom"] if !ok { return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "assetDenom") } - e, err = runtime.Enum(val, Denom_value) + protoReq.AssetDenom, err = runtime.String(val) if err != nil { return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "assetDenom", err) } - protoReq.AssetDenom = Denom(e) + val, ok = pathParams["epoch"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "epoch") + } + + protoReq.Epoch, err = runtime.Uint64(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "epoch", err) + } if err := req.ParseForm(); err != nil { return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) } - if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_GetTwap_0); err != nil { + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_GetPrice_0); err != nil { return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) } - msg, err := server.GetTwap(ctx, &protoReq) + msg, err := server.GetPrice(ctx, &protoReq) return msg, metadata, err } @@ -847,7 +859,7 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv }) - mux.Handle("GET", pattern_Query_GetTwap_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + mux.Handle("GET", pattern_Query_GetPrice_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() var stream runtime.ServerTransportStream @@ -858,7 +870,7 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := local_request_Query_GetTwap_0(rctx, inboundMarshaler, server, req, pathParams) + resp, md, err := local_request_Query_GetPrice_0(rctx, inboundMarshaler, server, req, pathParams) md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { @@ -866,7 +878,7 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv return } - forward_Query_GetTwap_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_Query_GetPrice_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -1031,7 +1043,7 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie }) - mux.Handle("GET", pattern_Query_GetTwap_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + mux.Handle("GET", pattern_Query_GetPrice_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) @@ -1040,14 +1052,14 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := request_Query_GetTwap_0(rctx, inboundMarshaler, client, req, pathParams) + resp, md, err := request_Query_GetPrice_0(rctx, inboundMarshaler, client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - forward_Query_GetTwap_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_Query_GetPrice_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -1067,7 +1079,7 @@ var ( pattern_Query_SettlementsAll_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"sei-protocol", "seichain", "dex", "settlement"}, "", runtime.AssumeColonVerbOpt(true))) - pattern_Query_GetTwap_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4, 1, 0, 4, 1, 5, 5}, []string{"sei-protocol", "seichain", "dex", "get_twap", "priceDenom", "assetDenom"}, "", runtime.AssumeColonVerbOpt(true))) + pattern_Query_GetPrice_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4, 1, 0, 4, 1, 5, 5, 1, 0, 4, 1, 5, 6}, []string{"sei-protocol", "seichain", "dex", "get_price", "priceDenom", "assetDenom", "epoch"}, "", runtime.AssumeColonVerbOpt(true))) ) var ( @@ -1083,5 +1095,5 @@ var ( forward_Query_SettlementsAll_0 = runtime.ForwardResponseMessage - forward_Query_GetTwap_0 = runtime.ForwardResponseMessage + forward_Query_GetPrice_0 = runtime.ForwardResponseMessage ) diff --git a/x/dex/types/twap.pb.go b/x/dex/types/twap.pb.go deleted file mode 100644 index 3e795a0aef..0000000000 --- a/x/dex/types/twap.pb.go +++ /dev/null @@ -1,548 +0,0 @@ -// Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: dex/twap.proto - -package types - -import ( - fmt "fmt" - proto "github.com/gogo/protobuf/proto" - io "io" - math "math" - math_bits "math/bits" -) - -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package - -type Twap struct { - LastEpoch uint64 `protobuf:"varint,1,opt,name=lastEpoch,proto3" json:"lastEpoch,omitempty"` - Prices []uint64 `protobuf:"varint,2,rep,packed,name=prices,proto3" json:"prices,omitempty"` - TwapPrice uint64 `protobuf:"varint,3,opt,name=twapPrice,proto3" json:"twapPrice,omitempty"` - PriceDenom string `protobuf:"bytes,4,opt,name=priceDenom,proto3" json:"priceDenom,omitempty"` - AssetDenom string `protobuf:"bytes,5,opt,name=assetDenom,proto3" json:"assetDenom,omitempty"` -} - -func (m *Twap) Reset() { *m = Twap{} } -func (m *Twap) String() string { return proto.CompactTextString(m) } -func (*Twap) ProtoMessage() {} -func (*Twap) Descriptor() ([]byte, []int) { - return fileDescriptor_10aa4b136085207a, []int{0} -} -func (m *Twap) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *Twap) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_Twap.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 *Twap) XXX_Merge(src proto.Message) { - xxx_messageInfo_Twap.Merge(m, src) -} -func (m *Twap) XXX_Size() int { - return m.Size() -} -func (m *Twap) XXX_DiscardUnknown() { - xxx_messageInfo_Twap.DiscardUnknown(m) -} - -var xxx_messageInfo_Twap proto.InternalMessageInfo - -func (m *Twap) GetLastEpoch() uint64 { - if m != nil { - return m.LastEpoch - } - return 0 -} - -func (m *Twap) GetPrices() []uint64 { - if m != nil { - return m.Prices - } - return nil -} - -func (m *Twap) GetTwapPrice() uint64 { - if m != nil { - return m.TwapPrice - } - return 0 -} - -func (m *Twap) GetPriceDenom() string { - if m != nil { - return m.PriceDenom - } - return "" -} - -func (m *Twap) GetAssetDenom() string { - if m != nil { - return m.AssetDenom - } - return "" -} - -func init() { - proto.RegisterType((*Twap)(nil), "seiprotocol.seichain.dex.Twap") -} - -func init() { proto.RegisterFile("dex/twap.proto", fileDescriptor_10aa4b136085207a) } - -var fileDescriptor_10aa4b136085207a = []byte{ - // 224 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x4b, 0x49, 0xad, 0xd0, - 0x2f, 0x29, 0x4f, 0x2c, 0xd0, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x92, 0x28, 0x4e, 0xcd, 0x04, - 0xb3, 0x92, 0xf3, 0x73, 0xf4, 0x8a, 0x53, 0x33, 0x93, 0x33, 0x12, 0x33, 0xf3, 0xf4, 0x52, 0x52, - 0x2b, 0x94, 0x66, 0x31, 0x72, 0xb1, 0x84, 0x94, 0x27, 0x16, 0x08, 0xc9, 0x70, 0x71, 0xe6, 0x24, - 0x16, 0x97, 0xb8, 0x16, 0xe4, 0x27, 0x67, 0x48, 0x30, 0x2a, 0x30, 0x6a, 0xb0, 0x04, 0x21, 0x04, - 0x84, 0xc4, 0xb8, 0xd8, 0x0a, 0x8a, 0x32, 0x93, 0x53, 0x8b, 0x25, 0x98, 0x14, 0x98, 0x35, 0x58, - 0x82, 0xa0, 0x3c, 0x90, 0x2e, 0x90, 0x35, 0x01, 0x20, 0x9e, 0x04, 0x33, 0x44, 0x17, 0x5c, 0x40, - 0x48, 0x8e, 0x8b, 0x0b, 0xac, 0xce, 0x25, 0x35, 0x2f, 0x3f, 0x57, 0x82, 0x45, 0x81, 0x51, 0x83, - 0x33, 0x08, 0x49, 0x04, 0x24, 0x9f, 0x58, 0x5c, 0x9c, 0x5a, 0x02, 0x91, 0x67, 0x85, 0xc8, 0x23, - 0x44, 0x9c, 0xdc, 0x4f, 0x3c, 0x92, 0x63, 0xbc, 0xf0, 0x48, 0x8e, 0xf1, 0xc1, 0x23, 0x39, 0xc6, - 0x09, 0x8f, 0xe5, 0x18, 0x2e, 0x3c, 0x96, 0x63, 0xb8, 0xf1, 0x58, 0x8e, 0x21, 0x4a, 0x37, 0x3d, - 0xb3, 0x24, 0xa3, 0x34, 0x49, 0x2f, 0x39, 0x3f, 0x57, 0xbf, 0x38, 0x35, 0x53, 0x17, 0xe6, 0x39, - 0x30, 0x07, 0xec, 0x3b, 0xfd, 0x0a, 0x7d, 0x70, 0x20, 0x54, 0x16, 0xa4, 0x16, 0x27, 0xb1, 0x81, - 0xe5, 0x8d, 0x01, 0x01, 0x00, 0x00, 0xff, 0xff, 0x98, 0x40, 0x0f, 0xa7, 0x18, 0x01, 0x00, 0x00, -} - -func (m *Twap) 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 *Twap) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *Twap) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.AssetDenom) > 0 { - i -= len(m.AssetDenom) - copy(dAtA[i:], m.AssetDenom) - i = encodeVarintTwap(dAtA, i, uint64(len(m.AssetDenom))) - i-- - dAtA[i] = 0x2a - } - if len(m.PriceDenom) > 0 { - i -= len(m.PriceDenom) - copy(dAtA[i:], m.PriceDenom) - i = encodeVarintTwap(dAtA, i, uint64(len(m.PriceDenom))) - i-- - dAtA[i] = 0x22 - } - if m.TwapPrice != 0 { - i = encodeVarintTwap(dAtA, i, uint64(m.TwapPrice)) - i-- - dAtA[i] = 0x18 - } - if len(m.Prices) > 0 { - dAtA2 := make([]byte, len(m.Prices)*10) - var j1 int - for _, num := range m.Prices { - for num >= 1<<7 { - dAtA2[j1] = uint8(uint64(num)&0x7f | 0x80) - num >>= 7 - j1++ - } - dAtA2[j1] = uint8(num) - j1++ - } - i -= j1 - copy(dAtA[i:], dAtA2[:j1]) - i = encodeVarintTwap(dAtA, i, uint64(j1)) - i-- - dAtA[i] = 0x12 - } - if m.LastEpoch != 0 { - i = encodeVarintTwap(dAtA, i, uint64(m.LastEpoch)) - i-- - dAtA[i] = 0x8 - } - return len(dAtA) - i, nil -} - -func encodeVarintTwap(dAtA []byte, offset int, v uint64) int { - offset -= sovTwap(v) - base := offset - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return base -} -func (m *Twap) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.LastEpoch != 0 { - n += 1 + sovTwap(uint64(m.LastEpoch)) - } - if len(m.Prices) > 0 { - l = 0 - for _, e := range m.Prices { - l += sovTwap(uint64(e)) - } - n += 1 + sovTwap(uint64(l)) + l - } - if m.TwapPrice != 0 { - n += 1 + sovTwap(uint64(m.TwapPrice)) - } - l = len(m.PriceDenom) - if l > 0 { - n += 1 + l + sovTwap(uint64(l)) - } - l = len(m.AssetDenom) - if l > 0 { - n += 1 + l + sovTwap(uint64(l)) - } - return n -} - -func sovTwap(x uint64) (n int) { - return (math_bits.Len64(x|1) + 6) / 7 -} -func sozTwap(x uint64) (n int) { - return sovTwap(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} -func (m *Twap) 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 ErrIntOverflowTwap - } - 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: Twap: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: Twap: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field LastEpoch", wireType) - } - m.LastEpoch = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTwap - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.LastEpoch |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 2: - if wireType == 0 { - var v uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTwap - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - m.Prices = append(m.Prices, v) - } else if wireType == 2 { - var packedLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTwap - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - packedLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if packedLen < 0 { - return ErrInvalidLengthTwap - } - postIndex := iNdEx + packedLen - if postIndex < 0 { - return ErrInvalidLengthTwap - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - var elementCount int - var count int - for _, integer := range dAtA[iNdEx:postIndex] { - if integer < 128 { - count++ - } - } - elementCount = count - if elementCount != 0 && len(m.Prices) == 0 { - m.Prices = make([]uint64, 0, elementCount) - } - for iNdEx < postIndex { - var v uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTwap - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - m.Prices = append(m.Prices, v) - } - } else { - return fmt.Errorf("proto: wrong wireType = %d for field Prices", wireType) - } - case 3: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field TwapPrice", wireType) - } - m.TwapPrice = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTwap - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.TwapPrice |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 4: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field PriceDenom", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTwap - } - 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 ErrInvalidLengthTwap - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthTwap - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.PriceDenom = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 5: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field AssetDenom", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTwap - } - 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 ErrInvalidLengthTwap - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthTwap - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.AssetDenom = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipTwap(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthTwap - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func skipTwap(dAtA []byte) (n int, err error) { - l := len(dAtA) - iNdEx := 0 - depth := 0 - for iNdEx < l { - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowTwap - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - wireType := int(wire & 0x7) - switch wireType { - case 0: - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowTwap - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - iNdEx++ - if dAtA[iNdEx-1] < 0x80 { - break - } - } - case 1: - iNdEx += 8 - case 2: - var length int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowTwap - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - length |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if length < 0 { - return 0, ErrInvalidLengthTwap - } - iNdEx += length - case 3: - depth++ - case 4: - if depth == 0 { - return 0, ErrUnexpectedEndOfGroupTwap - } - depth-- - case 5: - iNdEx += 4 - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - if iNdEx < 0 { - return 0, ErrInvalidLengthTwap - } - if depth == 0 { - return iNdEx, nil - } - } - return 0, io.ErrUnexpectedEOF -} - -var ( - ErrInvalidLengthTwap = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowTwap = fmt.Errorf("proto: integer overflow") - ErrUnexpectedEndOfGroupTwap = fmt.Errorf("proto: unexpected end of group") -) From 7a64fbefc3166e25de0c7fd6a76984ac3e765401 Mon Sep 17 00:00:00 2001 From: Xiaoyu Chen Date: Sat, 28 May 2022 16:06:04 -0700 Subject: [PATCH 2/5] Integrate oracle V2 with dex --- app/app.go | 2 +- go.mod | 1 - proto/dex/genesis.proto | 5 +- proto/dex/twap.proto | 14 + x/dex/client/cli/query.go | 2 +- x/dex/client/cli/query_get_price.go | 54 +++ x/dex/client/cli/query_get_twap.go | 61 --- x/dex/genesis.go | 6 + x/dex/keeper/grpc_query_get_price.go | 27 ++ x/dex/keeper/grpc_query_get_twap.go | 24 -- x/dex/keeper/price.go | 58 +++ x/dex/keeper/twap.go | 23 +- x/dex/module.go | 119 +++--- x/dex/types/funding_payment_rate.go | 12 - x/dex/types/genesis.pb.go | 109 ++++-- x/dex/types/keys.go | 5 + x/dex/types/price.go | 17 + x/dex/types/twap.pb.go | 549 +++++++++++++++++++++++++++ 18 files changed, 878 insertions(+), 210 deletions(-) create mode 100644 proto/dex/twap.proto create mode 100644 x/dex/client/cli/query_get_price.go delete mode 100644 x/dex/client/cli/query_get_twap.go create mode 100644 x/dex/keeper/grpc_query_get_price.go delete mode 100644 x/dex/keeper/grpc_query_get_twap.go create mode 100644 x/dex/keeper/price.go delete mode 100644 x/dex/types/funding_payment_rate.go create mode 100644 x/dex/types/price.go create mode 100644 x/dex/types/twap.pb.go diff --git a/app/app.go b/app/app.go index ebcb04bd3b..5a60d5d615 100644 --- a/app/app.go +++ b/app/app.go @@ -490,7 +490,7 @@ func New( app.BankKeeper, app.WasmKeeper, ) - dexModule := dexmodule.NewAppModule(appCodec, app.DexKeeper, app.AccountKeeper, app.BankKeeper, app.WasmKeeper, app.tracingInfo) + dexModule := dexmodule.NewAppModule(appCodec, app.DexKeeper, app.AccountKeeper, app.BankKeeper, app.WasmKeeper, app.OracleKeeper, app.tracingInfo) epochModule := epochmodule.NewAppModule(appCodec, app.EpochKeeper, app.AccountKeeper, app.BankKeeper) // this line is used by starport scaffolding # stargate/app/keeperDefinition diff --git a/go.mod b/go.mod index c88a7184d5..e5bb1ab4ae 100644 --- a/go.mod +++ b/go.mod @@ -31,7 +31,6 @@ require ( github.com/99designs/keyring v1.1.6 // indirect github.com/ChainSafe/go-schnorrkel v0.0.0-20200405005733-88cbf1b4c40d // indirect github.com/CosmWasm/wasmvm v1.0.0 // indirect - github.com/DataDog/zstd v1.4.5 // indirect github.com/Workiva/go-datastructures v1.0.53 // indirect github.com/armon/go-metrics v0.3.10 // indirect github.com/beorn7/perks v1.0.1 // indirect diff --git a/proto/dex/genesis.proto b/proto/dex/genesis.proto index 4864dd1948..d4a1866125 100644 --- a/proto/dex/genesis.proto +++ b/proto/dex/genesis.proto @@ -5,7 +5,7 @@ import "gogoproto/gogo.proto"; import "dex/params.proto"; import "dex/long_book.proto"; import "dex/short_book.proto"; -import "dex/price.proto"; +import "dex/twap.proto"; // this line is used by starport scaffolding # genesis/proto/import option go_package = "github.com/sei-protocol/sei-chain/x/dex/types"; @@ -15,6 +15,7 @@ message GenesisState { Params params = 1 [(gogoproto.nullable) = false]; repeated LongBook longBookList = 2 [(gogoproto.nullable) = false]; repeated ShortBook shortBookList = 3 [(gogoproto.nullable) = false]; - uint64 lastEpoch = 4; + repeated Twap twapList = 4; + uint64 lastEpoch = 5; // this line is used by starport scaffolding # genesis/proto/state } diff --git a/proto/dex/twap.proto b/proto/dex/twap.proto new file mode 100644 index 0000000000..a90df8bfba --- /dev/null +++ b/proto/dex/twap.proto @@ -0,0 +1,14 @@ +syntax = "proto3"; +package seiprotocol.seichain.dex; + +option go_package = "github.com/sei-protocol/sei-chain/x/dex/types"; + +// deprecated +message Twap { + + uint64 lastEpoch = 1; + repeated uint64 prices = 2; + uint64 twapPrice = 3; + string priceDenom = 4; + string assetDenom = 5; +} diff --git a/x/dex/client/cli/query.go b/x/dex/client/cli/query.go index d942f7c175..eb73d6b2df 100644 --- a/x/dex/client/cli/query.go +++ b/x/dex/client/cli/query.go @@ -29,7 +29,7 @@ func GetQueryCmd(queryRoute string) *cobra.Command { cmd.AddCommand(CmdShowLongBook()) cmd.AddCommand(CmdListShortBook()) cmd.AddCommand(CmdShowShortBook()) - cmd.AddCommand(CmdGetTwap()) + cmd.AddCommand(CmdGetPrice()) // this line is used by starport scaffolding # 1 diff --git a/x/dex/client/cli/query_get_price.go b/x/dex/client/cli/query_get_price.go new file mode 100644 index 0000000000..62f24e6754 --- /dev/null +++ b/x/dex/client/cli/query_get_price.go @@ -0,0 +1,54 @@ +package cli + +import ( + "strconv" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/sei-protocol/sei-chain/x/dex/types" + "github.com/spf13/cobra" +) + +var _ = strconv.Itoa(0) + +func CmdGetPrice() *cobra.Command { + cmd := &cobra.Command{ + Use: "get-price [contract-address] [epoch] [price-denom] [asset-denom]", + Short: "Query getPrice", + Args: cobra.ExactArgs(4), + RunE: func(cmd *cobra.Command, args []string) (err error) { + reqContractAddr := args[0] + reqEpoch, err := strconv.ParseUint(args[1], 10, 64) + if err != nil { + return err + } + reqPriceDenom := args[2] + reqAssetDenom := args[3] + + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + queryClient := types.NewQueryClient(clientCtx) + + params := &types.QueryGetPriceRequest{ + ContractAddr: reqContractAddr, + Epoch: reqEpoch, + PriceDenom: reqPriceDenom, + AssetDenom: reqAssetDenom, + } + + res, err := queryClient.GetPrice(cmd.Context(), params) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd +} diff --git a/x/dex/client/cli/query_get_twap.go b/x/dex/client/cli/query_get_twap.go deleted file mode 100644 index 42426e01c8..0000000000 --- a/x/dex/client/cli/query_get_twap.go +++ /dev/null @@ -1,61 +0,0 @@ -package cli - -import ( - "errors" - "strconv" - - "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/client/flags" - "github.com/sei-protocol/sei-chain/x/dex/types" - "github.com/spf13/cobra" -) - -var _ = strconv.Itoa(0) - -func CmdGetTwap() *cobra.Command { - cmd := &cobra.Command{ - Use: "get-twap [price-denom] [asset-denom]", - Short: "Query getTwap", - Args: cobra.ExactArgs(2), - RunE: func(cmd *cobra.Command, args []string) (err error) { - reqPriceDenom, unit, err := types.GetDenomFromStr(args[0]) - if err != nil { - return err - } - if unit != types.Unit_STANDARD { - return errors.New("Denom must be in standard/whole unit (e.g. sei instead of usei)") - } - - reqAssetDenom, unit, err := types.GetDenomFromStr(args[1]) - if err != nil { - return err - } - if unit != types.Unit_STANDARD { - return errors.New("Denom must be in standard/whole unit (e.g. sei instead of usei)") - } - - clientCtx, err := client.GetClientTxContext(cmd) - if err != nil { - return err - } - - queryClient := types.NewQueryClient(clientCtx) - - params := &types.QueryGetTwapRequest{ - PriceDenom: reqPriceDenom, - AssetDenom: reqAssetDenom, - } - - res, err := queryClient.GetTwap(cmd.Context(), params) - if err != nil { - return err - } - - return clientCtx.PrintProto(res) - }, - } - - flags.AddQueryFlagsToCmd(cmd) - - return cmd -} diff --git a/x/dex/genesis.go b/x/dex/genesis.go index 87a974b899..ac47abe982 100644 --- a/x/dex/genesis.go +++ b/x/dex/genesis.go @@ -22,6 +22,12 @@ func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState) // this line is used by starport scaffolding # genesis/module/init k.SetParams(ctx, genState.Params) + for _, twap := range genState.TwapList { + twap.LastEpoch = 0 + twap.TwapPrice = twap.Prices[0] + k.SetTwap(ctx, *twap, "genesis") + } + k.SetEpoch(ctx, genState.LastEpoch) } diff --git a/x/dex/keeper/grpc_query_get_price.go b/x/dex/keeper/grpc_query_get_price.go new file mode 100644 index 0000000000..6ba1a2b37b --- /dev/null +++ b/x/dex/keeper/grpc_query_get_price.go @@ -0,0 +1,27 @@ +package keeper + +import ( + "context" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/sei-protocol/sei-chain/x/dex/types" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" +) + +func (k Keeper) GetPrice(goCtx context.Context, req *types.QueryGetPriceRequest) (*types.QueryGetPriceResponse, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + + ctx := sdk.UnwrapSDKContext(goCtx) + + price, exist := k.GetPriceState(ctx, req.ContractAddr, req.Epoch, req.PriceDenom, req.AssetDenom) + if !exist { + return nil, status.Error(codes.NotFound, "not found") + } + + return &types.QueryGetPriceResponse{ + Price: &price, + }, nil +} diff --git a/x/dex/keeper/grpc_query_get_twap.go b/x/dex/keeper/grpc_query_get_twap.go deleted file mode 100644 index d413007b4b..0000000000 --- a/x/dex/keeper/grpc_query_get_twap.go +++ /dev/null @@ -1,24 +0,0 @@ -package keeper - -import ( - "context" - - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/sei-protocol/sei-chain/x/dex/types" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/status" -) - -func (k Keeper) GetTwap(goCtx context.Context, req *types.QueryGetTwapRequest) (*types.QueryGetTwapResponse, error) { - if req == nil { - return nil, status.Error(codes.InvalidArgument, "invalid request") - } - - ctx := sdk.UnwrapSDKContext(goCtx) - - twap := k.GetTwapState(ctx, req.ContractAddr, req.PriceDenom, req.AssetDenom) - - return &types.QueryGetTwapResponse{ - Twaps: &twap, - }, nil -} diff --git a/x/dex/keeper/price.go b/x/dex/keeper/price.go new file mode 100644 index 0000000000..453b7360c1 --- /dev/null +++ b/x/dex/keeper/price.go @@ -0,0 +1,58 @@ +package keeper + +import ( + "encoding/binary" + + "github.com/cosmos/cosmos-sdk/store/prefix" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/sei-protocol/sei-chain/x/dex/types" +) + +func (k Keeper) SetPriceState(ctx sdk.Context, price types.Price, contractAddr string) { + store := prefix.NewStore(ctx.KVStore(k.storeKey), types.PricePrefix(contractAddr)) + b := k.cdc.MustMarshal(&price) + store.Set(GetKeyForPriceState(price.Epoch, price.PriceDenom, price.AssetDenom), b) +} + +func (k Keeper) GetPriceState(ctx sdk.Context, contractAddr string, epoch uint64, priceDenom string, assetDenom string) (types.Price, bool) { + store := prefix.NewStore(ctx.KVStore(k.storeKey), types.PricePrefix(contractAddr)) + res := types.Price{} + key := GetKeyForPriceState(epoch, priceDenom, assetDenom) + if !store.Has(key) { + res.Epoch = epoch + res.PriceDenom = priceDenom + res.AssetDenom = assetDenom + return res, false + } + b := store.Get(key) + k.cdc.MustUnmarshal(b, &res) + return res, true +} + +func (k Keeper) GetAllPrices(ctx sdk.Context, contractAddr string, epoch uint64) (list []types.Price) { + store := prefix.NewStore(ctx.KVStore(k.storeKey), types.PricePrefix(contractAddr)) + iterator := sdk.KVStorePrefixIterator(store, GetKeyForEpoch(epoch)) + + defer iterator.Close() + + for ; iterator.Valid(); iterator.Next() { + var val types.Price + k.cdc.MustUnmarshal(iterator.Value(), &val) + list = append(list, val) + } + + return +} + +func GetKeyForEpoch(epoch uint64) []byte { + epochKey := make([]byte, 8) + binary.BigEndian.PutUint64(epochKey, epoch) + return epochKey +} + +func GetKeyForPriceState(epoch uint64, priceDenom string, assetDenom string) []byte { + return append( + GetKeyForEpoch(epoch), + append([]byte(priceDenom), []byte(assetDenom)...)..., + ) +} diff --git a/x/dex/keeper/twap.go b/x/dex/keeper/twap.go index 8a67022fc0..1842bc7b88 100644 --- a/x/dex/keeper/twap.go +++ b/x/dex/keeper/twap.go @@ -20,25 +20,6 @@ func (k Keeper) SetTwap(ctx sdk.Context, twap types.Twap, contractAddr string) { store.Set(types.PairPrefix(priceDenom, assetDenom), b) } -func (k Keeper) GetTwapState(ctx sdk.Context, contractAddr string, priceDenom types.Denom, assetDenom types.Denom) types.Twap { - store := prefix.NewStore(ctx.KVStore(k.storeKey), types.TwapPrefix(contractAddr)) - b := store.Get(types.PairPrefix(priceDenom, assetDenom)) - res := types.Twap{} - k.Cdc.MustUnmarshal(b, &res) - return res -} - -func (k Keeper) GetAllTwaps(ctx sdk.Context, contractAddr string) (list []types.Twap) { - store := prefix.NewStore(ctx.KVStore(k.storeKey), types.TwapPrefix(contractAddr)) - iterator := sdk.KVStorePrefixIterator(store, []byte{}) - - defer iterator.Close() - - for ; iterator.Valid(); iterator.Next() { - var val types.Twap - k.Cdc.MustUnmarshal(iterator.Value(), &val) - list = append(list, val) - } - - return +func GetKeyForTwap(priceDenom string, assetDenom string) []byte { + return append([]byte(priceDenom), []byte(assetDenom)...) } diff --git a/x/dex/module.go b/x/dex/module.go index c8538a0fe4..ef2edc17e3 100644 --- a/x/dex/module.go +++ b/x/dex/module.go @@ -26,6 +26,7 @@ import ( "github.com/sei-protocol/sei-chain/x/dex/keeper" "github.com/sei-protocol/sei-chain/x/dex/migrations" "github.com/sei-protocol/sei-chain/x/dex/types" + oraclekeeper "github.com/sei-protocol/sei-chain/x/oracle/keeper" ) var ( @@ -109,6 +110,7 @@ type AppModule struct { accountKeeper types.AccountKeeper bankKeeper types.BankKeeper wasmKeeper wasm.Keeper + oracleKeeper oraclekeeper.Keeper tracingInfo *tracing.TracingInfo } @@ -119,6 +121,7 @@ func NewAppModule( accountKeeper types.AccountKeeper, bankKeeper types.BankKeeper, wasmKeeper wasm.Keeper, + oracleKeeper oraclekeeper.Keeper, tracingInfo *tracing.TracingInfo, ) AppModule { return AppModule{ @@ -127,6 +130,7 @@ func NewAppModule( accountKeeper: accountKeeper, bankKeeper: bankKeeper, wasmKeeper: wasmKeeper, + oracleKeeper: oracleKeeper, tracingInfo: tracingInfo, } } @@ -207,6 +211,9 @@ func (am AppModule) BeginBlock(ctx sdk.Context, _ abci.RequestBeginBlock) { for _, contractAddr := range am.getAllContractAddresses(ctx) { am.beginBlockForContract(ctx, contractAddr) } + if isNewEpoch, currentEpoch := am.keeper.IsNewEpoch(ctx); isNewEpoch { + am.keeper.SetEpoch(ctx, currentEpoch) + } } func (am AppModule) beginBlockForContract(ctx sdk.Context, contractAddr string) { @@ -228,51 +235,52 @@ func (am AppModule) beginBlockForContract(ctx sdk.Context, contractAddr string) ctx.Logger().Info(fmt.Sprintf("Orders %s, %s", am.keeper.Orders, contractAddr)) if isNewEpoch, currentEpoch := am.keeper.IsNewEpoch(ctx); isNewEpoch { - ctx.Logger().Info(fmt.Sprintf("Updating funding payment rate for epoch %d", currentEpoch)) - for _, twap := range am.keeper.GetAllTwaps(ctx, contractAddr) { - dexPrice := twap.TwapPrice - ctx.Logger().Info(fmt.Sprintf("%s/%s: %d", twap.PriceDenom, twap.AssetDenom, dexPrice)) - oraclePrice := uint64(100) // TODO: replace with oracle call - var diff uint64 - var negative bool - if dexPrice < oraclePrice { - diff = oraclePrice - dexPrice - negative = true - } else { - diff = dexPrice - oraclePrice - negative = false - } - nativeSetFPRMsg := types.SudoSetFundingPaymentRateMsg{ - SetFundingPaymentRate: types.SetFundingPaymentRate{ - Epoch: currentEpoch, - AssetDenom: twap.AssetDenom, - PriceDiff: strconv.FormatUint(diff, 10), - Negative: negative, - }, + ctx.Logger().Info(fmt.Sprintf("Updating price for epoch %d", currentEpoch)) + setPrices := []types.SetPrice{} + for _, pair := range am.keeper.GetAllRegisteredPairs(ctx, contractAddr) { + lastEpochPrice, exist := am.keeper.GetPriceState(ctx, contractAddr, currentEpoch-1, pair.PriceDenom, pair.AssetDenom) + if exist { + setPrices = append(setPrices, types.SetPrice{ + Epoch: currentEpoch - 1, + PriceDenom: pair.PriceDenom, + AssetDenom: pair.AssetDenom, + ExchangePrice: strconv.FormatUint(lastEpochPrice.ExchangePrice, 10), + OraclePrice: strconv.FormatUint(lastEpochPrice.OraclePrice, 10), + }) } - wasmMsg, err := json.Marshal(nativeSetFPRMsg) - if err != nil { - ctx.Logger().Info(err.Error()) + newEpochPrice := types.Price{ + Epoch: currentEpoch, + PriceDenom: pair.PriceDenom, + AssetDenom: pair.AssetDenom, + ExchangePrice: lastEpochPrice.ExchangePrice, + OraclePrice: lastEpochPrice.OraclePrice, } + am.keeper.SetPriceState(ctx, newEpochPrice, contractAddr) + } + nativeSetFPRMsg := types.SudoSetPricesMsg{ + SetPrices: types.SetPrices{ + Prices: setPrices, + }, + } + wasmMsg, err := json.Marshal(nativeSetFPRMsg) + if err != nil { + ctx.Logger().Info(err.Error()) + } - ctx.Logger().Info("Setting funding payment rate") - am.callClearingHouseContractSudo(ctx, wasmMsg, contractAddr) - - var newPrices []uint64 - if len(twap.Prices) == 24 { // replace with config - newPrices = append(twap.Prices[1:], twap.Prices[len(twap.Prices)-1]) + am.callClearingHouseContractSudo(ctx, wasmMsg, contractAddr) + } else { + for _, pair := range am.keeper.GetAllRegisteredPairs(ctx, contractAddr) { + lastEpochPrice, _ := am.keeper.GetPriceState(ctx, contractAddr, currentEpoch, pair.PriceDenom, pair.AssetDenom) + oraclePriceDenom1, error1 := am.oracleKeeper.GetBaseExchangeRate(ctx, pair.PriceDenom) + oraclePriceDenom2, error2 := am.oracleKeeper.GetBaseExchangeRate(ctx, pair.AssetDenom) + if error1 == nil && error2 == nil { + lastEpochPrice.OraclePrice = oraclePriceDenom2.Quo(oraclePriceDenom1).TruncateInt().Uint64() } else { - newPrices = append(twap.Prices, twap.Prices[len(twap.Prices)-1]) + // if oracle price is not set, use exchange price as oracle price + lastEpochPrice.OraclePrice = lastEpochPrice.ExchangePrice } - am.keeper.SetTwap(ctx, types.Twap{ - LastEpoch: currentEpoch, - Prices: newPrices, - TwapPrice: getTwapPrice(newPrices), - PriceDenom: twap.PriceDenom, - AssetDenom: twap.AssetDenom, - }, contractAddr) + am.keeper.SetPriceState(ctx, lastEpochPrice, contractAddr) } - am.keeper.SetEpoch(ctx, currentEpoch) } } @@ -292,9 +300,11 @@ func (am AppModule) endBlockForContract(ctx sdk.Context, contractAddr string) { defer span.End() registeredPairs := am.keeper.GetAllRegisteredPairs(ctx, contractAddr) - am.keeper.HandleEBLiquidation(spanCtx, ctx, am.tracingInfo.Tracer, contractAddr, registeredPairs) - am.keeper.HandleEBCancelOrders(spanCtx, ctx, am.tracingInfo.Tracer, contractAddr, registeredPairs) - am.keeper.HandleEBPlaceOrders(spanCtx, ctx, am.tracingInfo.Tracer, contractAddr, registeredPairs) + _, currentEpoch := am.keeper.IsNewEpoch(ctx) + + am.keeper.HandleEBLiquidation(spanCtx, ctx, am.tracingInfo.Tracer, contractAddr) + am.keeper.HandleEBCancelOrders(spanCtx, ctx, am.tracingInfo.Tracer, contractAddr) + am.keeper.HandleEBPlaceOrders(spanCtx, ctx, am.tracingInfo.Tracer, contractAddr) am.keeper.OrderCancellations[contractAddr] = map[string]*dexcache.OrderCancellations{} for _, pair := range registeredPairs { @@ -348,20 +358,9 @@ func (am AppModule) endBlockForContract(ctx sdk.Context, contractAddr string) { avgPrice = sdk.ZeroDec() } else { avgPrice = (marketBuyTotalPrice.Add(marketSellTotalPrice).Add(limitTotalPrice)).Quo(marketBuyTotalQuantity.Add(marketSellTotalQuantity).Add(limitTotalQuantity)) - twap := am.keeper.GetTwapState(ctx, contractAddr, pair.PriceDenom, pair.AssetDenom) - newPrices := twap.Prices - if len(newPrices) == 0 { - newPrices = []uint64{avgPrice.BigInt().Uint64()} - } else { - newPrices[len(newPrices)-1] = avgPrice.BigInt().Uint64() - } - am.keeper.SetTwap(ctx, types.Twap{ - LastEpoch: am.keeper.EpochKeeper.GetEpoch(ctx).CurrentEpoch, - Prices: newPrices, - TwapPrice: getTwapPrice(newPrices), - PriceDenom: pair.PriceDenom.String(), - AssetDenom: pair.AssetDenom.String(), - }, contractAddr) + priceState, _ := am.keeper.GetPriceState(ctx, contractAddr, currentEpoch, pair.PriceDenom, pair.AssetDenom) + priceState.ExchangePrice = avgPrice + am.keeper.SetPriceState(ctx, priceState, contractAddr) } ctx.Logger().Info(fmt.Sprintf("Average price for %s/%s: %d", pair.PriceDenom, pair.AssetDenom, avgPrice)) for _, buy := range allExistingBuys { @@ -455,11 +454,3 @@ func (am AppModule) endBlockForContract(ctx sdk.Context, contractAddr string) { // Cancel unfilled market orders am.keeper.HandleEBCancelOrders(spanCtx, ctx, am.tracingInfo.Tracer, contractAddr, registeredPairs) } - -func getTwapPrice(prices []uint64) uint64 { - var total uint64 = 0 - for _, price := range prices { - total += price - } - return total / uint64(len(prices)) -} diff --git a/x/dex/types/funding_payment_rate.go b/x/dex/types/funding_payment_rate.go deleted file mode 100644 index 3ee18ebc38..0000000000 --- a/x/dex/types/funding_payment_rate.go +++ /dev/null @@ -1,12 +0,0 @@ -package types - -type SudoSetFundingPaymentRateMsg struct { - SetFundingPaymentRate SetFundingPaymentRate `json:"set_funding_payment_rate"` -} - -type SetFundingPaymentRate struct { - Epoch uint64 `json:"epoch"` - AssetDenom string `json:"asset_denom"` - PriceDiff string `json:"price_diff"` - Negative bool `json:"negative"` -} diff --git a/x/dex/types/genesis.pb.go b/x/dex/types/genesis.pb.go index 9667c60a44..0a94c875c2 100644 --- a/x/dex/types/genesis.pb.go +++ b/x/dex/types/genesis.pb.go @@ -28,7 +28,8 @@ type GenesisState struct { Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` LongBookList []LongBook `protobuf:"bytes,2,rep,name=longBookList,proto3" json:"longBookList"` ShortBookList []ShortBook `protobuf:"bytes,3,rep,name=shortBookList,proto3" json:"shortBookList"` - LastEpoch uint64 `protobuf:"varint,4,opt,name=lastEpoch,proto3" json:"lastEpoch,omitempty"` + TwapList []*Twap `protobuf:"bytes,4,rep,name=twapList,proto3" json:"twapList,omitempty"` + LastEpoch uint64 `protobuf:"varint,5,opt,name=lastEpoch,proto3" json:"lastEpoch,omitempty"` } func (m *GenesisState) Reset() { *m = GenesisState{} } @@ -85,6 +86,13 @@ func (m *GenesisState) GetShortBookList() []ShortBook { return nil } +func (m *GenesisState) GetTwapList() []*Twap { + if m != nil { + return m.TwapList + } + return nil +} + func (m *GenesisState) GetLastEpoch() uint64 { if m != nil { return m.LastEpoch @@ -99,27 +107,28 @@ func init() { func init() { proto.RegisterFile("dex/genesis.proto", fileDescriptor_a803aaabd08db59d) } var fileDescriptor_a803aaabd08db59d = []byte{ - // 309 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x90, 0xb1, 0x4e, 0xf3, 0x30, - 0x14, 0x85, 0xe3, 0xb6, 0xaa, 0xf4, 0xbb, 0xfd, 0x05, 0x84, 0x0e, 0x51, 0x85, 0x4c, 0x54, 0x96, - 0x2e, 0x75, 0xa4, 0xb2, 0x33, 0x54, 0x42, 0x5d, 0x22, 0x81, 0xda, 0x8d, 0x05, 0x25, 0xa9, 0x95, - 0x58, 0x4d, 0x73, 0xa3, 0xd8, 0x48, 0xe1, 0x19, 0x58, 0x78, 0xac, 0x8e, 0x1d, 0x99, 0x10, 0x4a, - 0x5e, 0x04, 0xd9, 0x71, 0x81, 0x0e, 0xd9, 0x6e, 0xce, 0x3d, 0xe7, 0xbb, 0x27, 0xc6, 0x17, 0x1b, - 0x56, 0x7a, 0x31, 0xcb, 0x98, 0xe0, 0x82, 0xe6, 0x05, 0x48, 0xb0, 0x1d, 0xc1, 0xb8, 0x9e, 0x22, - 0x48, 0xa9,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, 0x3f, 0xf4, 0x75, 0xaf, 0xf4, 0xd4, 0xe3, 0xca, - 0xd7, 0x9c, 0x89, 0xb0, 0xaf, 0xf7, 0xb7, 0xdf, 0x01, 0x00, 0x00, 0xff, 0xff, 0x7f, 0xfd, 0x77, - 0x48, 0xf0, 0x01, 0x00, 0x00, + // 326 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x91, 0xcf, 0x4e, 0x02, 0x31, + 0x10, 0xc6, 0x77, 0x01, 0x89, 0x16, 0x34, 0x5a, 0x39, 0x6c, 0x88, 0xa9, 0x1b, 0xbc, 0x70, 0xa1, + 0x9b, 0xe0, 0xcd, 0x83, 0x07, 0x12, 0xc3, 0x85, 0x44, 0x03, 0x9e, 0xbc, 0x98, 0xb2, 0x34, 0xbb, + 0x0d, 0x7f, 0xa6, 0xa1, 0x35, 0xe0, 0x5b, 0xf8, 0x56, 0x72, 0xe4, 0xe8, 0xc9, 0x18, 0x78, 0x11, + 0xd3, 0x6e, 0x41, 0x39, 0xec, 0xad, 0xf3, 0xcd, 0x37, 0xbf, 0xf9, 0x26, 0x45, 0x17, 0x23, 0xbe, + 0x8c, 0x12, 0x3e, 0xe3, 0x4a, 0x28, 0x2a, 0xe7, 0xa0, 0x01, 0x07, 0x8a, 0x0b, 0xfb, 0x8a, 0x61, + 0x42, 0x15, 0x17, 0x71, 0xca, 0xc4, 0x8c, 0x8e, 0xf8, 0xb2, 0x5e, 0x4b, 0x20, 0x01, 0xdb, 0x8a, + 0xcc, 0x2b, 0xf3, 0xd7, 0xcf, 0x0d, 0x42, 0xb2, 0x39, 0x9b, 0x3a, 0x42, 0xfd, 0xd2, 0x28, 0x13, + 0x98, 0x25, 0xaf, 0x43, 0x80, 0xb1, 0x13, 0x6b, 0x46, 0x54, 0x29, 0xcc, 0xf5, 0x7f, 0xf5, 0xcc, + 0xa8, 0x7a, 0xc1, 0x64, 0x56, 0x37, 0x3e, 0x0b, 0xa8, 0xda, 0xcd, 0xe2, 0x0c, 0x34, 0xd3, 0x1c, + 0xdf, 0xa3, 0x72, 0xc6, 0x0e, 0xfc, 0xd0, 0x6f, 0x56, 0xda, 0x21, 0xcd, 0x8b, 0x47, 0x9f, 0xac, + 0xaf, 0x53, 0x5a, 0x7d, 0x5f, 0x7b, 0x7d, 0x37, 0x85, 0x7b, 0xa8, 0x6a, 0x92, 0x74, 0x00, 0xc6, + 0x3d, 0xa1, 0x74, 0x50, 0x08, 0x8b, 0xcd, 0x4a, 0xbb, 0x91, 0x4f, 0xe9, 0x39, 0xb7, 0xe3, 0x1c, + 0x4c, 0xe3, 0x47, 0x74, 0x6a, 0x4f, 0xd8, 0xe3, 0x8a, 0x16, 0x77, 0x93, 0x8f, 0x1b, 0xec, 0xec, + 0x8e, 0x77, 0x38, 0x8f, 0xef, 0xd0, 0xb1, 0xb9, 0xde, 0xb2, 0x4a, 0x96, 0x45, 0xf2, 0x59, 0xcf, + 0x0b, 0x26, 0xfb, 0x7b, 0x3f, 0xbe, 0x42, 0x27, 0x13, 0xa6, 0xf4, 0x83, 0x84, 0x38, 0x0d, 0x8e, + 0x42, 0xbf, 0x59, 0xea, 0xff, 0x09, 0x9d, 0xee, 0x6a, 0x43, 0xfc, 0xf5, 0x86, 0xf8, 0x3f, 0x1b, + 0xe2, 0x7f, 0x6c, 0x89, 0xb7, 0xde, 0x12, 0xef, 0x6b, 0x4b, 0xbc, 0x97, 0x56, 0x22, 0x74, 0xfa, + 0x36, 0xa4, 0x31, 0x4c, 0x23, 0xc5, 0x45, 0x6b, 0xb7, 0xcc, 0x16, 0x76, 0x5b, 0xb4, 0x8c, 0xec, + 0xbf, 0xbc, 0x4b, 0xae, 0x86, 0x65, 0xdb, 0xbf, 0xfd, 0x0d, 0x00, 0x00, 0xff, 0xff, 0x87, 0x21, + 0x64, 0x44, 0x2b, 0x02, 0x00, 0x00, } func (m *GenesisState) Marshal() (dAtA []byte, err error) { @@ -145,7 +154,21 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { if m.LastEpoch != 0 { i = encodeVarintGenesis(dAtA, i, uint64(m.LastEpoch)) i-- - dAtA[i] = 0x20 + dAtA[i] = 0x28 + } + if len(m.TwapList) > 0 { + for iNdEx := len(m.TwapList) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.TwapList[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x22 + } } if len(m.ShortBookList) > 0 { for iNdEx := len(m.ShortBookList) - 1; iNdEx >= 0; iNdEx-- { @@ -219,6 +242,12 @@ func (m *GenesisState) Size() (n int) { n += 1 + l + sovGenesis(uint64(l)) } } + if len(m.TwapList) > 0 { + for _, e := range m.TwapList { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } if m.LastEpoch != 0 { n += 1 + sovGenesis(uint64(m.LastEpoch)) } @@ -362,6 +391,40 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { } iNdEx = postIndex case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field TwapList", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.TwapList = append(m.TwapList, &Twap{}) + if err := m.TwapList[len(m.TwapList)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 5: if wireType != 0 { return fmt.Errorf("proto: wrong wireType = %d for field LastEpoch", wireType) } diff --git a/x/dex/types/keys.go b/x/dex/types/keys.go index 1a51e497c0..8ad25db6da 100644 --- a/x/dex/types/keys.go +++ b/x/dex/types/keys.go @@ -52,6 +52,10 @@ func TwapPrefix(contractAddr string) []byte { return append(KeyPrefix(TwapKey), KeyPrefix(contractAddr)...) } +func PricePrefix(contractAddr string) []byte { + return append(KeyPrefix(PriceKey), KeyPrefix(contractAddr)...) +} + func SettlementEntryPrefix(contractAddr string, blockHeight uint64) []byte { return append( append(KeyPrefix(SettlementEntryKey), KeyPrefix(contractAddr)...), @@ -89,6 +93,7 @@ const ( ) const TwapKey = "TWAP-" +const PriceKey = "Price-" const SettlementEntryKey = "SettlementEntry-" diff --git a/x/dex/types/price.go b/x/dex/types/price.go new file mode 100644 index 0000000000..e95760d42a --- /dev/null +++ b/x/dex/types/price.go @@ -0,0 +1,17 @@ +package types + +type SudoSetPricesMsg struct { + SetPrices SetPrices `json:"set_prices"` +} + +type SetPrices struct { + Prices []SetPrice `json:"prices"` +} + +type SetPrice struct { + Epoch uint64 `json:"epoch"` + PriceDenom string `json:"price_denom"` + AssetDenom string `json:"asset_denom"` + ExchangePrice string `json:"exchange_price"` + OraclePrice string `json:"oracle_price"` +} diff --git a/x/dex/types/twap.pb.go b/x/dex/types/twap.pb.go new file mode 100644 index 0000000000..699fe0d6b3 --- /dev/null +++ b/x/dex/types/twap.pb.go @@ -0,0 +1,549 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: dex/twap.proto + +package types + +import ( + fmt "fmt" + proto "github.com/gogo/protobuf/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// deprecated +type Twap struct { + LastEpoch uint64 `protobuf:"varint,1,opt,name=lastEpoch,proto3" json:"lastEpoch,omitempty"` + Prices []uint64 `protobuf:"varint,2,rep,packed,name=prices,proto3" json:"prices,omitempty"` + TwapPrice uint64 `protobuf:"varint,3,opt,name=twapPrice,proto3" json:"twapPrice,omitempty"` + PriceDenom string `protobuf:"bytes,4,opt,name=priceDenom,proto3" json:"priceDenom,omitempty"` + AssetDenom string `protobuf:"bytes,5,opt,name=assetDenom,proto3" json:"assetDenom,omitempty"` +} + +func (m *Twap) Reset() { *m = Twap{} } +func (m *Twap) String() string { return proto.CompactTextString(m) } +func (*Twap) ProtoMessage() {} +func (*Twap) Descriptor() ([]byte, []int) { + return fileDescriptor_10aa4b136085207a, []int{0} +} +func (m *Twap) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Twap) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Twap.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 *Twap) XXX_Merge(src proto.Message) { + xxx_messageInfo_Twap.Merge(m, src) +} +func (m *Twap) XXX_Size() int { + return m.Size() +} +func (m *Twap) XXX_DiscardUnknown() { + xxx_messageInfo_Twap.DiscardUnknown(m) +} + +var xxx_messageInfo_Twap proto.InternalMessageInfo + +func (m *Twap) GetLastEpoch() uint64 { + if m != nil { + return m.LastEpoch + } + return 0 +} + +func (m *Twap) GetPrices() []uint64 { + if m != nil { + return m.Prices + } + return nil +} + +func (m *Twap) GetTwapPrice() uint64 { + if m != nil { + return m.TwapPrice + } + return 0 +} + +func (m *Twap) GetPriceDenom() string { + if m != nil { + return m.PriceDenom + } + return "" +} + +func (m *Twap) GetAssetDenom() string { + if m != nil { + return m.AssetDenom + } + return "" +} + +func init() { + proto.RegisterType((*Twap)(nil), "seiprotocol.seichain.dex.Twap") +} + +func init() { proto.RegisterFile("dex/twap.proto", fileDescriptor_10aa4b136085207a) } + +var fileDescriptor_10aa4b136085207a = []byte{ + // 224 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x4b, 0x49, 0xad, 0xd0, + 0x2f, 0x29, 0x4f, 0x2c, 0xd0, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x92, 0x28, 0x4e, 0xcd, 0x04, + 0xb3, 0x92, 0xf3, 0x73, 0xf4, 0x8a, 0x53, 0x33, 0x93, 0x33, 0x12, 0x33, 0xf3, 0xf4, 0x52, 0x52, + 0x2b, 0x94, 0x66, 0x31, 0x72, 0xb1, 0x84, 0x94, 0x27, 0x16, 0x08, 0xc9, 0x70, 0x71, 0xe6, 0x24, + 0x16, 0x97, 0xb8, 0x16, 0xe4, 0x27, 0x67, 0x48, 0x30, 0x2a, 0x30, 0x6a, 0xb0, 0x04, 0x21, 0x04, + 0x84, 0xc4, 0xb8, 0xd8, 0x0a, 0x8a, 0x32, 0x93, 0x53, 0x8b, 0x25, 0x98, 0x14, 0x98, 0x35, 0x58, + 0x82, 0xa0, 0x3c, 0x90, 0x2e, 0x90, 0x35, 0x01, 0x20, 0x9e, 0x04, 0x33, 0x44, 0x17, 0x5c, 0x40, + 0x48, 0x8e, 0x8b, 0x0b, 0xac, 0xce, 0x25, 0x35, 0x2f, 0x3f, 0x57, 0x82, 0x45, 0x81, 0x51, 0x83, + 0x33, 0x08, 0x49, 0x04, 0x24, 0x9f, 0x58, 0x5c, 0x9c, 0x5a, 0x02, 0x91, 0x67, 0x85, 0xc8, 0x23, + 0x44, 0x9c, 0xdc, 0x4f, 0x3c, 0x92, 0x63, 0xbc, 0xf0, 0x48, 0x8e, 0xf1, 0xc1, 0x23, 0x39, 0xc6, + 0x09, 0x8f, 0xe5, 0x18, 0x2e, 0x3c, 0x96, 0x63, 0xb8, 0xf1, 0x58, 0x8e, 0x21, 0x4a, 0x37, 0x3d, + 0xb3, 0x24, 0xa3, 0x34, 0x49, 0x2f, 0x39, 0x3f, 0x57, 0xbf, 0x38, 0x35, 0x53, 0x17, 0xe6, 0x39, + 0x30, 0x07, 0xec, 0x3b, 0xfd, 0x0a, 0x7d, 0x70, 0x20, 0x54, 0x16, 0xa4, 0x16, 0x27, 0xb1, 0x81, + 0xe5, 0x8d, 0x01, 0x01, 0x00, 0x00, 0xff, 0xff, 0x98, 0x40, 0x0f, 0xa7, 0x18, 0x01, 0x00, 0x00, +} + +func (m *Twap) 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 *Twap) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Twap) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.AssetDenom) > 0 { + i -= len(m.AssetDenom) + copy(dAtA[i:], m.AssetDenom) + i = encodeVarintTwap(dAtA, i, uint64(len(m.AssetDenom))) + i-- + dAtA[i] = 0x2a + } + if len(m.PriceDenom) > 0 { + i -= len(m.PriceDenom) + copy(dAtA[i:], m.PriceDenom) + i = encodeVarintTwap(dAtA, i, uint64(len(m.PriceDenom))) + i-- + dAtA[i] = 0x22 + } + if m.TwapPrice != 0 { + i = encodeVarintTwap(dAtA, i, uint64(m.TwapPrice)) + i-- + dAtA[i] = 0x18 + } + if len(m.Prices) > 0 { + dAtA2 := make([]byte, len(m.Prices)*10) + var j1 int + for _, num := range m.Prices { + for num >= 1<<7 { + dAtA2[j1] = uint8(uint64(num)&0x7f | 0x80) + num >>= 7 + j1++ + } + dAtA2[j1] = uint8(num) + j1++ + } + i -= j1 + copy(dAtA[i:], dAtA2[:j1]) + i = encodeVarintTwap(dAtA, i, uint64(j1)) + i-- + dAtA[i] = 0x12 + } + if m.LastEpoch != 0 { + i = encodeVarintTwap(dAtA, i, uint64(m.LastEpoch)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func encodeVarintTwap(dAtA []byte, offset int, v uint64) int { + offset -= sovTwap(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *Twap) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.LastEpoch != 0 { + n += 1 + sovTwap(uint64(m.LastEpoch)) + } + if len(m.Prices) > 0 { + l = 0 + for _, e := range m.Prices { + l += sovTwap(uint64(e)) + } + n += 1 + sovTwap(uint64(l)) + l + } + if m.TwapPrice != 0 { + n += 1 + sovTwap(uint64(m.TwapPrice)) + } + l = len(m.PriceDenom) + if l > 0 { + n += 1 + l + sovTwap(uint64(l)) + } + l = len(m.AssetDenom) + if l > 0 { + n += 1 + l + sovTwap(uint64(l)) + } + return n +} + +func sovTwap(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozTwap(x uint64) (n int) { + return sovTwap(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *Twap) 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 ErrIntOverflowTwap + } + 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: Twap: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Twap: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field LastEpoch", wireType) + } + m.LastEpoch = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTwap + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.LastEpoch |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType == 0 { + var v uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTwap + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.Prices = append(m.Prices, v) + } else if wireType == 2 { + var packedLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTwap + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + packedLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if packedLen < 0 { + return ErrInvalidLengthTwap + } + postIndex := iNdEx + packedLen + if postIndex < 0 { + return ErrInvalidLengthTwap + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + var elementCount int + var count int + for _, integer := range dAtA[iNdEx:postIndex] { + if integer < 128 { + count++ + } + } + elementCount = count + if elementCount != 0 && len(m.Prices) == 0 { + m.Prices = make([]uint64, 0, elementCount) + } + for iNdEx < postIndex { + var v uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTwap + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.Prices = append(m.Prices, v) + } + } else { + return fmt.Errorf("proto: wrong wireType = %d for field Prices", wireType) + } + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field TwapPrice", wireType) + } + m.TwapPrice = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTwap + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.TwapPrice |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field PriceDenom", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTwap + } + 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 ErrInvalidLengthTwap + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTwap + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.PriceDenom = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field AssetDenom", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTwap + } + 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 ErrInvalidLengthTwap + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTwap + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.AssetDenom = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTwap(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTwap + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipTwap(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTwap + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTwap + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTwap + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthTwap + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupTwap + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthTwap + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthTwap = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowTwap = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupTwap = fmt.Errorf("proto: unexpected end of group") +) From ef4dacf9ea2f79893c83354141044c0dd7daa57f Mon Sep 17 00:00:00 2001 From: Xiaoyu Chen Date: Fri, 10 Jun 2022 13:16:12 -0700 Subject: [PATCH 3/5] Add DEX TWAP endpoint --- proto/dex/params.proto | 4 +- proto/dex/price.proto | 15 +- proto/dex/query.proto | 30 +- proto/dex/twap.proto | 17 +- x/dex/client/cli/query.go | 1 + ...query_get_price.go => query_get_prices.go} | 19 +- x/dex/client/cli/query_get_twaps.go | 49 ++ x/dex/genesis.go | 6 - x/dex/keeper/grpc_query_get_price.go | 27 - x/dex/keeper/grpc_query_get_prices.go | 24 + x/dex/keeper/grpc_query_get_twaps.go | 57 ++ x/dex/keeper/grpc_query_get_twaps_test.go | 144 ++++ x/dex/keeper/params.go | 4 +- x/dex/keeper/price.go | 35 +- x/dex/keeper/twap.go | 25 - x/dex/module.go | 67 +- x/dex/types/genesis.go | 16 - x/dex/types/params.go | 31 +- x/dex/types/params.pb.go | 77 +- x/dex/types/price.pb.go | 204 ++--- x/dex/types/query.pb.go | 730 +++++++++++++----- x/dex/types/query.pb.gw.go | 203 +++-- x/dex/types/twap.pb.go | 292 ++----- 23 files changed, 1326 insertions(+), 751 deletions(-) rename x/dex/client/cli/{query_get_price.go => query_get_prices.go} (67%) create mode 100644 x/dex/client/cli/query_get_twaps.go delete mode 100644 x/dex/keeper/grpc_query_get_price.go create mode 100644 x/dex/keeper/grpc_query_get_prices.go create mode 100644 x/dex/keeper/grpc_query_get_twaps.go create mode 100644 x/dex/keeper/grpc_query_get_twaps_test.go delete mode 100644 x/dex/keeper/twap.go diff --git a/proto/dex/params.proto b/proto/dex/params.proto index 546d828b76..7fb90c9a86 100644 --- a/proto/dex/params.proto +++ b/proto/dex/params.proto @@ -7,6 +7,8 @@ option go_package = "github.com/sei-protocol/sei-chain/x/dex/types"; // Params defines the parameters for the module. message Params { + option (gogoproto.equal) = true; option (gogoproto.goproto_stringer) = false; - + + uint64 price_snapshot_retention = 1 [(gogoproto.moretags) = "yaml:\"price_snapshot_retention\""]; } \ No newline at end of file diff --git a/proto/dex/price.proto b/proto/dex/price.proto index a52ad67e3d..33fd4df25d 100644 --- a/proto/dex/price.proto +++ b/proto/dex/price.proto @@ -1,13 +1,18 @@ syntax = "proto3"; package seiprotocol.seichain.dex; +import "gogoproto/gogo.proto"; +import "dex/pair.proto"; + option go_package = "github.com/sei-protocol/sei-chain/x/dex/types"; message Price { - uint64 epoch = 1; - uint64 oraclePrice = 2; - uint64 exchangePrice = 3; - string priceDenom = 4; - string assetDenom = 5; + uint64 snapshotTimestampInSeconds = 1; + string price = 2 [ + (gogoproto.moretags) = "yaml:\"price\"", + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", + (gogoproto.nullable) = false + ]; + Pair pair = 3; } diff --git a/proto/dex/query.proto b/proto/dex/query.proto index 65470efe42..8dd319ea0e 100644 --- a/proto/dex/query.proto +++ b/proto/dex/query.proto @@ -10,6 +10,7 @@ import "dex/short_book.proto"; import "dex/settlement.proto"; import "dex/enums.proto"; import "dex/price.proto"; +import "dex/twap.proto"; // this line is used by starport scaffolding # 1 option go_package = "github.com/sei-protocol/sei-chain/x/dex/types"; @@ -44,9 +45,12 @@ service Query { option (google.api.http).get = "/sei-protocol/seichain/dex/settlement"; } -// Queries a list of GetPrice items. - rpc GetPrice(QueryGetPriceRequest) returns (QueryGetPriceResponse) { - option (google.api.http).get = "/sei-protocol/seichain/dex/get_price/{priceDenom}/{assetDenom}/{epoch}"; + rpc GetPrices(QueryGetPricesRequest) returns (QueryGetPricesResponse) { + option (google.api.http).get = "/sei-protocol/seichain/dex/get_prices/{contractAddr}/{priceDenom}/{assetDenom}"; + } + + rpc GetTwaps(QueryGetTwapsRequest) returns (QueryGetTwapsResponse) { + option (google.api.http).get = "/sei-protocol/seichain/dex/get_twaps/{contractAddr}/{lookbackSeconds}"; } // this line is used by starport scaffolding # 2 @@ -127,15 +131,23 @@ message QueryAllSettlementsResponse { cosmos.base.query.v1beta1.PageResponse pagination = 2; } -message QueryGetPriceRequest { - string priceDenom = 1; - string assetDenom = 2; +message QueryGetPricesRequest { + Denom priceDenom = 1; + Denom assetDenom = 2; string contractAddr = 3; - uint64 epoch = 4; } -message QueryGetPriceResponse { - Price price = 1; +message QueryGetPricesResponse { + repeated Price prices = 1; } +message QueryGetTwapsRequest { + string contractAddr = 1; + uint64 lookbackSeconds = 2; + } + + message QueryGetTwapsResponse { + repeated Twap twaps = 1; + } + // this line is used by starport scaffolding # 3 diff --git a/proto/dex/twap.proto b/proto/dex/twap.proto index a90df8bfba..fbbf65fc9f 100644 --- a/proto/dex/twap.proto +++ b/proto/dex/twap.proto @@ -1,14 +1,19 @@ syntax = "proto3"; package seiprotocol.seichain.dex; +import "gogoproto/gogo.proto"; +import "dex/pair.proto"; + option go_package = "github.com/sei-protocol/sei-chain/x/dex/types"; -// deprecated + message Twap { - uint64 lastEpoch = 1; - repeated uint64 prices = 2; - uint64 twapPrice = 3; - string priceDenom = 4; - string assetDenom = 5; + Pair pair = 1; + string twap = 2 [ + (gogoproto.moretags) = "yaml:\"twap\"", + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", + (gogoproto.nullable) = false + ]; + uint64 lookbackSeconds = 3; } diff --git a/x/dex/client/cli/query.go b/x/dex/client/cli/query.go index eb73d6b2df..350e969b7e 100644 --- a/x/dex/client/cli/query.go +++ b/x/dex/client/cli/query.go @@ -30,6 +30,7 @@ func GetQueryCmd(queryRoute string) *cobra.Command { cmd.AddCommand(CmdListShortBook()) cmd.AddCommand(CmdShowShortBook()) cmd.AddCommand(CmdGetPrice()) + cmd.AddCommand(CmdGetTwaps()) // this line is used by starport scaffolding # 1 diff --git a/x/dex/client/cli/query_get_price.go b/x/dex/client/cli/query_get_prices.go similarity index 67% rename from x/dex/client/cli/query_get_price.go rename to x/dex/client/cli/query_get_prices.go index 62f24e6754..ca87cedbe9 100644 --- a/x/dex/client/cli/query_get_price.go +++ b/x/dex/client/cli/query_get_prices.go @@ -13,17 +13,19 @@ var _ = strconv.Itoa(0) func CmdGetPrice() *cobra.Command { cmd := &cobra.Command{ - Use: "get-price [contract-address] [epoch] [price-denom] [asset-denom]", - Short: "Query getPrice", - Args: cobra.ExactArgs(4), + Use: "get-prices [contract-address] [price-denom] [asset-denom]", + Short: "Query getPrices", + Args: cobra.ExactArgs(3), RunE: func(cmd *cobra.Command, args []string) (err error) { reqContractAddr := args[0] - reqEpoch, err := strconv.ParseUint(args[1], 10, 64) + reqPriceDenom, _, err := types.GetDenomFromStr(args[1]) + if err != nil { + return err + } + reqAssetDenom, _, err := types.GetDenomFromStr(args[2]) if err != nil { return err } - reqPriceDenom := args[2] - reqAssetDenom := args[3] clientCtx, err := client.GetClientTxContext(cmd) if err != nil { @@ -32,14 +34,13 @@ func CmdGetPrice() *cobra.Command { queryClient := types.NewQueryClient(clientCtx) - params := &types.QueryGetPriceRequest{ + params := &types.QueryGetPricesRequest{ ContractAddr: reqContractAddr, - Epoch: reqEpoch, PriceDenom: reqPriceDenom, AssetDenom: reqAssetDenom, } - res, err := queryClient.GetPrice(cmd.Context(), params) + res, err := queryClient.GetPrices(cmd.Context(), params) if err != nil { return err } diff --git a/x/dex/client/cli/query_get_twaps.go b/x/dex/client/cli/query_get_twaps.go new file mode 100644 index 0000000000..f251d020e5 --- /dev/null +++ b/x/dex/client/cli/query_get_twaps.go @@ -0,0 +1,49 @@ +package cli + +import ( + "strconv" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/sei-protocol/sei-chain/x/dex/types" + "github.com/spf13/cobra" +) + +var _ = strconv.Itoa(0) + +func CmdGetTwaps() *cobra.Command { + cmd := &cobra.Command{ + Use: "get-twaps [contract-address] [lookback]", + Short: "Query getPrice", + Args: cobra.ExactArgs(2), + RunE: func(cmd *cobra.Command, args []string) (err error) { + reqContractAddr := args[0] + reqLookback, err := strconv.ParseUint(args[1], 10, 64) + if err != nil { + return err + } + + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + queryClient := types.NewQueryClient(clientCtx) + + params := &types.QueryGetTwapsRequest{ + ContractAddr: reqContractAddr, + LookbackSeconds: reqLookback, + } + + res, err := queryClient.GetTwaps(cmd.Context(), params) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd +} diff --git a/x/dex/genesis.go b/x/dex/genesis.go index ac47abe982..87a974b899 100644 --- a/x/dex/genesis.go +++ b/x/dex/genesis.go @@ -22,12 +22,6 @@ func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState) // this line is used by starport scaffolding # genesis/module/init k.SetParams(ctx, genState.Params) - for _, twap := range genState.TwapList { - twap.LastEpoch = 0 - twap.TwapPrice = twap.Prices[0] - k.SetTwap(ctx, *twap, "genesis") - } - k.SetEpoch(ctx, genState.LastEpoch) } diff --git a/x/dex/keeper/grpc_query_get_price.go b/x/dex/keeper/grpc_query_get_price.go deleted file mode 100644 index 6ba1a2b37b..0000000000 --- a/x/dex/keeper/grpc_query_get_price.go +++ /dev/null @@ -1,27 +0,0 @@ -package keeper - -import ( - "context" - - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/sei-protocol/sei-chain/x/dex/types" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/status" -) - -func (k Keeper) GetPrice(goCtx context.Context, req *types.QueryGetPriceRequest) (*types.QueryGetPriceResponse, error) { - if req == nil { - return nil, status.Error(codes.InvalidArgument, "invalid request") - } - - ctx := sdk.UnwrapSDKContext(goCtx) - - price, exist := k.GetPriceState(ctx, req.ContractAddr, req.Epoch, req.PriceDenom, req.AssetDenom) - if !exist { - return nil, status.Error(codes.NotFound, "not found") - } - - return &types.QueryGetPriceResponse{ - Price: &price, - }, nil -} diff --git a/x/dex/keeper/grpc_query_get_prices.go b/x/dex/keeper/grpc_query_get_prices.go new file mode 100644 index 0000000000..01a77b34b6 --- /dev/null +++ b/x/dex/keeper/grpc_query_get_prices.go @@ -0,0 +1,24 @@ +package keeper + +import ( + "context" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/sei-protocol/sei-chain/x/dex/types" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" +) + +func (k Keeper) GetPrices(goCtx context.Context, req *types.QueryGetPricesRequest) (*types.QueryGetPricesResponse, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + + ctx := sdk.UnwrapSDKContext(goCtx) + + prices := k.GetAllPrices(ctx, req.ContractAddr, types.Pair{PriceDenom: req.PriceDenom, AssetDenom: req.AssetDenom}) + + return &types.QueryGetPricesResponse{ + Prices: prices, + }, nil +} diff --git a/x/dex/keeper/grpc_query_get_twaps.go b/x/dex/keeper/grpc_query_get_twaps.go new file mode 100644 index 0000000000..2f3fbaa4db --- /dev/null +++ b/x/dex/keeper/grpc_query_get_twaps.go @@ -0,0 +1,57 @@ +package keeper + +import ( + "context" + "sort" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/sei-protocol/sei-chain/x/dex/types" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" +) + +func (k Keeper) GetTwaps(goCtx context.Context, req *types.QueryGetTwapsRequest) (*types.QueryGetTwapsResponse, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + + ctx := sdk.UnwrapSDKContext(goCtx) + allRegisteredPairs := k.GetAllRegisteredPairs(ctx, req.ContractAddr) + twaps := []*types.Twap{} + for _, pair := range allRegisteredPairs { + prices := k.GetAllPrices(ctx, req.ContractAddr, pair) + twaps = append(twaps, &types.Twap{ + Pair: &pair, + Twap: calculateTwap(ctx, prices, req.LookbackSeconds), + LookbackSeconds: req.LookbackSeconds, + }) + } + + return &types.QueryGetTwapsResponse{ + Twaps: twaps, + }, nil +} + +func calculateTwap(ctx sdk.Context, prices []*types.Price, lookback uint64) sdk.Dec { + // sort prices in descending order to start iteration from the latest + sort.Slice(prices, func(p1, p2 int) bool { + return prices[p1].SnapshotTimestampInSeconds > prices[p2].SnapshotTimestampInSeconds + }) + var timeTraversed uint64 = 0 + var weightedPriceSum sdk.Dec = sdk.ZeroDec() + for _, price := range prices { + newTimeTraversed := uint64(ctx.BlockTime().Unix()) - price.SnapshotTimestampInSeconds + if newTimeTraversed > lookback { + break + } + weightedPriceSum = weightedPriceSum.Add( + price.Price.MulInt64(int64(newTimeTraversed - timeTraversed)), + ) + timeTraversed = newTimeTraversed + } + if timeTraversed == 0 { + return sdk.ZeroDec() + } else { + return weightedPriceSum.QuoInt64(int64(timeTraversed)) + } +} diff --git a/x/dex/keeper/grpc_query_get_twaps_test.go b/x/dex/keeper/grpc_query_get_twaps_test.go new file mode 100644 index 0000000000..82172396ce --- /dev/null +++ b/x/dex/keeper/grpc_query_get_twaps_test.go @@ -0,0 +1,144 @@ +package keeper_test + +import ( + "testing" + "time" + + sdk "github.com/cosmos/cosmos-sdk/types" + keepertest "github.com/sei-protocol/sei-chain/testutil/keeper" + "github.com/sei-protocol/sei-chain/x/dex/types" + "github.com/stretchr/testify/require" +) + +const GENESIS_TIME uint64 = 3600 + +var TEST_PAIR = types.Pair{ + PriceDenom: TEST_PRICE_DENOM, + AssetDenom: TEST_ASSET_DENOM, +} + +func TestGetTwapsNoPriceSnapshot(t *testing.T) { + keeper, ctx := keepertest.DexKeeper(t) + keeper.AddRegisteredPair(ctx, TEST_CONTRACT, TEST_PAIR) + wctx := sdk.WrapSDKContext(ctx) + var lookback uint64 = 10 + request := types.QueryGetTwapsRequest{ + ContractAddr: TEST_CONTRACT, + LookbackSeconds: lookback, + } + expectedResponse := types.QueryGetTwapsResponse{ + Twaps: []*types.Twap{ + { + Pair: &TEST_PAIR, + Twap: sdk.ZeroDec(), + LookbackSeconds: lookback, + }, + }, + } + t.Run("No snapshot", func(t *testing.T) { + response, err := keeper.GetTwaps(wctx, &request) + require.NoError(t, err) + require.Equal(t, expectedResponse, *response) + }) +} + +func TestGetTwapsOnePriceSnapshot(t *testing.T) { + keeper, ctx := keepertest.DexKeeper(t) + keeper.AddRegisteredPair(ctx, TEST_CONTRACT, TEST_PAIR) + ctx = ctx.WithBlockTime(time.Unix(int64(GENESIS_TIME)+5, 0)) + wctx := sdk.WrapSDKContext(ctx) + + snapshotPrice := sdk.MustNewDecFromStr("100.00") + keeper.SetPriceState(ctx, types.Price{ + SnapshotTimestampInSeconds: GENESIS_TIME, + Price: snapshotPrice, + Pair: &TEST_PAIR, + }, TEST_CONTRACT, 0) + + var lookback uint64 = 10 + request := types.QueryGetTwapsRequest{ + ContractAddr: TEST_CONTRACT, + LookbackSeconds: lookback, + } + expectedResponse := types.QueryGetTwapsResponse{ + Twaps: []*types.Twap{ + { + Pair: &TEST_PAIR, + Twap: snapshotPrice, + LookbackSeconds: lookback, + }, + }, + } + t.Run("One snapshot", func(t *testing.T) { + response, err := keeper.GetTwaps(wctx, &request) + require.NoError(t, err) + require.Equal(t, expectedResponse, *response) + }) + + lookback = 4 + request = types.QueryGetTwapsRequest{ + ContractAddr: TEST_CONTRACT, + LookbackSeconds: lookback, + } + expectedResponse = types.QueryGetTwapsResponse{ + Twaps: []*types.Twap{ + { + Pair: &TEST_PAIR, + Twap: sdk.ZeroDec(), + LookbackSeconds: lookback, + }, + }, + } + t.Run("One snapshot too old", func(t *testing.T) { + response, err := keeper.GetTwaps(wctx, &request) + require.NoError(t, err) + require.Equal(t, expectedResponse, *response) + }) +} + +func TestGetTwapsMultipleSnapshots(t *testing.T) { + keeper, ctx := keepertest.DexKeeper(t) + keeper.AddRegisteredPair(ctx, TEST_CONTRACT, TEST_PAIR) + ctx = ctx.WithBlockTime(time.Unix(int64(GENESIS_TIME)+20, 0)) + wctx := sdk.WrapSDKContext(ctx) + + snapshotPrices := []sdk.Dec{ + sdk.MustNewDecFromStr("100.00"), + sdk.MustNewDecFromStr("98.50"), + sdk.MustNewDecFromStr("101.00"), + } + timestampDeltas := []uint64{0, 10, 15} + for i := range snapshotPrices { + keeper.SetPriceState(ctx, types.Price{ + SnapshotTimestampInSeconds: GENESIS_TIME + timestampDeltas[i], + Price: snapshotPrices[i], + Pair: &TEST_PAIR, + }, TEST_CONTRACT, uint64(i)) + } + + var lookback uint64 = 20 + request := types.QueryGetTwapsRequest{ + ContractAddr: TEST_CONTRACT, + LookbackSeconds: lookback, + } + expectedTwap := snapshotPrices[0].MulInt64(10).Add( + snapshotPrices[1].MulInt64(15 - 10), + ).Add( + snapshotPrices[2].MulInt64(20 - 15), + ).QuoInt64(20) + require.Equal(t, sdk.MustNewDecFromStr("99.875"), expectedTwap) + expectedResponse := types.QueryGetTwapsResponse{ + Twaps: []*types.Twap{ + { + Pair: &TEST_PAIR, + Twap: expectedTwap, + LookbackSeconds: lookback, + }, + }, + } + t.Run("Multiple snapshots", func(t *testing.T) { + response, err := keeper.GetTwaps(wctx, &request) + require.NoError(t, err) + require.Equal(t, expectedResponse, *response) + }) +} diff --git a/x/dex/keeper/params.go b/x/dex/keeper/params.go index 92ce38d221..30087a9987 100644 --- a/x/dex/keeper/params.go +++ b/x/dex/keeper/params.go @@ -7,7 +7,9 @@ import ( // GetParams get all parameters as types.Params func (k Keeper) GetParams(ctx sdk.Context) types.Params { - return types.NewParams() + params := types.Params{} + k.paramstore.GetParamSet(ctx, ¶ms) + return params } // SetParams set the params diff --git a/x/dex/keeper/price.go b/x/dex/keeper/price.go index 453b7360c1..661b8e0d37 100644 --- a/x/dex/keeper/price.go +++ b/x/dex/keeper/price.go @@ -8,37 +8,40 @@ import ( "github.com/sei-protocol/sei-chain/x/dex/types" ) -func (k Keeper) SetPriceState(ctx sdk.Context, price types.Price, contractAddr string) { +func (k Keeper) SetPriceState(ctx sdk.Context, price types.Price, contractAddr string, epoch uint64) { store := prefix.NewStore(ctx.KVStore(k.storeKey), types.PricePrefix(contractAddr)) - b := k.cdc.MustMarshal(&price) - store.Set(GetKeyForPriceState(price.Epoch, price.PriceDenom, price.AssetDenom), b) + b := k.Cdc.MustMarshal(&price) + store.Set(GetKeyForPriceState(epoch, *price.Pair), b) } -func (k Keeper) GetPriceState(ctx sdk.Context, contractAddr string, epoch uint64, priceDenom string, assetDenom string) (types.Price, bool) { +func (k Keeper) DeletePriceState(ctx sdk.Context, contractAddr string, epoch uint64, pair types.Pair) { + store := prefix.NewStore(ctx.KVStore(k.storeKey), types.PricePrefix(contractAddr)) + store.Delete(GetKeyForPriceState(epoch, pair)) +} + +func (k Keeper) GetPriceState(ctx sdk.Context, contractAddr string, epoch uint64, pair types.Pair) (types.Price, bool) { store := prefix.NewStore(ctx.KVStore(k.storeKey), types.PricePrefix(contractAddr)) res := types.Price{} - key := GetKeyForPriceState(epoch, priceDenom, assetDenom) + key := GetKeyForPriceState(epoch, pair) if !store.Has(key) { - res.Epoch = epoch - res.PriceDenom = priceDenom - res.AssetDenom = assetDenom + res.Pair = &pair return res, false } b := store.Get(key) - k.cdc.MustUnmarshal(b, &res) + k.Cdc.MustUnmarshal(b, &res) return res, true } -func (k Keeper) GetAllPrices(ctx sdk.Context, contractAddr string, epoch uint64) (list []types.Price) { +func (k Keeper) GetAllPrices(ctx sdk.Context, contractAddr string, pair types.Pair) (list []*types.Price) { store := prefix.NewStore(ctx.KVStore(k.storeKey), types.PricePrefix(contractAddr)) - iterator := sdk.KVStorePrefixIterator(store, GetKeyForEpoch(epoch)) + iterator := sdk.KVStorePrefixIterator(store, types.PairPrefix(pair.PriceDenom, pair.AssetDenom)) defer iterator.Close() for ; iterator.Valid(); iterator.Next() { var val types.Price - k.cdc.MustUnmarshal(iterator.Value(), &val) - list = append(list, val) + k.Cdc.MustUnmarshal(iterator.Value(), &val) + list = append(list, &val) } return @@ -50,9 +53,9 @@ func GetKeyForEpoch(epoch uint64) []byte { return epochKey } -func GetKeyForPriceState(epoch uint64, priceDenom string, assetDenom string) []byte { +func GetKeyForPriceState(epoch uint64, pair types.Pair) []byte { return append( - GetKeyForEpoch(epoch), - append([]byte(priceDenom), []byte(assetDenom)...)..., + types.PairPrefix(pair.PriceDenom, pair.AssetDenom), + GetKeyForEpoch(epoch)..., ) } diff --git a/x/dex/keeper/twap.go b/x/dex/keeper/twap.go deleted file mode 100644 index 1842bc7b88..0000000000 --- a/x/dex/keeper/twap.go +++ /dev/null @@ -1,25 +0,0 @@ -package keeper - -import ( - "github.com/cosmos/cosmos-sdk/store/prefix" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/sei-protocol/sei-chain/x/dex/types" -) - -func (k Keeper) SetTwap(ctx sdk.Context, twap types.Twap, contractAddr string) { - store := prefix.NewStore(ctx.KVStore(k.storeKey), types.TwapPrefix(contractAddr)) - b := k.Cdc.MustMarshal(&twap) - priceDenom, _, err := types.GetDenomFromStr(twap.PriceDenom) - if err != nil { - panic(err) - } - assetDenom, _, err := types.GetDenomFromStr(twap.AssetDenom) - if err != nil { - panic(err) - } - store.Set(types.PairPrefix(priceDenom, assetDenom), b) -} - -func GetKeyForTwap(priceDenom string, assetDenom string) []byte { - return append([]byte(priceDenom), []byte(assetDenom)...) -} diff --git a/x/dex/module.go b/x/dex/module.go index ef2edc17e3..0ac50f2bc0 100644 --- a/x/dex/module.go +++ b/x/dex/module.go @@ -4,7 +4,6 @@ import ( "context" "encoding/json" "fmt" - "strconv" "github.com/CosmWasm/wasmd/x/wasm" "github.com/gorilla/mux" @@ -236,50 +235,23 @@ func (am AppModule) beginBlockForContract(ctx sdk.Context, contractAddr string) if isNewEpoch, currentEpoch := am.keeper.IsNewEpoch(ctx); isNewEpoch { ctx.Logger().Info(fmt.Sprintf("Updating price for epoch %d", currentEpoch)) - setPrices := []types.SetPrice{} + priceRetention := am.keeper.GetParams(ctx).PriceSnapshotRetention for _, pair := range am.keeper.GetAllRegisteredPairs(ctx, contractAddr) { - lastEpochPrice, exist := am.keeper.GetPriceState(ctx, contractAddr, currentEpoch-1, pair.PriceDenom, pair.AssetDenom) - if exist { - setPrices = append(setPrices, types.SetPrice{ - Epoch: currentEpoch - 1, - PriceDenom: pair.PriceDenom, - AssetDenom: pair.AssetDenom, - ExchangePrice: strconv.FormatUint(lastEpochPrice.ExchangePrice, 10), - OraclePrice: strconv.FormatUint(lastEpochPrice.OraclePrice, 10), - }) - } - newEpochPrice := types.Price{ - Epoch: currentEpoch, - PriceDenom: pair.PriceDenom, - AssetDenom: pair.AssetDenom, - ExchangePrice: lastEpochPrice.ExchangePrice, - OraclePrice: lastEpochPrice.OraclePrice, + lastEpochPrice, exists := am.keeper.GetPriceState(ctx, contractAddr, currentEpoch-1, pair) + if exists { + newEpochPrice := types.Price{ + SnapshotTimestampInSeconds: uint64(ctx.BlockTime().Unix()), + Pair: &pair, + Price: lastEpochPrice.Price, + } + am.keeper.SetPriceState(ctx, newEpochPrice, contractAddr, currentEpoch) } - am.keeper.SetPriceState(ctx, newEpochPrice, contractAddr) - } - nativeSetFPRMsg := types.SudoSetPricesMsg{ - SetPrices: types.SetPrices{ - Prices: setPrices, - }, - } - wasmMsg, err := json.Marshal(nativeSetFPRMsg) - if err != nil { - ctx.Logger().Info(err.Error()) - } - am.callClearingHouseContractSudo(ctx, wasmMsg, contractAddr) - } else { - for _, pair := range am.keeper.GetAllRegisteredPairs(ctx, contractAddr) { - lastEpochPrice, _ := am.keeper.GetPriceState(ctx, contractAddr, currentEpoch, pair.PriceDenom, pair.AssetDenom) - oraclePriceDenom1, error1 := am.oracleKeeper.GetBaseExchangeRate(ctx, pair.PriceDenom) - oraclePriceDenom2, error2 := am.oracleKeeper.GetBaseExchangeRate(ctx, pair.AssetDenom) - if error1 == nil && error2 == nil { - lastEpochPrice.OraclePrice = oraclePriceDenom2.Quo(oraclePriceDenom1).TruncateInt().Uint64() - } else { - // if oracle price is not set, use exchange price as oracle price - lastEpochPrice.OraclePrice = lastEpochPrice.ExchangePrice + // condition to prevent unsigned integer overflow + if currentEpoch >= priceRetention { + // this will no-op if price snapshot for the target epoch doesn't exist + am.keeper.DeletePriceState(ctx, contractAddr, currentEpoch-priceRetention, pair) } - am.keeper.SetPriceState(ctx, lastEpochPrice, contractAddr) } } } @@ -302,9 +274,9 @@ func (am AppModule) endBlockForContract(ctx sdk.Context, contractAddr string) { registeredPairs := am.keeper.GetAllRegisteredPairs(ctx, contractAddr) _, currentEpoch := am.keeper.IsNewEpoch(ctx) - am.keeper.HandleEBLiquidation(spanCtx, ctx, am.tracingInfo.Tracer, contractAddr) - am.keeper.HandleEBCancelOrders(spanCtx, ctx, am.tracingInfo.Tracer, contractAddr) - am.keeper.HandleEBPlaceOrders(spanCtx, ctx, am.tracingInfo.Tracer, contractAddr) + am.keeper.HandleEBLiquidation(spanCtx, ctx, am.tracingInfo.Tracer, contractAddr, registeredPairs) + am.keeper.HandleEBCancelOrders(spanCtx, ctx, am.tracingInfo.Tracer, contractAddr, registeredPairs) + am.keeper.HandleEBPlaceOrders(spanCtx, ctx, am.tracingInfo.Tracer, contractAddr, registeredPairs) am.keeper.OrderCancellations[contractAddr] = map[string]*dexcache.OrderCancellations{} for _, pair := range registeredPairs { @@ -358,9 +330,10 @@ func (am AppModule) endBlockForContract(ctx sdk.Context, contractAddr string) { avgPrice = sdk.ZeroDec() } else { avgPrice = (marketBuyTotalPrice.Add(marketSellTotalPrice).Add(limitTotalPrice)).Quo(marketBuyTotalQuantity.Add(marketSellTotalQuantity).Add(limitTotalQuantity)) - priceState, _ := am.keeper.GetPriceState(ctx, contractAddr, currentEpoch, pair.PriceDenom, pair.AssetDenom) - priceState.ExchangePrice = avgPrice - am.keeper.SetPriceState(ctx, priceState, contractAddr) + priceState, _ := am.keeper.GetPriceState(ctx, contractAddr, currentEpoch, pair) + priceState.SnapshotTimestampInSeconds = uint64(ctx.BlockTime().Unix()) + priceState.Price = avgPrice + am.keeper.SetPriceState(ctx, priceState, contractAddr, currentEpoch) } ctx.Logger().Info(fmt.Sprintf("Average price for %s/%s: %d", pair.PriceDenom, pair.AssetDenom, avgPrice)) for _, buy := range allExistingBuys { diff --git a/x/dex/types/genesis.go b/x/dex/types/genesis.go index f9378c3a5e..6cb58ee95d 100644 --- a/x/dex/types/genesis.go +++ b/x/dex/types/genesis.go @@ -15,22 +15,6 @@ func DefaultGenesis() *GenesisState { // this line is used by starport scaffolding # genesis/types/default Params: DefaultParams(), LastEpoch: 0, - TwapList: []*Twap{ - { - LastEpoch: 0, - Prices: []uint64{105}, - TwapPrice: 105, - PriceDenom: "usdc", - AssetDenom: "sei", - }, - { - LastEpoch: 0, - Prices: []uint64{105}, - TwapPrice: 105, - PriceDenom: "usdc", - AssetDenom: "atom", - }, - }, } } diff --git a/x/dex/types/params.go b/x/dex/types/params.go index 357196ad6a..43b1193238 100644 --- a/x/dex/types/params.go +++ b/x/dex/types/params.go @@ -1,10 +1,20 @@ package types import ( + fmt "fmt" + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" "gopkg.in/yaml.v2" ) +var ( + KeyPriceSnapshotRetention = []byte("PriceSnapshotRetention") // number of epochs to retain price snapshots for +) + +const ( + DefaultPriceSnapshotRetention = 60 // default epoch interval is one minute so this results in a one-hour retention +) + var _ paramtypes.ParamSet = (*Params)(nil) // ParamKeyTable the param key table for launch module @@ -19,12 +29,16 @@ func NewParams() Params { // DefaultParams returns a default set of parameters func DefaultParams() Params { - return NewParams() + return Params{ + PriceSnapshotRetention: DefaultPriceSnapshotRetention, + } } // ParamSetPairs get the params.ParamSet func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { - return paramtypes.ParamSetPairs{} + return paramtypes.ParamSetPairs{ + paramtypes.NewParamSetPair(KeyPriceSnapshotRetention, &p.PriceSnapshotRetention, validatePriceSnapshotRetention), + } } // Validate validates the set of params @@ -37,3 +51,16 @@ func (p Params) String() string { out, _ := yaml.Marshal(p) return string(out) } + +func validatePriceSnapshotRetention(i interface{}) error { + v, ok := i.(uint64) + if !ok { + return fmt.Errorf("invalid parameter type: %T", i) + } + + if v == 0 { + return fmt.Errorf("price snapshot retention must be a positive integer: %d", v) + } + + return nil +} diff --git a/x/dex/types/params.pb.go b/x/dex/types/params.pb.go index f3c816fcca..4b898d9c9a 100644 --- a/x/dex/types/params.pb.go +++ b/x/dex/types/params.pb.go @@ -25,6 +25,7 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // Params defines the parameters for the module. type Params struct { + PriceSnapshotRetention uint64 `protobuf:"varint,1,opt,name=price_snapshot_retention,json=priceSnapshotRetention,proto3" json:"price_snapshot_retention,omitempty" yaml:"price_snapshot_retention"` } func (m *Params) Reset() { *m = Params{} } @@ -59,6 +60,13 @@ func (m *Params) XXX_DiscardUnknown() { var xxx_messageInfo_Params proto.InternalMessageInfo +func (m *Params) GetPriceSnapshotRetention() uint64 { + if m != nil { + return m.PriceSnapshotRetention + } + return 0 +} + func init() { proto.RegisterType((*Params)(nil), "seiprotocol.seichain.dex.Params") } @@ -66,19 +74,47 @@ func init() { func init() { proto.RegisterFile("dex/params.proto", fileDescriptor_e49286500ccff43e) } var fileDescriptor_e49286500ccff43e = []byte{ - // 156 bytes of a gzipped FileDescriptorProto + // 220 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0x48, 0x49, 0xad, 0xd0, 0x2f, 0x48, 0x2c, 0x4a, 0xcc, 0x2d, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x92, 0x28, 0x4e, 0xcd, 0x04, 0xb3, 0x92, 0xf3, 0x73, 0xf4, 0x8a, 0x53, 0x33, 0x93, 0x33, 0x12, 0x33, 0xf3, 0xf4, 0x52, 0x52, 0x2b, 0xa4, 0x44, 0xd2, 0xf3, 0xd3, 0xf3, 0xc1, 0x52, 0xfa, 0x20, 0x16, 0x44, 0xbd, - 0x12, 0x1f, 0x17, 0x5b, 0x00, 0x58, 0xbf, 0x15, 0xcb, 0x8c, 0x05, 0xf2, 0x0c, 0x4e, 0xee, 0x27, - 0x1e, 0xc9, 0x31, 0x5e, 0x78, 0x24, 0xc7, 0xf8, 0xe0, 0x91, 0x1c, 0xe3, 0x84, 0xc7, 0x72, 0x0c, - 0x17, 0x1e, 0xcb, 0x31, 0xdc, 0x78, 0x2c, 0xc7, 0x10, 0xa5, 0x9b, 0x9e, 0x59, 0x92, 0x51, 0x9a, - 0xa4, 0x97, 0x9c, 0x9f, 0xab, 0x5f, 0x9c, 0x9a, 0xa9, 0x0b, 0xb3, 0x05, 0xcc, 0x01, 0x5b, 0xa3, - 0x5f, 0xa1, 0x0f, 0x72, 0x4f, 0x49, 0x65, 0x41, 0x6a, 0x71, 0x12, 0x1b, 0x58, 0xde, 0x18, 0x10, - 0x00, 0x00, 0xff, 0xff, 0x6a, 0x11, 0x75, 0x70, 0xa3, 0x00, 0x00, 0x00, + 0x52, 0x21, 0x17, 0x5b, 0x00, 0x58, 0xbf, 0x50, 0x2c, 0x97, 0x44, 0x41, 0x51, 0x66, 0x72, 0x6a, + 0x7c, 0x71, 0x5e, 0x62, 0x41, 0x71, 0x46, 0x7e, 0x49, 0x7c, 0x51, 0x6a, 0x49, 0x6a, 0x5e, 0x49, + 0x66, 0x7e, 0x9e, 0x04, 0xa3, 0x02, 0xa3, 0x06, 0x8b, 0x93, 0xf2, 0xa7, 0x7b, 0xf2, 0xf2, 0x95, + 0x89, 0xb9, 0x39, 0x56, 0x4a, 0xb8, 0x54, 0x2a, 0x05, 0x89, 0x81, 0xa5, 0x82, 0xa1, 0x32, 0x41, + 0x30, 0x09, 0x2b, 0x8e, 0x19, 0x0b, 0xe4, 0x19, 0x5e, 0x2c, 0x90, 0x67, 0x74, 0x72, 0x3f, 0xf1, + 0x48, 0x8e, 0xf1, 0xc2, 0x23, 0x39, 0xc6, 0x07, 0x8f, 0xe4, 0x18, 0x27, 0x3c, 0x96, 0x63, 0xb8, + 0xf0, 0x58, 0x8e, 0xe1, 0xc6, 0x63, 0x39, 0x86, 0x28, 0xdd, 0xf4, 0xcc, 0x92, 0x8c, 0xd2, 0x24, + 0xbd, 0xe4, 0xfc, 0x5c, 0xfd, 0xe2, 0xd4, 0x4c, 0x5d, 0x98, 0x47, 0xc0, 0x1c, 0xb0, 0x4f, 0xf4, + 0x2b, 0xf4, 0x41, 0x5e, 0x2e, 0xa9, 0x2c, 0x48, 0x2d, 0x4e, 0x62, 0x03, 0xcb, 0x1b, 0x03, 0x02, + 0x00, 0x00, 0xff, 0xff, 0xb9, 0xf5, 0xe8, 0x21, 0x06, 0x01, 0x00, 0x00, } +func (this *Params) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*Params) + if !ok { + that2, ok := that.(Params) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if this.PriceSnapshotRetention != that1.PriceSnapshotRetention { + return false + } + return true +} func (m *Params) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) @@ -99,6 +135,11 @@ func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if m.PriceSnapshotRetention != 0 { + i = encodeVarintParams(dAtA, i, uint64(m.PriceSnapshotRetention)) + i-- + dAtA[i] = 0x8 + } return len(dAtA) - i, nil } @@ -119,6 +160,9 @@ func (m *Params) Size() (n int) { } var l int _ = l + if m.PriceSnapshotRetention != 0 { + n += 1 + sovParams(uint64(m.PriceSnapshotRetention)) + } return n } @@ -157,6 +201,25 @@ func (m *Params) Unmarshal(dAtA []byte) error { return fmt.Errorf("proto: Params: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field PriceSnapshotRetention", wireType) + } + m.PriceSnapshotRetention = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.PriceSnapshotRetention |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } default: iNdEx = preIndex skippy, err := skipParams(dAtA[iNdEx:]) diff --git a/x/dex/types/price.pb.go b/x/dex/types/price.pb.go index f124301e05..39bf38bf1f 100644 --- a/x/dex/types/price.pb.go +++ b/x/dex/types/price.pb.go @@ -5,6 +5,8 @@ package types import ( fmt "fmt" + github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" + _ "github.com/gogo/protobuf/gogoproto" proto "github.com/gogo/protobuf/proto" io "io" math "math" @@ -23,11 +25,9 @@ var _ = math.Inf const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package type Price struct { - Epoch uint64 `protobuf:"varint,1,opt,name=epoch,proto3" json:"epoch,omitempty"` - OraclePrice uint64 `protobuf:"varint,2,opt,name=oraclePrice,proto3" json:"oraclePrice,omitempty"` - ExchangePrice uint64 `protobuf:"varint,3,opt,name=exchangePrice,proto3" json:"exchangePrice,omitempty"` - PriceDenom string `protobuf:"bytes,4,opt,name=priceDenom,proto3" json:"priceDenom,omitempty"` - AssetDenom string `protobuf:"bytes,5,opt,name=assetDenom,proto3" json:"assetDenom,omitempty"` + SnapshotTimestampInSeconds uint64 `protobuf:"varint,1,opt,name=snapshotTimestampInSeconds,proto3" json:"snapshotTimestampInSeconds,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" yaml:"price"` + Pair *Pair `protobuf:"bytes,3,opt,name=pair,proto3" json:"pair,omitempty"` } func (m *Price) Reset() { *m = Price{} } @@ -63,39 +63,18 @@ func (m *Price) XXX_DiscardUnknown() { var xxx_messageInfo_Price proto.InternalMessageInfo -func (m *Price) GetEpoch() uint64 { +func (m *Price) GetSnapshotTimestampInSeconds() uint64 { if m != nil { - return m.Epoch + return m.SnapshotTimestampInSeconds } return 0 } -func (m *Price) GetOraclePrice() uint64 { +func (m *Price) GetPair() *Pair { if m != nil { - return m.OraclePrice + return m.Pair } - return 0 -} - -func (m *Price) GetExchangePrice() uint64 { - if m != nil { - return m.ExchangePrice - } - return 0 -} - -func (m *Price) GetPriceDenom() string { - if m != nil { - return m.PriceDenom - } - return "" -} - -func (m *Price) GetAssetDenom() string { - if m != nil { - return m.AssetDenom - } - return "" + return nil } func init() { @@ -105,22 +84,25 @@ func init() { func init() { proto.RegisterFile("dex/price.proto", fileDescriptor_bd5d1c9d490efb8c) } var fileDescriptor_bd5d1c9d490efb8c = []byte{ - // 225 bytes of a gzipped FileDescriptorProto + // 285 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x4f, 0x49, 0xad, 0xd0, 0x2f, 0x28, 0xca, 0x4c, 0x4e, 0xd5, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x92, 0x28, 0x4e, 0xcd, 0x04, 0xb3, 0x92, 0xf3, 0x73, 0xf4, 0x8a, 0x53, 0x33, 0x93, 0x33, 0x12, 0x33, 0xf3, 0xf4, 0x52, - 0x52, 0x2b, 0x94, 0x96, 0x32, 0x72, 0xb1, 0x06, 0x80, 0x54, 0x0a, 0x89, 0x70, 0xb1, 0xa6, 0x16, - 0xe4, 0x27, 0x67, 0x48, 0x30, 0x2a, 0x30, 0x6a, 0xb0, 0x04, 0x41, 0x38, 0x42, 0x0a, 0x5c, 0xdc, - 0xf9, 0x45, 0x89, 0xc9, 0x39, 0xa9, 0x60, 0x45, 0x12, 0x4c, 0x60, 0x39, 0x64, 0x21, 0x21, 0x15, - 0x2e, 0xde, 0xd4, 0x8a, 0xe4, 0x8c, 0xc4, 0xbc, 0x74, 0xa8, 0x1a, 0x66, 0xb0, 0x1a, 0x54, 0x41, - 0x21, 0x39, 0x2e, 0x2e, 0xb0, 0x83, 0x5c, 0x52, 0xf3, 0xf2, 0x73, 0x25, 0x58, 0x14, 0x18, 0x35, - 0x38, 0x83, 0x90, 0x44, 0x40, 0xf2, 0x89, 0xc5, 0xc5, 0xa9, 0x25, 0x10, 0x79, 0x56, 0x88, 0x3c, - 0x42, 0xc4, 0xc9, 0xfd, 0xc4, 0x23, 0x39, 0xc6, 0x0b, 0x8f, 0xe4, 0x18, 0x1f, 0x3c, 0x92, 0x63, - 0x9c, 0xf0, 0x58, 0x8e, 0xe1, 0xc2, 0x63, 0x39, 0x86, 0x1b, 0x8f, 0xe5, 0x18, 0xa2, 0x74, 0xd3, - 0x33, 0x4b, 0x32, 0x4a, 0x93, 0xf4, 0x92, 0xf3, 0x73, 0xf5, 0x8b, 0x53, 0x33, 0x75, 0x61, 0xfe, - 0x04, 0x73, 0xc0, 0x1e, 0xd5, 0xaf, 0xd0, 0x07, 0x05, 0x48, 0x49, 0x65, 0x41, 0x6a, 0x71, 0x12, - 0x1b, 0x58, 0xde, 0x18, 0x10, 0x00, 0x00, 0xff, 0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, 0x8c, 0x17, + 0x1e, 0xc9, 0x31, 0x3e, 0x78, 0x24, 0xc7, 0x38, 0xe1, 0xb1, 0x1c, 0xc3, 0x85, 0xc7, 0x72, 0x0c, + 0x37, 0x1e, 0xcb, 0x31, 0x44, 0xe9, 0x22, 0x39, 0xa6, 0x38, 0x35, 0x53, 0x17, 0x66, 0x14, 0x98, + 0x03, 0x36, 0x4b, 0xbf, 0x42, 0x1f, 0x14, 0x42, 0x60, 0x77, 0x25, 0xb1, 0x81, 0xe5, 0x8d, 0x01, + 0x01, 0x00, 0x00, 0xff, 0xff, 0x55, 0x90, 0xf5, 0xec, 0x76, 0x01, 0x00, 0x00, } func (m *Price) Marshal() (dAtA []byte, err error) { @@ -143,32 +125,30 @@ func (m *Price) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if len(m.AssetDenom) > 0 { - i -= len(m.AssetDenom) - copy(dAtA[i:], m.AssetDenom) - i = encodeVarintPrice(dAtA, i, uint64(len(m.AssetDenom))) - i-- - dAtA[i] = 0x2a - } - if len(m.PriceDenom) > 0 { - i -= len(m.PriceDenom) - copy(dAtA[i:], m.PriceDenom) - i = encodeVarintPrice(dAtA, i, uint64(len(m.PriceDenom))) - i-- - dAtA[i] = 0x22 - } - if m.ExchangePrice != 0 { - i = encodeVarintPrice(dAtA, i, uint64(m.ExchangePrice)) + if m.Pair != nil { + { + size, err := m.Pair.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintPrice(dAtA, i, uint64(size)) + } i-- - dAtA[i] = 0x18 + dAtA[i] = 0x1a } - if m.OraclePrice != 0 { - i = encodeVarintPrice(dAtA, i, uint64(m.OraclePrice)) - i-- - dAtA[i] = 0x10 + { + size := m.Price.Size() + i -= size + if _, err := m.Price.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintPrice(dAtA, i, uint64(size)) } - if m.Epoch != 0 { - i = encodeVarintPrice(dAtA, i, uint64(m.Epoch)) + i-- + dAtA[i] = 0x12 + if m.SnapshotTimestampInSeconds != 0 { + i = encodeVarintPrice(dAtA, i, uint64(m.SnapshotTimestampInSeconds)) i-- dAtA[i] = 0x8 } @@ -192,21 +172,13 @@ func (m *Price) Size() (n int) { } var l int _ = l - if m.Epoch != 0 { - n += 1 + sovPrice(uint64(m.Epoch)) - } - if m.OraclePrice != 0 { - n += 1 + sovPrice(uint64(m.OraclePrice)) - } - if m.ExchangePrice != 0 { - n += 1 + sovPrice(uint64(m.ExchangePrice)) - } - l = len(m.PriceDenom) - if l > 0 { - n += 1 + l + sovPrice(uint64(l)) + if m.SnapshotTimestampInSeconds != 0 { + n += 1 + sovPrice(uint64(m.SnapshotTimestampInSeconds)) } - l = len(m.AssetDenom) - if l > 0 { + l = m.Price.Size() + n += 1 + l + sovPrice(uint64(l)) + if m.Pair != nil { + l = m.Pair.Size() n += 1 + l + sovPrice(uint64(l)) } return n @@ -249,9 +221,9 @@ func (m *Price) Unmarshal(dAtA []byte) error { switch fieldNum { case 1: if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Epoch", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field SnapshotTimestampInSeconds", wireType) } - m.Epoch = 0 + m.SnapshotTimestampInSeconds = 0 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowPrice @@ -261,52 +233,14 @@ func (m *Price) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.Epoch |= uint64(b&0x7F) << shift + m.SnapshotTimestampInSeconds |= uint64(b&0x7F) << shift if b < 0x80 { break } } case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field OraclePrice", wireType) - } - m.OraclePrice = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowPrice - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.OraclePrice |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 3: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field ExchangePrice", wireType) - } - m.ExchangePrice = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowPrice - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.ExchangePrice |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 4: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field PriceDenom", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Price", wireType) } var stringLen uint64 for shift := uint(0); ; shift += 7 { @@ -334,13 +268,15 @@ func (m *Price) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.PriceDenom = string(dAtA[iNdEx:postIndex]) + if err := m.Price.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } iNdEx = postIndex - case 5: + case 3: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field AssetDenom", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Pair", wireType) } - var stringLen uint64 + var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowPrice @@ -350,23 +286,27 @@ func (m *Price) 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 ErrInvalidLengthPrice } - postIndex := iNdEx + intStringLen + postIndex := iNdEx + msglen if postIndex < 0 { return ErrInvalidLengthPrice } if postIndex > l { return io.ErrUnexpectedEOF } - m.AssetDenom = string(dAtA[iNdEx:postIndex]) + if m.Pair == nil { + m.Pair = &Pair{} + } + if err := m.Pair.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } iNdEx = postIndex default: iNdEx = preIndex diff --git a/x/dex/types/query.pb.go b/x/dex/types/query.pb.go index 8289b99708..e11b0effb0 100644 --- a/x/dex/types/query.pb.go +++ b/x/dex/types/query.pb.go @@ -785,25 +785,24 @@ func (m *QueryAllSettlementsResponse) GetPagination() *query.PageResponse { return nil } -type QueryGetPriceRequest struct { - PriceDenom string `protobuf:"bytes,1,opt,name=priceDenom,proto3" json:"priceDenom,omitempty"` - AssetDenom string `protobuf:"bytes,2,opt,name=assetDenom,proto3" json:"assetDenom,omitempty"` +type QueryGetPricesRequest struct { + PriceDenom Denom `protobuf:"varint,1,opt,name=priceDenom,proto3,enum=seiprotocol.seichain.dex.Denom" json:"priceDenom,omitempty"` + AssetDenom Denom `protobuf:"varint,2,opt,name=assetDenom,proto3,enum=seiprotocol.seichain.dex.Denom" json:"assetDenom,omitempty"` ContractAddr string `protobuf:"bytes,3,opt,name=contractAddr,proto3" json:"contractAddr,omitempty"` - Epoch uint64 `protobuf:"varint,4,opt,name=epoch,proto3" json:"epoch,omitempty"` } -func (m *QueryGetPriceRequest) Reset() { *m = QueryGetPriceRequest{} } -func (m *QueryGetPriceRequest) String() string { return proto.CompactTextString(m) } -func (*QueryGetPriceRequest) ProtoMessage() {} -func (*QueryGetPriceRequest) Descriptor() ([]byte, []int) { +func (m *QueryGetPricesRequest) Reset() { *m = QueryGetPricesRequest{} } +func (m *QueryGetPricesRequest) String() string { return proto.CompactTextString(m) } +func (*QueryGetPricesRequest) ProtoMessage() {} +func (*QueryGetPricesRequest) Descriptor() ([]byte, []int) { return fileDescriptor_d8e98105e6e08a59, []int{14} } -func (m *QueryGetPriceRequest) XXX_Unmarshal(b []byte) error { +func (m *QueryGetPricesRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *QueryGetPriceRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *QueryGetPricesRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_QueryGetPriceRequest.Marshal(b, m, deterministic) + return xxx_messageInfo_QueryGetPricesRequest.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -813,62 +812,151 @@ func (m *QueryGetPriceRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte return b[:n], nil } } -func (m *QueryGetPriceRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_QueryGetPriceRequest.Merge(m, src) +func (m *QueryGetPricesRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryGetPricesRequest.Merge(m, src) } -func (m *QueryGetPriceRequest) XXX_Size() int { +func (m *QueryGetPricesRequest) XXX_Size() int { return m.Size() } -func (m *QueryGetPriceRequest) XXX_DiscardUnknown() { - xxx_messageInfo_QueryGetPriceRequest.DiscardUnknown(m) +func (m *QueryGetPricesRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryGetPricesRequest.DiscardUnknown(m) } -var xxx_messageInfo_QueryGetPriceRequest proto.InternalMessageInfo +var xxx_messageInfo_QueryGetPricesRequest proto.InternalMessageInfo -func (m *QueryGetPriceRequest) GetPriceDenom() string { +func (m *QueryGetPricesRequest) GetPriceDenom() Denom { if m != nil { return m.PriceDenom } - return "" + return Denom_SEI } -func (m *QueryGetPriceRequest) GetAssetDenom() string { +func (m *QueryGetPricesRequest) GetAssetDenom() Denom { if m != nil { return m.AssetDenom } + return Denom_SEI +} + +func (m *QueryGetPricesRequest) GetContractAddr() string { + if m != nil { + return m.ContractAddr + } return "" } -func (m *QueryGetPriceRequest) GetContractAddr() string { +type QueryGetPricesResponse struct { + Prices []*Price `protobuf:"bytes,1,rep,name=prices,proto3" json:"prices,omitempty"` +} + +func (m *QueryGetPricesResponse) Reset() { *m = QueryGetPricesResponse{} } +func (m *QueryGetPricesResponse) String() string { return proto.CompactTextString(m) } +func (*QueryGetPricesResponse) ProtoMessage() {} +func (*QueryGetPricesResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_d8e98105e6e08a59, []int{15} +} +func (m *QueryGetPricesResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryGetPricesResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryGetPricesResponse.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 *QueryGetPricesResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryGetPricesResponse.Merge(m, src) +} +func (m *QueryGetPricesResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryGetPricesResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryGetPricesResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryGetPricesResponse proto.InternalMessageInfo + +func (m *QueryGetPricesResponse) GetPrices() []*Price { + if m != nil { + return m.Prices + } + return nil +} + +type QueryGetTwapsRequest struct { + ContractAddr string `protobuf:"bytes,1,opt,name=contractAddr,proto3" json:"contractAddr,omitempty"` + LookbackSeconds uint64 `protobuf:"varint,2,opt,name=lookbackSeconds,proto3" json:"lookbackSeconds,omitempty"` +} + +func (m *QueryGetTwapsRequest) Reset() { *m = QueryGetTwapsRequest{} } +func (m *QueryGetTwapsRequest) String() string { return proto.CompactTextString(m) } +func (*QueryGetTwapsRequest) ProtoMessage() {} +func (*QueryGetTwapsRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_d8e98105e6e08a59, []int{16} +} +func (m *QueryGetTwapsRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryGetTwapsRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryGetTwapsRequest.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 *QueryGetTwapsRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryGetTwapsRequest.Merge(m, src) +} +func (m *QueryGetTwapsRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryGetTwapsRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryGetTwapsRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryGetTwapsRequest proto.InternalMessageInfo + +func (m *QueryGetTwapsRequest) GetContractAddr() string { if m != nil { return m.ContractAddr } return "" } -func (m *QueryGetPriceRequest) GetEpoch() uint64 { +func (m *QueryGetTwapsRequest) GetLookbackSeconds() uint64 { if m != nil { - return m.Epoch + return m.LookbackSeconds } return 0 } -type QueryGetPriceResponse struct { - Price *Price `protobuf:"bytes,1,opt,name=price,proto3" json:"price,omitempty"` +type QueryGetTwapsResponse struct { + Twaps []*Twap `protobuf:"bytes,1,rep,name=twaps,proto3" json:"twaps,omitempty"` } -func (m *QueryGetPriceResponse) Reset() { *m = QueryGetPriceResponse{} } -func (m *QueryGetPriceResponse) String() string { return proto.CompactTextString(m) } -func (*QueryGetPriceResponse) ProtoMessage() {} -func (*QueryGetPriceResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_d8e98105e6e08a59, []int{15} +func (m *QueryGetTwapsResponse) Reset() { *m = QueryGetTwapsResponse{} } +func (m *QueryGetTwapsResponse) String() string { return proto.CompactTextString(m) } +func (*QueryGetTwapsResponse) ProtoMessage() {} +func (*QueryGetTwapsResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_d8e98105e6e08a59, []int{17} } -func (m *QueryGetPriceResponse) XXX_Unmarshal(b []byte) error { +func (m *QueryGetTwapsResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *QueryGetPriceResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *QueryGetTwapsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_QueryGetPriceResponse.Marshal(b, m, deterministic) + return xxx_messageInfo_QueryGetTwapsResponse.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -878,21 +966,21 @@ func (m *QueryGetPriceResponse) XXX_Marshal(b []byte, deterministic bool) ([]byt return b[:n], nil } } -func (m *QueryGetPriceResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_QueryGetPriceResponse.Merge(m, src) +func (m *QueryGetTwapsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryGetTwapsResponse.Merge(m, src) } -func (m *QueryGetPriceResponse) XXX_Size() int { +func (m *QueryGetTwapsResponse) XXX_Size() int { return m.Size() } -func (m *QueryGetPriceResponse) XXX_DiscardUnknown() { - xxx_messageInfo_QueryGetPriceResponse.DiscardUnknown(m) +func (m *QueryGetTwapsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryGetTwapsResponse.DiscardUnknown(m) } -var xxx_messageInfo_QueryGetPriceResponse proto.InternalMessageInfo +var xxx_messageInfo_QueryGetTwapsResponse proto.InternalMessageInfo -func (m *QueryGetPriceResponse) GetPrice() *Price { +func (m *QueryGetTwapsResponse) GetTwaps() []*Twap { if m != nil { - return m.Price + return m.Twaps } return nil } @@ -912,74 +1000,81 @@ func init() { proto.RegisterType((*QueryGetSettlementsResponse)(nil), "seiprotocol.seichain.dex.QueryGetSettlementsResponse") proto.RegisterType((*QueryAllSettlementsRequest)(nil), "seiprotocol.seichain.dex.QueryAllSettlementsRequest") proto.RegisterType((*QueryAllSettlementsResponse)(nil), "seiprotocol.seichain.dex.QueryAllSettlementsResponse") - proto.RegisterType((*QueryGetPriceRequest)(nil), "seiprotocol.seichain.dex.QueryGetPriceRequest") - proto.RegisterType((*QueryGetPriceResponse)(nil), "seiprotocol.seichain.dex.QueryGetPriceResponse") + proto.RegisterType((*QueryGetPricesRequest)(nil), "seiprotocol.seichain.dex.QueryGetPricesRequest") + proto.RegisterType((*QueryGetPricesResponse)(nil), "seiprotocol.seichain.dex.QueryGetPricesResponse") + proto.RegisterType((*QueryGetTwapsRequest)(nil), "seiprotocol.seichain.dex.QueryGetTwapsRequest") + proto.RegisterType((*QueryGetTwapsResponse)(nil), "seiprotocol.seichain.dex.QueryGetTwapsResponse") } func init() { proto.RegisterFile("dex/query.proto", fileDescriptor_d8e98105e6e08a59) } var fileDescriptor_d8e98105e6e08a59 = []byte{ - // 957 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe4, 0x57, 0x4d, 0x6f, 0xeb, 0x44, - 0x14, 0xcd, 0x24, 0x69, 0xf5, 0xde, 0xe4, 0xe9, 0x81, 0xa6, 0x41, 0x04, 0x83, 0xdc, 0xe0, 0xaa, - 0xb4, 0x20, 0x62, 0xab, 0x29, 0xdd, 0x82, 0x5a, 0x55, 0x4d, 0x17, 0xb4, 0x84, 0xa0, 0x16, 0x84, - 0x04, 0xc5, 0x71, 0x46, 0x8e, 0x55, 0xc7, 0xe3, 0xc6, 0x13, 0xd4, 0xaa, 0xca, 0x86, 0x0d, 0x2c, - 0x2b, 0xf1, 0x2b, 0x90, 0x60, 0xc9, 0x8a, 0x3f, 0x50, 0x89, 0x05, 0x45, 0x7c, 0x88, 0x15, 0x42, - 0x6d, 0x7f, 0x08, 0xf2, 0xcc, 0xf8, 0x23, 0xb1, 0xf3, 0x55, 0xb2, 0x00, 0xde, 0xae, 0xb9, 0x73, - 0xcf, 0xdc, 0x7b, 0xce, 0x3d, 0x9e, 0x99, 0xc2, 0xe7, 0x5a, 0xf8, 0x5c, 0x3b, 0xeb, 0xe1, 0xee, - 0x85, 0xea, 0x76, 0x09, 0x25, 0xa8, 0xe4, 0x61, 0x8b, 0xfd, 0x65, 0x10, 0x5b, 0xf5, 0xb0, 0x65, - 0xb4, 0x75, 0xcb, 0x51, 0x5b, 0xf8, 0x5c, 0x2a, 0x9a, 0xc4, 0x24, 0x6c, 0x49, 0xf3, 0xff, 0xe2, - 0xf9, 0xd2, 0x2b, 0x26, 0x21, 0xa6, 0x8d, 0x35, 0xdd, 0xb5, 0x34, 0xdd, 0x71, 0x08, 0xd5, 0xa9, - 0x45, 0x1c, 0x4f, 0xac, 0xbe, 0x61, 0x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, 0x22, 0xda, 0xfb, 0x84, - 0xb5, 0xf7, 0x21, 0x3a, 0x1a, 0xd3, 0x5e, 0xf8, 0x7e, 0xd6, 0x2e, 0xe3, 0x23, 0xeb, 0x6b, 0x97, - 0x91, 0x07, 0xfa, 0xda, 0x65, 0x34, 0xf0, 0x60, 0xa5, 0x8f, 0x7e, 0x04, 0xb0, 0x10, 0xd4, 0xdc, - 0xb6, 0xed, 0x89, 0xac, 0x92, 0x8f, 0xb3, 0x89, 0xac, 0x52, 0x5e, 0x31, 0xca, 0x11, 0x63, 0xf5, - 0x1e, 0x3a, 0x98, 0x2b, 0x2b, 0xf4, 0x2b, 0x88, 0x5d, 0x13, 0x68, 0x0a, 0xb9, 0x87, 0xef, 0x5c, - 0x69, 0x73, 0x26, 0x8c, 0x60, 0xf3, 0x29, 0x63, 0xf3, 0x11, 0x3a, 0x1e, 0xc3, 0x26, 0xfa, 0x77, - 0x66, 0xf6, 0x21, 0xfd, 0x04, 0xe0, 0x93, 0xb0, 0xaa, 0x3f, 0xa5, 0x29, 0x24, 0x9f, 0x99, 0x59, - 0xda, 0xb5, 0xab, 0x1c, 0x33, 0x66, 0x75, 0x74, 0x38, 0x5f, 0x66, 0xe8, 0x5b, 0x00, 0x9f, 0xc6, - 0x8e, 0x48, 0x9f, 0xd3, 0x5b, 0x53, 0xf4, 0x97, 0xb8, 0x12, 0xa4, 0xad, 0x19, 0x51, 0x82, 0x57, - 0x85, 0xf1, 0x5a, 0x43, 0xab, 0xe3, 0x78, 0x85, 0x38, 0xf4, 0x03, 0x80, 0x8f, 0x82, 0x13, 0x0e, - 0xa9, 0x93, 0x2d, 0x12, 0x3f, 0x9c, 0x25, 0x6d, 0xea, 0x7c, 0xd1, 0xdc, 0x21, 0x6b, 0x6e, 0x1f, - 0xed, 0x8d, 0x69, 0xce, 0xc4, 0xf4, 0x84, 0xa9, 0x3b, 0xce, 0x3e, 0xec, 0x88, 0xee, 0xef, 0xd4, - 0xae, 0x6f, 0x65, 0x70, 0x73, 0x2b, 0x83, 0xbf, 0x6e, 0x65, 0x70, 0x75, 0x27, 0x67, 0x6e, 0xee, - 0xe4, 0xcc, 0x1f, 0x77, 0x72, 0xe6, 0xe3, 0x8a, 0x69, 0xd1, 0x76, 0xaf, 0xa9, 0x1a, 0xa4, 0x93, - 0xa8, 0x55, 0xe1, 0xc5, 0xce, 0x59, 0x39, 0x7a, 0xe1, 0x62, 0xaf, 0xb9, 0xc8, 0xd6, 0x37, 0xff, - 0x0e, 0x00, 0x00, 0xff, 0xff, 0x57, 0x6a, 0xd2, 0x61, 0x52, 0x10, 0x00, 0x00, + // 1033 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe4, 0x57, 0xcf, 0x6f, 0x1b, 0x45, + 0x14, 0xce, 0xd8, 0x49, 0xd4, 0xbc, 0x44, 0x29, 0x9a, 0x1a, 0x30, 0x0b, 0x72, 0xc3, 0x54, 0xa5, + 0x01, 0xe1, 0x5d, 0x92, 0x16, 0x71, 0x03, 0x25, 0x2a, 0x98, 0x03, 0x81, 0xd4, 0x25, 0x05, 0x21, + 0x41, 0x59, 0xaf, 0x47, 0x9b, 0x95, 0xd7, 0x3b, 0x5b, 0xef, 0x84, 0xa6, 0x8a, 0x7c, 0xe1, 0x02, + 0xc7, 0x4a, 0x9c, 0xf8, 0x13, 0x90, 0xe0, 0xc8, 0x05, 0x89, 0x2b, 0xaa, 0xc4, 0x81, 0x48, 0xfc, + 0x10, 0x27, 0x84, 0x92, 0xfe, 0x21, 0x68, 0x67, 0xdf, 0xfe, 0xb0, 0xd7, 0x3f, 0x1b, 0x1f, 0x80, + 0xde, 0xec, 0x37, 0xef, 0x9b, 0xf7, 0xbe, 0xef, 0x7d, 0xbb, 0x33, 0x0b, 0xe7, 0x9b, 0xfc, 0xd0, + 0xb8, 0x73, 0xc0, 0x3b, 0xf7, 0x74, 0xbf, 0x23, 0xa4, 0xa0, 0xe5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x12, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -1005,8 +1100,8 @@ type QueryClient interface { // Queries a list of ShortBook items. ShortBookAll(ctx context.Context, in *QueryAllShortBookRequest, opts ...grpc.CallOption) (*QueryAllShortBookResponse, error) SettlementsAll(ctx context.Context, in *QueryAllSettlementsRequest, opts ...grpc.CallOption) (*QueryAllSettlementsResponse, error) - // Queries a list of GetPrice items. - GetPrice(ctx context.Context, in *QueryGetPriceRequest, opts ...grpc.CallOption) (*QueryGetPriceResponse, error) + GetPrices(ctx context.Context, in *QueryGetPricesRequest, opts ...grpc.CallOption) (*QueryGetPricesResponse, error) + GetTwaps(ctx context.Context, in *QueryGetTwapsRequest, opts ...grpc.CallOption) (*QueryGetTwapsResponse, error) } type queryClient struct { @@ -1071,9 +1166,18 @@ func (c *queryClient) SettlementsAll(ctx context.Context, in *QueryAllSettlement return out, nil } -func (c *queryClient) GetPrice(ctx context.Context, in *QueryGetPriceRequest, opts ...grpc.CallOption) (*QueryGetPriceResponse, error) { - out := new(QueryGetPriceResponse) - err := c.cc.Invoke(ctx, "/seiprotocol.seichain.dex.Query/GetPrice", in, out, opts...) +func (c *queryClient) GetPrices(ctx context.Context, in *QueryGetPricesRequest, opts ...grpc.CallOption) (*QueryGetPricesResponse, error) { + out := new(QueryGetPricesResponse) + err := c.cc.Invoke(ctx, "/seiprotocol.seichain.dex.Query/GetPrices", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) GetTwaps(ctx context.Context, in *QueryGetTwapsRequest, opts ...grpc.CallOption) (*QueryGetTwapsResponse, error) { + out := new(QueryGetTwapsResponse) + err := c.cc.Invoke(ctx, "/seiprotocol.seichain.dex.Query/GetTwaps", in, out, opts...) if err != nil { return nil, err } @@ -1093,8 +1197,8 @@ type QueryServer interface { // Queries a list of ShortBook items. ShortBookAll(context.Context, *QueryAllShortBookRequest) (*QueryAllShortBookResponse, error) SettlementsAll(context.Context, *QueryAllSettlementsRequest) (*QueryAllSettlementsResponse, error) - // Queries a list of GetPrice items. - GetPrice(context.Context, *QueryGetPriceRequest) (*QueryGetPriceResponse, error) + GetPrices(context.Context, *QueryGetPricesRequest) (*QueryGetPricesResponse, error) + GetTwaps(context.Context, *QueryGetTwapsRequest) (*QueryGetTwapsResponse, error) } // UnimplementedQueryServer can be embedded to have forward compatible implementations. @@ -1119,8 +1223,11 @@ func (*UnimplementedQueryServer) ShortBookAll(ctx context.Context, req *QueryAll func (*UnimplementedQueryServer) SettlementsAll(ctx context.Context, req *QueryAllSettlementsRequest) (*QueryAllSettlementsResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method SettlementsAll not implemented") } -func (*UnimplementedQueryServer) GetPrice(ctx context.Context, req *QueryGetPriceRequest) (*QueryGetPriceResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method GetPrice not implemented") +func (*UnimplementedQueryServer) GetPrices(ctx context.Context, req *QueryGetPricesRequest) (*QueryGetPricesResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetPrices not implemented") +} +func (*UnimplementedQueryServer) GetTwaps(ctx context.Context, req *QueryGetTwapsRequest) (*QueryGetTwapsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetTwaps not implemented") } func RegisterQueryServer(s grpc1.Server, srv QueryServer) { @@ -1235,20 +1342,38 @@ func _Query_SettlementsAll_Handler(srv interface{}, ctx context.Context, dec fun return interceptor(ctx, in, info, handler) } -func _Query_GetPrice_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(QueryGetPriceRequest) +func _Query_GetPrices_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryGetPricesRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).GetPrices(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/seiprotocol.seichain.dex.Query/GetPrices", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).GetPrices(ctx, req.(*QueryGetPricesRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_GetTwaps_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryGetTwapsRequest) if err := dec(in); err != nil { return nil, err } if interceptor == nil { - return srv.(QueryServer).GetPrice(ctx, in) + return srv.(QueryServer).GetTwaps(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/seiprotocol.seichain.dex.Query/GetPrice", + FullMethod: "/seiprotocol.seichain.dex.Query/GetTwaps", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(QueryServer).GetPrice(ctx, req.(*QueryGetPriceRequest)) + return srv.(QueryServer).GetTwaps(ctx, req.(*QueryGetTwapsRequest)) } return interceptor(ctx, in, info, handler) } @@ -1282,8 +1407,12 @@ var _Query_serviceDesc = grpc.ServiceDesc{ Handler: _Query_SettlementsAll_Handler, }, { - MethodName: "GetPrice", - Handler: _Query_GetPrice_Handler, + MethodName: "GetPrices", + Handler: _Query_GetPrices_Handler, + }, + { + MethodName: "GetTwaps", + Handler: _Query_GetTwaps_Handler, }, }, Streams: []grpc.StreamDesc{}, @@ -1870,7 +1999,7 @@ func (m *QueryAllSettlementsResponse) MarshalToSizedBuffer(dAtA []byte) (int, er return len(dAtA) - i, nil } -func (m *QueryGetPriceRequest) Marshal() (dAtA []byte, err error) { +func (m *QueryGetPricesRequest) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -1880,21 +2009,16 @@ func (m *QueryGetPriceRequest) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *QueryGetPriceRequest) MarshalTo(dAtA []byte) (int, error) { +func (m *QueryGetPricesRequest) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *QueryGetPriceRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *QueryGetPricesRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int _ = l - if m.Epoch != 0 { - i = encodeVarintQuery(dAtA, i, uint64(m.Epoch)) - i-- - dAtA[i] = 0x20 - } if len(m.ContractAddr) > 0 { i -= len(m.ContractAddr) copy(dAtA[i:], m.ContractAddr) @@ -1902,24 +2026,20 @@ func (m *QueryGetPriceRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { i-- dAtA[i] = 0x1a } - if len(m.AssetDenom) > 0 { - i -= len(m.AssetDenom) - copy(dAtA[i:], m.AssetDenom) - i = encodeVarintQuery(dAtA, i, uint64(len(m.AssetDenom))) + if m.AssetDenom != 0 { + i = encodeVarintQuery(dAtA, i, uint64(m.AssetDenom)) i-- - dAtA[i] = 0x12 + dAtA[i] = 0x10 } - if len(m.PriceDenom) > 0 { - i -= len(m.PriceDenom) - copy(dAtA[i:], m.PriceDenom) - i = encodeVarintQuery(dAtA, i, uint64(len(m.PriceDenom))) + if m.PriceDenom != 0 { + i = encodeVarintQuery(dAtA, i, uint64(m.PriceDenom)) i-- - dAtA[i] = 0xa + dAtA[i] = 0x8 } return len(dAtA) - i, nil } -func (m *QueryGetPriceResponse) Marshal() (dAtA []byte, err error) { +func (m *QueryGetPricesResponse) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -1929,31 +2049,105 @@ func (m *QueryGetPriceResponse) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *QueryGetPriceResponse) MarshalTo(dAtA []byte) (int, error) { +func (m *QueryGetPricesResponse) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *QueryGetPriceResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *QueryGetPricesResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int _ = l - if m.Price != nil { - { - size, err := m.Price.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err + 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 = encodeVarintQuery(dAtA, i, uint64(size)) } - i -= size - i = encodeVarintQuery(dAtA, i, uint64(size)) + i-- + dAtA[i] = 0xa } + } + return len(dAtA) - i, nil +} + +func (m *QueryGetTwapsRequest) 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 *QueryGetTwapsRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryGetTwapsRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.LookbackSeconds != 0 { + i = encodeVarintQuery(dAtA, i, uint64(m.LookbackSeconds)) + i-- + dAtA[i] = 0x10 + } + if len(m.ContractAddr) > 0 { + i -= len(m.ContractAddr) + copy(dAtA[i:], m.ContractAddr) + i = encodeVarintQuery(dAtA, i, uint64(len(m.ContractAddr))) i-- dAtA[i] = 0xa } return len(dAtA) - i, nil } +func (m *QueryGetTwapsResponse) 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 *QueryGetTwapsResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryGetTwapsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Twaps) > 0 { + for iNdEx := len(m.Twaps) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Twaps[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + func encodeVarintQuery(dAtA []byte, offset int, v uint64) int { offset -= sovQuery(v) base := offset @@ -2202,39 +2396,67 @@ func (m *QueryAllSettlementsResponse) Size() (n int) { return n } -func (m *QueryGetPriceRequest) Size() (n int) { +func (m *QueryGetPricesRequest) Size() (n int) { if m == nil { return 0 } var l int _ = l - l = len(m.PriceDenom) - if l > 0 { - n += 1 + l + sovQuery(uint64(l)) + if m.PriceDenom != 0 { + n += 1 + sovQuery(uint64(m.PriceDenom)) } - l = len(m.AssetDenom) + if m.AssetDenom != 0 { + n += 1 + sovQuery(uint64(m.AssetDenom)) + } + l = len(m.ContractAddr) if l > 0 { n += 1 + l + sovQuery(uint64(l)) } + return n +} + +func (m *QueryGetPricesResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.Prices) > 0 { + for _, e := range m.Prices { + l = e.Size() + n += 1 + l + sovQuery(uint64(l)) + } + } + return n +} + +func (m *QueryGetTwapsRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l l = len(m.ContractAddr) if l > 0 { n += 1 + l + sovQuery(uint64(l)) } - if m.Epoch != 0 { - n += 1 + sovQuery(uint64(m.Epoch)) + if m.LookbackSeconds != 0 { + n += 1 + sovQuery(uint64(m.LookbackSeconds)) } return n } -func (m *QueryGetPriceResponse) Size() (n int) { +func (m *QueryGetTwapsResponse) Size() (n int) { if m == nil { return 0 } var l int _ = l - if m.Price != nil { - l = m.Price.Size() - n += 1 + l + sovQuery(uint64(l)) + if len(m.Twaps) > 0 { + for _, e := range m.Twaps { + l = e.Size() + n += 1 + l + sovQuery(uint64(l)) + } } return n } @@ -3828,7 +4050,7 @@ func (m *QueryAllSettlementsResponse) Unmarshal(dAtA []byte) error { } return nil } -func (m *QueryGetPriceRequest) Unmarshal(dAtA []byte) error { +func (m *QueryGetPricesRequest) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -3851,16 +4073,54 @@ func (m *QueryGetPriceRequest) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: QueryGetPriceRequest: wiretype end group for non-group") + return fmt.Errorf("proto: QueryGetPricesRequest: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: QueryGetPriceRequest: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: QueryGetPricesRequest: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: - if wireType != 2 { + if wireType != 0 { return fmt.Errorf("proto: wrong wireType = %d for field PriceDenom", wireType) } + m.PriceDenom = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.PriceDenom |= Denom(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field AssetDenom", wireType) + } + m.AssetDenom = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.AssetDenom |= Denom(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ContractAddr", wireType) + } var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { @@ -3887,13 +4147,63 @@ func (m *QueryGetPriceRequest) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.PriceDenom = string(dAtA[iNdEx:postIndex]) + m.ContractAddr = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex - case 2: + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryGetPricesResponse) 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 ErrIntOverflowQuery + } + 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: QueryGetPricesResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryGetPricesResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field AssetDenom", 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 ErrIntOverflowQuery @@ -3903,25 +4213,77 @@ func (m *QueryGetPriceRequest) 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 ErrInvalidLengthQuery } - postIndex := iNdEx + intStringLen + postIndex := iNdEx + msglen if postIndex < 0 { return ErrInvalidLengthQuery } if postIndex > l { return io.ErrUnexpectedEOF } - m.AssetDenom = string(dAtA[iNdEx:postIndex]) + m.Prices = append(m.Prices, &Price{}) + if err := m.Prices[len(m.Prices)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } iNdEx = postIndex - case 3: + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryGetTwapsRequest) 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 ErrIntOverflowQuery + } + 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: QueryGetTwapsRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryGetTwapsRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field ContractAddr", wireType) } @@ -3953,11 +4315,11 @@ func (m *QueryGetPriceRequest) Unmarshal(dAtA []byte) error { } m.ContractAddr = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex - case 4: + case 2: if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Epoch", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field LookbackSeconds", wireType) } - m.Epoch = 0 + m.LookbackSeconds = 0 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowQuery @@ -3967,7 +4329,7 @@ func (m *QueryGetPriceRequest) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.Epoch |= uint64(b&0x7F) << shift + m.LookbackSeconds |= uint64(b&0x7F) << shift if b < 0x80 { break } @@ -3993,7 +4355,7 @@ func (m *QueryGetPriceRequest) Unmarshal(dAtA []byte) error { } return nil } -func (m *QueryGetPriceResponse) Unmarshal(dAtA []byte) error { +func (m *QueryGetTwapsResponse) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -4016,15 +4378,15 @@ func (m *QueryGetPriceResponse) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: QueryGetPriceResponse: wiretype end group for non-group") + return fmt.Errorf("proto: QueryGetTwapsResponse: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: QueryGetPriceResponse: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: QueryGetTwapsResponse: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Price", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Twaps", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -4051,10 +4413,8 @@ func (m *QueryGetPriceResponse) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if m.Price == nil { - m.Price = &Price{} - } - if err := m.Price.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + m.Twaps = append(m.Twaps, &Twap{}) + if err := m.Twaps[len(m.Twaps)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex diff --git a/x/dex/types/query.pb.gw.go b/x/dex/types/query.pb.gw.go index 613ae97a3f..93360c07a4 100644 --- a/x/dex/types/query.pb.gw.go +++ b/x/dex/types/query.pb.gw.go @@ -599,68 +599,116 @@ func local_request_Query_SettlementsAll_0(ctx context.Context, marshaler runtime } -var ( - filter_Query_GetPrice_0 = &utilities.DoubleArray{Encoding: map[string]int{"priceDenom": 0, "assetDenom": 1, "epoch": 2}, Base: []int{1, 1, 2, 3, 0, 0, 0}, Check: []int{0, 1, 1, 1, 2, 3, 4}} -) - -func request_Query_GetPrice_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq QueryGetPriceRequest +func request_Query_GetPrices_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryGetPricesRequest var metadata runtime.ServerMetadata var ( val string + e int32 ok bool err error _ = err ) + val, ok = pathParams["contractAddr"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "contractAddr") + } + + protoReq.ContractAddr, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "contractAddr", err) + } + val, ok = pathParams["priceDenom"] if !ok { return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "priceDenom") } - protoReq.PriceDenom, err = runtime.String(val) + e, err = runtime.Enum(val, Denom_value) if err != nil { return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "priceDenom", err) } + protoReq.PriceDenom = Denom(e) + val, ok = pathParams["assetDenom"] if !ok { return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "assetDenom") } - protoReq.AssetDenom, err = runtime.String(val) + e, err = runtime.Enum(val, Denom_value) if err != nil { return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "assetDenom", err) } - val, ok = pathParams["epoch"] + protoReq.AssetDenom = Denom(e) + + msg, err := client.GetPrices(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_GetPrices_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryGetPricesRequest + var metadata runtime.ServerMetadata + + var ( + val string + e int32 + ok bool + err error + _ = err + ) + + val, ok = pathParams["contractAddr"] if !ok { - return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "epoch") + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "contractAddr") } - protoReq.Epoch, err = runtime.Uint64(val) + protoReq.ContractAddr, err = runtime.String(val) if err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "epoch", err) + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "contractAddr", err) } - if err := req.ParseForm(); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + val, ok = pathParams["priceDenom"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "priceDenom") } - if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_GetPrice_0); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + + e, err = runtime.Enum(val, Denom_value) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "priceDenom", err) + } + + protoReq.PriceDenom = Denom(e) + + val, ok = pathParams["assetDenom"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "assetDenom") } - msg, err := client.GetPrice(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + e, err = runtime.Enum(val, Denom_value) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "assetDenom", err) + } + + protoReq.AssetDenom = Denom(e) + + msg, err := server.GetPrices(ctx, &protoReq) return msg, metadata, err } -func local_request_Query_GetPrice_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq QueryGetPriceRequest +func request_Query_GetTwaps_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryGetTwapsRequest var metadata runtime.ServerMetadata var ( @@ -670,47 +718,67 @@ func local_request_Query_GetPrice_0(ctx context.Context, marshaler runtime.Marsh _ = err ) - val, ok = pathParams["priceDenom"] + val, ok = pathParams["contractAddr"] if !ok { - return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "priceDenom") + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "contractAddr") } - protoReq.PriceDenom, err = runtime.String(val) + protoReq.ContractAddr, err = runtime.String(val) if err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "priceDenom", err) + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "contractAddr", err) } - val, ok = pathParams["assetDenom"] + val, ok = pathParams["lookbackSeconds"] if !ok { - return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "assetDenom") + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "lookbackSeconds") } - protoReq.AssetDenom, err = runtime.String(val) + protoReq.LookbackSeconds, err = runtime.Uint64(val) if err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "assetDenom", err) + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "lookbackSeconds", err) } - val, ok = pathParams["epoch"] + msg, err := client.GetTwaps(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_GetTwaps_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryGetTwapsRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["contractAddr"] if !ok { - return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "epoch") + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "contractAddr") } - protoReq.Epoch, err = runtime.Uint64(val) + protoReq.ContractAddr, err = runtime.String(val) if err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "epoch", err) + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "contractAddr", err) } - if err := req.ParseForm(); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + val, ok = pathParams["lookbackSeconds"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "lookbackSeconds") } - if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_GetPrice_0); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + + protoReq.LookbackSeconds, err = runtime.Uint64(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "lookbackSeconds", err) } - msg, err := server.GetPrice(ctx, &protoReq) + msg, err := server.GetTwaps(ctx, &protoReq) return msg, metadata, err } @@ -859,7 +927,7 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv }) - mux.Handle("GET", pattern_Query_GetPrice_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + mux.Handle("GET", pattern_Query_GetPrices_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() var stream runtime.ServerTransportStream @@ -870,7 +938,7 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := local_request_Query_GetPrice_0(rctx, inboundMarshaler, server, req, pathParams) + resp, md, err := local_request_Query_GetPrices_0(rctx, inboundMarshaler, server, req, pathParams) md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { @@ -878,7 +946,30 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv return } - forward_Query_GetPrice_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_Query_GetPrices_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_GetTwaps_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_GetTwaps_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_GetTwaps_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -1043,7 +1134,27 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie }) - mux.Handle("GET", pattern_Query_GetPrice_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + mux.Handle("GET", pattern_Query_GetPrices_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_GetPrices_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_GetPrices_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_GetTwaps_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) @@ -1052,14 +1163,14 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := request_Query_GetPrice_0(rctx, inboundMarshaler, client, req, pathParams) + resp, md, err := request_Query_GetTwaps_0(rctx, inboundMarshaler, client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - forward_Query_GetPrice_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_Query_GetTwaps_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -1079,7 +1190,9 @@ var ( pattern_Query_SettlementsAll_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"sei-protocol", "seichain", "dex", "settlement"}, "", runtime.AssumeColonVerbOpt(true))) - pattern_Query_GetPrice_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4, 1, 0, 4, 1, 5, 5, 1, 0, 4, 1, 5, 6}, []string{"sei-protocol", "seichain", "dex", "get_price", "priceDenom", "assetDenom", "epoch"}, "", runtime.AssumeColonVerbOpt(true))) + pattern_Query_GetPrices_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4, 1, 0, 4, 1, 5, 5, 1, 0, 4, 1, 5, 6}, []string{"sei-protocol", "seichain", "dex", "get_prices", "contractAddr", "priceDenom", "assetDenom"}, "", runtime.AssumeColonVerbOpt(true))) + + pattern_Query_GetTwaps_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4, 1, 0, 4, 1, 5, 5}, []string{"sei-protocol", "seichain", "dex", "get_twaps", "contractAddr", "lookbackSeconds"}, "", runtime.AssumeColonVerbOpt(true))) ) var ( @@ -1095,5 +1208,7 @@ var ( forward_Query_SettlementsAll_0 = runtime.ForwardResponseMessage - forward_Query_GetPrice_0 = runtime.ForwardResponseMessage + forward_Query_GetPrices_0 = runtime.ForwardResponseMessage + + forward_Query_GetTwaps_0 = runtime.ForwardResponseMessage ) diff --git a/x/dex/types/twap.pb.go b/x/dex/types/twap.pb.go index 699fe0d6b3..8307ea0114 100644 --- a/x/dex/types/twap.pb.go +++ b/x/dex/types/twap.pb.go @@ -5,6 +5,8 @@ package types import ( fmt "fmt" + github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" + _ "github.com/gogo/protobuf/gogoproto" proto "github.com/gogo/protobuf/proto" io "io" math "math" @@ -22,13 +24,10 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package -// deprecated type Twap struct { - LastEpoch uint64 `protobuf:"varint,1,opt,name=lastEpoch,proto3" json:"lastEpoch,omitempty"` - Prices []uint64 `protobuf:"varint,2,rep,packed,name=prices,proto3" json:"prices,omitempty"` - TwapPrice uint64 `protobuf:"varint,3,opt,name=twapPrice,proto3" json:"twapPrice,omitempty"` - PriceDenom string `protobuf:"bytes,4,opt,name=priceDenom,proto3" json:"priceDenom,omitempty"` - AssetDenom string `protobuf:"bytes,5,opt,name=assetDenom,proto3" json:"assetDenom,omitempty"` + Pair *Pair `protobuf:"bytes,1,opt,name=pair,proto3" json:"pair,omitempty"` + Twap github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,2,opt,name=twap,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"twap" yaml:"twap"` + LookbackSeconds uint64 `protobuf:"varint,3,opt,name=lookbackSeconds,proto3" json:"lookbackSeconds,omitempty"` } func (m *Twap) Reset() { *m = Twap{} } @@ -64,41 +63,20 @@ func (m *Twap) XXX_DiscardUnknown() { var xxx_messageInfo_Twap proto.InternalMessageInfo -func (m *Twap) GetLastEpoch() uint64 { +func (m *Twap) GetPair() *Pair { if m != nil { - return m.LastEpoch - } - return 0 -} - -func (m *Twap) GetPrices() []uint64 { - if m != nil { - return m.Prices + return m.Pair } return nil } -func (m *Twap) GetTwapPrice() uint64 { +func (m *Twap) GetLookbackSeconds() uint64 { if m != nil { - return m.TwapPrice + return m.LookbackSeconds } return 0 } -func (m *Twap) GetPriceDenom() string { - if m != nil { - return m.PriceDenom - } - return "" -} - -func (m *Twap) GetAssetDenom() string { - if m != nil { - return m.AssetDenom - } - return "" -} - func init() { proto.RegisterType((*Twap)(nil), "seiprotocol.seichain.dex.Twap") } @@ -106,21 +84,25 @@ func init() { func init() { proto.RegisterFile("dex/twap.proto", fileDescriptor_10aa4b136085207a) } var fileDescriptor_10aa4b136085207a = []byte{ - // 224 bytes of a gzipped FileDescriptorProto + // 273 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x4b, 0x49, 0xad, 0xd0, 0x2f, 0x29, 0x4f, 0x2c, 0xd0, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x92, 0x28, 0x4e, 0xcd, 0x04, 0xb3, 0x92, 0xf3, 0x73, 0xf4, 0x8a, 0x53, 0x33, 0x93, 0x33, 0x12, 0x33, 0xf3, 0xf4, 0x52, 0x52, - 0x2b, 0x94, 0x66, 0x31, 0x72, 0xb1, 0x84, 0x94, 0x27, 0x16, 0x08, 0xc9, 0x70, 0x71, 0xe6, 0x24, - 0x16, 0x97, 0xb8, 0x16, 0xe4, 0x27, 0x67, 0x48, 0x30, 0x2a, 0x30, 0x6a, 0xb0, 0x04, 0x21, 0x04, - 0x84, 0xc4, 0xb8, 0xd8, 0x0a, 0x8a, 0x32, 0x93, 0x53, 0x8b, 0x25, 0x98, 0x14, 0x98, 0x35, 0x58, - 0x82, 0xa0, 0x3c, 0x90, 0x2e, 0x90, 0x35, 0x01, 0x20, 0x9e, 0x04, 0x33, 0x44, 0x17, 0x5c, 0x40, - 0x48, 0x8e, 0x8b, 0x0b, 0xac, 0xce, 0x25, 0x35, 0x2f, 0x3f, 0x57, 0x82, 0x45, 0x81, 0x51, 0x83, - 0x33, 0x08, 0x49, 0x04, 0x24, 0x9f, 0x58, 0x5c, 0x9c, 0x5a, 0x02, 0x91, 0x67, 0x85, 0xc8, 0x23, - 0x44, 0x9c, 0xdc, 0x4f, 0x3c, 0x92, 0x63, 0xbc, 0xf0, 0x48, 0x8e, 0xf1, 0xc1, 0x23, 0x39, 0xc6, - 0x09, 0x8f, 0xe5, 0x18, 0x2e, 0x3c, 0x96, 0x63, 0xb8, 0xf1, 0x58, 0x8e, 0x21, 0x4a, 0x37, 0x3d, - 0xb3, 0x24, 0xa3, 0x34, 0x49, 0x2f, 0x39, 0x3f, 0x57, 0xbf, 0x38, 0x35, 0x53, 0x17, 0xe6, 0x39, - 0x30, 0x07, 0xec, 0x3b, 0xfd, 0x0a, 0x7d, 0x70, 0x20, 0x54, 0x16, 0xa4, 0x16, 0x27, 0xb1, 0x81, - 0xe5, 0x8d, 0x01, 0x01, 0x00, 0x00, 0xff, 0xff, 0x98, 0x40, 0x0f, 0xa7, 0x18, 0x01, 0x00, 0x00, + 0x2b, 0xa4, 0x44, 0xd2, 0xf3, 0xd3, 0xf3, 0xc1, 0x52, 0xfa, 0x20, 0x16, 0x44, 0xbd, 0x14, 0x58, + 0x7f, 0x41, 0x62, 0x66, 0x11, 0x84, 0xaf, 0xb4, 0x9d, 0x91, 0x8b, 0x25, 0xa4, 0x3c, 0xb1, 0x40, + 0xc8, 0x88, 0x8b, 0x05, 0x24, 0x2c, 0xc1, 0xa8, 0xc0, 0xa8, 0xc1, 0x6d, 0x24, 0xa7, 0x87, 0xcb, + 0x5c, 0xbd, 0x80, 0xc4, 0xcc, 0xa2, 0x20, 0xb0, 0x5a, 0xa1, 0x40, 0x2e, 0x16, 0x90, 0x53, 0x24, + 0x98, 0x14, 0x18, 0x35, 0x38, 0x9d, 0x6c, 0x4f, 0xdc, 0x93, 0x67, 0xb8, 0x75, 0x4f, 0x5e, 0x2d, + 0x3d, 0xb3, 0x24, 0xa3, 0x34, 0x49, 0x2f, 0x39, 0x3f, 0x57, 0x3f, 0x39, 0xbf, 0x38, 0x37, 0xbf, + 0x18, 0x4a, 0xe9, 0x16, 0xa7, 0x64, 0xeb, 0x97, 0x54, 0x16, 0xa4, 0x16, 0xeb, 0xb9, 0xa4, 0x26, + 0x7f, 0xba, 0x27, 0xcf, 0x5d, 0x99, 0x98, 0x9b, 0x63, 0xa5, 0x04, 0x32, 0x43, 0x29, 0x08, 0x6c, + 0x94, 0x90, 0x06, 0x17, 0x7f, 0x4e, 0x7e, 0x7e, 0x76, 0x52, 0x62, 0x72, 0x76, 0x70, 0x6a, 0x72, + 0x7e, 0x5e, 0x4a, 0xb1, 0x04, 0xb3, 0x02, 0xa3, 0x06, 0x4b, 0x10, 0xba, 0xb0, 0x93, 0xfb, 0x89, + 0x47, 0x72, 0x8c, 0x17, 0x1e, 0xc9, 0x31, 0x3e, 0x78, 0x24, 0xc7, 0x38, 0xe1, 0xb1, 0x1c, 0xc3, + 0x85, 0xc7, 0x72, 0x0c, 0x37, 0x1e, 0xcb, 0x31, 0x44, 0xe9, 0x22, 0x39, 0xa0, 0x38, 0x35, 0x53, + 0x17, 0xe6, 0x0f, 0x30, 0x07, 0xec, 0x11, 0xfd, 0x0a, 0x7d, 0x70, 0x38, 0x82, 0xdc, 0x92, 0xc4, + 0x06, 0x96, 0x37, 0x06, 0x04, 0x00, 0x00, 0xff, 0xff, 0x99, 0x67, 0x7b, 0xff, 0x5b, 0x01, 0x00, + 0x00, } func (m *Twap) Marshal() (dAtA []byte, err error) { @@ -143,47 +125,32 @@ func (m *Twap) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if len(m.AssetDenom) > 0 { - i -= len(m.AssetDenom) - copy(dAtA[i:], m.AssetDenom) - i = encodeVarintTwap(dAtA, i, uint64(len(m.AssetDenom))) - i-- - dAtA[i] = 0x2a - } - if len(m.PriceDenom) > 0 { - i -= len(m.PriceDenom) - copy(dAtA[i:], m.PriceDenom) - i = encodeVarintTwap(dAtA, i, uint64(len(m.PriceDenom))) - i-- - dAtA[i] = 0x22 - } - if m.TwapPrice != 0 { - i = encodeVarintTwap(dAtA, i, uint64(m.TwapPrice)) + if m.LookbackSeconds != 0 { + i = encodeVarintTwap(dAtA, i, uint64(m.LookbackSeconds)) i-- dAtA[i] = 0x18 } - if len(m.Prices) > 0 { - dAtA2 := make([]byte, len(m.Prices)*10) - var j1 int - for _, num := range m.Prices { - for num >= 1<<7 { - dAtA2[j1] = uint8(uint64(num)&0x7f | 0x80) - num >>= 7 - j1++ - } - dAtA2[j1] = uint8(num) - j1++ + { + size := m.Twap.Size() + i -= size + if _, err := m.Twap.MarshalTo(dAtA[i:]); err != nil { + return 0, err } - i -= j1 - copy(dAtA[i:], dAtA2[:j1]) - i = encodeVarintTwap(dAtA, i, uint64(j1)) - i-- - dAtA[i] = 0x12 + i = encodeVarintTwap(dAtA, i, uint64(size)) } - if m.LastEpoch != 0 { - i = encodeVarintTwap(dAtA, i, uint64(m.LastEpoch)) + i-- + dAtA[i] = 0x12 + if m.Pair != nil { + { + size, err := m.Pair.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTwap(dAtA, i, uint64(size)) + } i-- - dAtA[i] = 0x8 + dAtA[i] = 0xa } return len(dAtA) - i, nil } @@ -205,26 +172,14 @@ func (m *Twap) Size() (n int) { } var l int _ = l - if m.LastEpoch != 0 { - n += 1 + sovTwap(uint64(m.LastEpoch)) - } - if len(m.Prices) > 0 { - l = 0 - for _, e := range m.Prices { - l += sovTwap(uint64(e)) - } - n += 1 + sovTwap(uint64(l)) + l - } - if m.TwapPrice != 0 { - n += 1 + sovTwap(uint64(m.TwapPrice)) - } - l = len(m.PriceDenom) - if l > 0 { + if m.Pair != nil { + l = m.Pair.Size() n += 1 + l + sovTwap(uint64(l)) } - l = len(m.AssetDenom) - if l > 0 { - n += 1 + l + sovTwap(uint64(l)) + l = m.Twap.Size() + n += 1 + l + sovTwap(uint64(l)) + if m.LookbackSeconds != 0 { + n += 1 + sovTwap(uint64(m.LookbackSeconds)) } return n } @@ -265,10 +220,10 @@ func (m *Twap) Unmarshal(dAtA []byte) error { } switch fieldNum { case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field LastEpoch", wireType) + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Pair", wireType) } - m.LastEpoch = 0 + var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowTwap @@ -278,109 +233,31 @@ func (m *Twap) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.LastEpoch |= uint64(b&0x7F) << shift + msglen |= int(b&0x7F) << shift if b < 0x80 { break } } - case 2: - if wireType == 0 { - var v uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTwap - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - m.Prices = append(m.Prices, v) - } else if wireType == 2 { - var packedLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTwap - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - packedLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if packedLen < 0 { - return ErrInvalidLengthTwap - } - postIndex := iNdEx + packedLen - if postIndex < 0 { - return ErrInvalidLengthTwap - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - var elementCount int - var count int - for _, integer := range dAtA[iNdEx:postIndex] { - if integer < 128 { - count++ - } - } - elementCount = count - if elementCount != 0 && len(m.Prices) == 0 { - m.Prices = make([]uint64, 0, elementCount) - } - for iNdEx < postIndex { - var v uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTwap - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - m.Prices = append(m.Prices, v) - } - } else { - return fmt.Errorf("proto: wrong wireType = %d for field Prices", wireType) + if msglen < 0 { + return ErrInvalidLengthTwap } - case 3: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field TwapPrice", wireType) + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTwap } - m.TwapPrice = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTwap - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.TwapPrice |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } + if postIndex > l { + return io.ErrUnexpectedEOF } - case 4: + if m.Pair == nil { + m.Pair = &Pair{} + } + if err := m.Pair.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field PriceDenom", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Twap", wireType) } var stringLen uint64 for shift := uint(0); ; shift += 7 { @@ -408,13 +285,15 @@ func (m *Twap) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.PriceDenom = string(dAtA[iNdEx:postIndex]) + if err := m.Twap.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } iNdEx = postIndex - case 5: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field AssetDenom", wireType) + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field LookbackSeconds", wireType) } - var stringLen uint64 + m.LookbackSeconds = 0 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowTwap @@ -424,24 +303,11 @@ func (m *Twap) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - stringLen |= uint64(b&0x7F) << shift + m.LookbackSeconds |= uint64(b&0x7F) << shift if b < 0x80 { break } } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthTwap - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthTwap - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.AssetDenom = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipTwap(dAtA[iNdEx:]) From 5d8e5cb6811895e3ae55475ca65355358610be47 Mon Sep 17 00:00:00 2001 From: Xiaoyu Chen Date: Fri, 10 Jun 2022 13:17:26 -0700 Subject: [PATCH 4/5] nit --- app/app.go | 2 +- x/dex/module.go | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/app/app.go b/app/app.go index 5a60d5d615..ebcb04bd3b 100644 --- a/app/app.go +++ b/app/app.go @@ -490,7 +490,7 @@ func New( app.BankKeeper, app.WasmKeeper, ) - dexModule := dexmodule.NewAppModule(appCodec, app.DexKeeper, app.AccountKeeper, app.BankKeeper, app.WasmKeeper, app.OracleKeeper, app.tracingInfo) + dexModule := dexmodule.NewAppModule(appCodec, app.DexKeeper, app.AccountKeeper, app.BankKeeper, app.WasmKeeper, app.tracingInfo) epochModule := epochmodule.NewAppModule(appCodec, app.EpochKeeper, app.AccountKeeper, app.BankKeeper) // this line is used by starport scaffolding # stargate/app/keeperDefinition diff --git a/x/dex/module.go b/x/dex/module.go index 0ac50f2bc0..bfd4793877 100644 --- a/x/dex/module.go +++ b/x/dex/module.go @@ -25,7 +25,6 @@ import ( "github.com/sei-protocol/sei-chain/x/dex/keeper" "github.com/sei-protocol/sei-chain/x/dex/migrations" "github.com/sei-protocol/sei-chain/x/dex/types" - oraclekeeper "github.com/sei-protocol/sei-chain/x/oracle/keeper" ) var ( @@ -109,7 +108,6 @@ type AppModule struct { accountKeeper types.AccountKeeper bankKeeper types.BankKeeper wasmKeeper wasm.Keeper - oracleKeeper oraclekeeper.Keeper tracingInfo *tracing.TracingInfo } @@ -120,7 +118,6 @@ func NewAppModule( accountKeeper types.AccountKeeper, bankKeeper types.BankKeeper, wasmKeeper wasm.Keeper, - oracleKeeper oraclekeeper.Keeper, tracingInfo *tracing.TracingInfo, ) AppModule { return AppModule{ @@ -129,7 +126,6 @@ func NewAppModule( accountKeeper: accountKeeper, bankKeeper: bankKeeper, wasmKeeper: wasmKeeper, - oracleKeeper: oracleKeeper, tracingInfo: tracingInfo, } } From a28779b4d8f5d76ab073536e31933a4c8b278285 Mon Sep 17 00:00:00 2001 From: Xiaoyu Chen Date: Wed, 15 Jun 2022 10:21:43 -0700 Subject: [PATCH 5/5] fix twap edge case --- x/dex/keeper/grpc_query_get_twaps.go | 4 ++++ x/dex/keeper/grpc_query_get_twaps_test.go | 4 ++-- x/dex/types/params.go | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/x/dex/keeper/grpc_query_get_twaps.go b/x/dex/keeper/grpc_query_get_twaps.go index 2f3fbaa4db..509391e65a 100644 --- a/x/dex/keeper/grpc_query_get_twaps.go +++ b/x/dex/keeper/grpc_query_get_twaps.go @@ -42,6 +42,10 @@ func calculateTwap(ctx sdk.Context, prices []*types.Price, lookback uint64) sdk. for _, price := range prices { newTimeTraversed := uint64(ctx.BlockTime().Unix()) - price.SnapshotTimestampInSeconds if newTimeTraversed > lookback { + weightedPriceSum = weightedPriceSum.Add( + price.Price.MulInt64(int64(lookback - timeTraversed)), + ) + timeTraversed = lookback break } weightedPriceSum = weightedPriceSum.Add( diff --git a/x/dex/keeper/grpc_query_get_twaps_test.go b/x/dex/keeper/grpc_query_get_twaps_test.go index 82172396ce..24f0e385b7 100644 --- a/x/dex/keeper/grpc_query_get_twaps_test.go +++ b/x/dex/keeper/grpc_query_get_twaps_test.go @@ -84,12 +84,12 @@ func TestGetTwapsOnePriceSnapshot(t *testing.T) { Twaps: []*types.Twap{ { Pair: &TEST_PAIR, - Twap: sdk.ZeroDec(), + Twap: snapshotPrice, LookbackSeconds: lookback, }, }, } - t.Run("One snapshot too old", func(t *testing.T) { + t.Run("One old snapshot", func(t *testing.T) { response, err := keeper.GetTwaps(wctx, &request) require.NoError(t, err) require.Equal(t, expectedResponse, *response) diff --git a/x/dex/types/params.go b/x/dex/types/params.go index 43b1193238..62b33f074b 100644 --- a/x/dex/types/params.go +++ b/x/dex/types/params.go @@ -12,7 +12,7 @@ var ( ) const ( - DefaultPriceSnapshotRetention = 60 // default epoch interval is one minute so this results in a one-hour retention + DefaultPriceSnapshotRetention = 1440 // default epoch interval is one minute so this results in a one-day retention ) var _ paramtypes.ParamSet = (*Params)(nil)