diff --git a/proto/osmosis/concentrated-liquidity/concentratedPool.proto b/proto/osmosis/concentrated-liquidity/concentratedPool.proto index 1737ecb1f3e..6410853cbf4 100644 --- a/proto/osmosis/concentrated-liquidity/concentratedPool.proto +++ b/proto/osmosis/concentrated-liquidity/concentratedPool.proto @@ -17,4 +17,43 @@ message Pool { string address = 1 [ (gogoproto.moretags) = "yaml:\"address\"" ]; uint64 id = 2; + + // Amount of total liquidity + string liquidity = 3 [ + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", + (gogoproto.moretags) = "yaml:\"liquidity\"", + (gogoproto.nullable) = false + ]; + + string token0 = 4; + string token1 = 5; + + string current_sqrt_price = 6 [ + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", + (gogoproto.moretags) = "yaml:\"spot_price\"", + (gogoproto.nullable) = false + ]; + string current_tick = 7 [ + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", + (gogoproto.moretags) = "yaml:\"current_tick\"", + (gogoproto.nullable) = false + ]; +} + +message TickInfo { + bool initialized = 1; + // sum of all non-normalized pool weights + string liquidity = 2 [ + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", + (gogoproto.moretags) = "yaml:\"liquidity\"", + (gogoproto.nullable) = false + ]; +} + +message Position { + string liquidity = 1 [ + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", + (gogoproto.moretags) = "yaml:\"liquidity\"", + (gogoproto.nullable) = false + ]; } diff --git a/x/concentrated-liquidity/concentratedPool.pb.go b/x/concentrated-liquidity/concentratedPool.pb.go index ef229427f64..a7dd065121d 100644 --- a/x/concentrated-liquidity/concentratedPool.pb.go +++ b/x/concentrated-liquidity/concentratedPool.pb.go @@ -11,6 +11,7 @@ package concentrated_liquidity import ( fmt "fmt" _ "github.com/cosmos/cosmos-proto" + 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" @@ -32,6 +33,12 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package type Pool struct { Address string `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty" yaml:"address"` Id uint64 `protobuf:"varint,2,opt,name=id,proto3" json:"id,omitempty"` + // Amount of total liquidity + Liquidity github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,3,opt,name=liquidity,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"liquidity" yaml:"liquidity"` + Token0 string `protobuf:"bytes,4,opt,name=token0,proto3" json:"token0,omitempty"` + Token1 string `protobuf:"bytes,5,opt,name=token1,proto3" json:"token1,omitempty"` + CurrentSqrtPrice github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,6,opt,name=current_sqrt_price,json=currentSqrtPrice,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"current_sqrt_price" yaml:"spot_price"` + CurrentTick github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,7,opt,name=current_tick,json=currentTick,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"current_tick" yaml:"current_tick"` } func (m *Pool) Reset() { *m = Pool{} } @@ -66,8 +73,93 @@ func (m *Pool) XXX_DiscardUnknown() { var xxx_messageInfo_Pool proto.InternalMessageInfo +type TickInfo struct { + Initialized bool `protobuf:"varint,1,opt,name=initialized,proto3" json:"initialized,omitempty"` + // sum of all non-normalized pool weights + Liquidity github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,2,opt,name=liquidity,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"liquidity" yaml:"liquidity"` +} + +func (m *TickInfo) Reset() { *m = TickInfo{} } +func (m *TickInfo) String() string { return proto.CompactTextString(m) } +func (*TickInfo) ProtoMessage() {} +func (*TickInfo) Descriptor() ([]byte, []int) { + return fileDescriptor_b144264ce94bcf63, []int{1} +} +func (m *TickInfo) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *TickInfo) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_TickInfo.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 *TickInfo) XXX_Merge(src proto.Message) { + xxx_messageInfo_TickInfo.Merge(m, src) +} +func (m *TickInfo) XXX_Size() int { + return m.Size() +} +func (m *TickInfo) XXX_DiscardUnknown() { + xxx_messageInfo_TickInfo.DiscardUnknown(m) +} + +var xxx_messageInfo_TickInfo proto.InternalMessageInfo + +func (m *TickInfo) GetInitialized() bool { + if m != nil { + return m.Initialized + } + return false +} + +type Position struct { + Liquidity github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,1,opt,name=liquidity,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"liquidity" yaml:"liquidity"` +} + +func (m *Position) Reset() { *m = Position{} } +func (m *Position) String() string { return proto.CompactTextString(m) } +func (*Position) ProtoMessage() {} +func (*Position) Descriptor() ([]byte, []int) { + return fileDescriptor_b144264ce94bcf63, []int{2} +} +func (m *Position) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Position) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Position.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 *Position) XXX_Merge(src proto.Message) { + xxx_messageInfo_Position.Merge(m, src) +} +func (m *Position) XXX_Size() int { + return m.Size() +} +func (m *Position) XXX_DiscardUnknown() { + xxx_messageInfo_Position.DiscardUnknown(m) +} + +var xxx_messageInfo_Position proto.InternalMessageInfo + func init() { proto.RegisterType((*Pool)(nil), "osmosis.concentratedliquidity.v1beta1.Pool") + proto.RegisterType((*TickInfo)(nil), "osmosis.concentratedliquidity.v1beta1.TickInfo") + proto.RegisterType((*Position)(nil), "osmosis.concentratedliquidity.v1beta1.Position") } func init() { @@ -75,23 +167,36 @@ func init() { } var fileDescriptor_b144264ce94bcf63 = []byte{ - // 248 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x32, 0xcd, 0x2f, 0xce, 0xcd, - 0x2f, 0xce, 0x2c, 0xd6, 0x4f, 0xce, 0xcf, 0x4b, 0x4e, 0xcd, 0x2b, 0x29, 0x4a, 0x2c, 0x49, 0x4d, - 0xd1, 0xcd, 0xc9, 0x2c, 0x2c, 0xcd, 0x4c, 0xc9, 0x2c, 0xa9, 0x44, 0x11, 0x0e, 0xc8, 0xcf, 0xcf, - 0xd1, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x52, 0x85, 0x6a, 0xd3, 0x43, 0x96, 0x87, 0xeb, 0xd2, - 0x2b, 0x33, 0x4c, 0x4a, 0x2d, 0x49, 0x34, 0x94, 0x92, 0x4c, 0x06, 0xab, 0x8b, 0x07, 0x6b, 0xd2, - 0x87, 0x70, 0x20, 0x26, 0x48, 0x89, 0xa4, 0xe7, 0xa7, 0xe7, 0x43, 0xc4, 0x41, 0x2c, 0x88, 0xa8, - 0x52, 0x38, 0x17, 0x0b, 0xc8, 0x16, 0x21, 0x1d, 0x2e, 0xf6, 0xc4, 0x94, 0x94, 0xa2, 0xd4, 0xe2, - 0x62, 0x09, 0x46, 0x05, 0x46, 0x0d, 0x4e, 0x27, 0xa1, 0x4f, 0xf7, 0xe4, 0xf9, 0x2a, 0x13, 0x73, - 0x73, 0xac, 0x94, 0xa0, 0x12, 0x4a, 0x41, 0x30, 0x25, 0x42, 0x7c, 0x5c, 0x4c, 0x99, 0x29, 0x12, - 0x4c, 0x0a, 0x8c, 0x1a, 0x2c, 0x41, 0x4c, 0x99, 0x29, 0x56, 0x82, 0x1d, 0x0b, 0xe4, 0x19, 0x66, - 0x2c, 0x90, 0x67, 0x38, 0xb5, 0x45, 0x97, 0x15, 0x64, 0x9e, 0xa7, 0x53, 0xd8, 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, 0xd9, 0xa4, 0x67, 0x96, 0x64, 0x94, 0x26, 0xe9, 0x25, - 0xe7, 0xe7, 0xea, 0x43, 0x7d, 0xa5, 0x9b, 0x93, 0x98, 0x54, 0x0c, 0xe3, 0xe8, 0x97, 0x19, 0x1a, - 0xe9, 0x57, 0xe0, 0x08, 0x9f, 0x24, 0x36, 0xb0, 0xbb, 0x8d, 0x01, 0x01, 0x00, 0x00, 0xff, 0xff, - 0x06, 0xb2, 0x0a, 0x2c, 0x48, 0x01, 0x00, 0x00, + // 460 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x93, 0x31, 0x6f, 0xd3, 0x40, + 0x14, 0xc7, 0xed, 0x34, 0x4d, 0xd3, 0x2b, 0xaa, 0xda, 0x03, 0x21, 0xd3, 0xc1, 0x8e, 0x2c, 0x81, + 0x3a, 0x10, 0x1b, 0x83, 0x58, 0x2a, 0xa6, 0x20, 0x86, 0x6c, 0x91, 0x41, 0x0c, 0x2c, 0xc1, 0xb9, + 0x3b, 0xd2, 0xa7, 0x38, 0x77, 0xc9, 0xdd, 0xa5, 0x22, 0x7c, 0x02, 0x26, 0xc4, 0xc8, 0xd8, 0x0f, + 0xc1, 0x67, 0x40, 0x15, 0x53, 0x47, 0xc4, 0x10, 0xa1, 0xe4, 0x1b, 0xf4, 0x13, 0x20, 0xdb, 0x17, + 0xe3, 0x0c, 0x0c, 0x1d, 0x32, 0xd9, 0xef, 0xff, 0xee, 0xfd, 0x7f, 0x7f, 0xe9, 0xe9, 0xa1, 0xe7, + 0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} func (m *Pool) Marshal() (dAtA []byte, err error) { @@ -114,6 +219,50 @@ func (m *Pool) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + { + size := m.CurrentTick.Size() + i -= size + if _, err := m.CurrentTick.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintConcentratedPool(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x3a + { + size := m.CurrentSqrtPrice.Size() + i -= size + if _, err := m.CurrentSqrtPrice.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintConcentratedPool(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x32 + if len(m.Token1) > 0 { + i -= len(m.Token1) + copy(dAtA[i:], m.Token1) + i = encodeVarintConcentratedPool(dAtA, i, uint64(len(m.Token1))) + i-- + dAtA[i] = 0x2a + } + if len(m.Token0) > 0 { + i -= len(m.Token0) + copy(dAtA[i:], m.Token0) + i = encodeVarintConcentratedPool(dAtA, i, uint64(len(m.Token0))) + i-- + dAtA[i] = 0x22 + } + { + size := m.Liquidity.Size() + i -= size + if _, err := m.Liquidity.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintConcentratedPool(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a if m.Id != 0 { i = encodeVarintConcentratedPool(dAtA, i, uint64(m.Id)) i-- @@ -129,6 +278,82 @@ func (m *Pool) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +func (m *TickInfo) 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 *TickInfo) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *TickInfo) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size := m.Liquidity.Size() + i -= size + if _, err := m.Liquidity.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintConcentratedPool(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + if m.Initialized { + i-- + if m.Initialized { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *Position) 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 *Position) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Position) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size := m.Liquidity.Size() + i -= size + if _, err := m.Liquidity.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintConcentratedPool(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + func encodeVarintConcentratedPool(dAtA []byte, offset int, v uint64) int { offset -= sovConcentratedPool(v) base := offset @@ -153,6 +378,45 @@ func (m *Pool) Size() (n int) { if m.Id != 0 { n += 1 + sovConcentratedPool(uint64(m.Id)) } + l = m.Liquidity.Size() + n += 1 + l + sovConcentratedPool(uint64(l)) + l = len(m.Token0) + if l > 0 { + n += 1 + l + sovConcentratedPool(uint64(l)) + } + l = len(m.Token1) + if l > 0 { + n += 1 + l + sovConcentratedPool(uint64(l)) + } + l = m.CurrentSqrtPrice.Size() + n += 1 + l + sovConcentratedPool(uint64(l)) + l = m.CurrentTick.Size() + n += 1 + l + sovConcentratedPool(uint64(l)) + return n +} + +func (m *TickInfo) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Initialized { + n += 2 + } + l = m.Liquidity.Size() + n += 1 + l + sovConcentratedPool(uint64(l)) + return n +} + +func (m *Position) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.Liquidity.Size() + n += 1 + l + sovConcentratedPool(uint64(l)) return n } @@ -242,6 +506,360 @@ func (m *Pool) Unmarshal(dAtA []byte) error { break } } + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Liquidity", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowConcentratedPool + } + 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 ErrInvalidLengthConcentratedPool + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthConcentratedPool + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Liquidity.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Token0", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowConcentratedPool + } + 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 ErrInvalidLengthConcentratedPool + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthConcentratedPool + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Token0 = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Token1", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowConcentratedPool + } + 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 ErrInvalidLengthConcentratedPool + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthConcentratedPool + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Token1 = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 6: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field CurrentSqrtPrice", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowConcentratedPool + } + 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 ErrInvalidLengthConcentratedPool + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthConcentratedPool + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.CurrentSqrtPrice.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 7: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field CurrentTick", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowConcentratedPool + } + 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 ErrInvalidLengthConcentratedPool + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthConcentratedPool + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.CurrentTick.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipConcentratedPool(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthConcentratedPool + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *TickInfo) 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 ErrIntOverflowConcentratedPool + } + 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: TickInfo: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: TickInfo: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Initialized", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowConcentratedPool + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.Initialized = bool(v != 0) + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Liquidity", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowConcentratedPool + } + 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 ErrInvalidLengthConcentratedPool + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthConcentratedPool + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Liquidity.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipConcentratedPool(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthConcentratedPool + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *Position) 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 ErrIntOverflowConcentratedPool + } + 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: Position: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Position: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Liquidity", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowConcentratedPool + } + 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 ErrInvalidLengthConcentratedPool + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthConcentratedPool + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Liquidity.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipConcentratedPool(dAtA[iNdEx:]) diff --git a/x/concentrated-liquidity/lp.go b/x/concentrated-liquidity/lp.go index 1d4104c7213..da3b65de38e 100644 --- a/x/concentrated-liquidity/lp.go +++ b/x/concentrated-liquidity/lp.go @@ -1,6 +1,32 @@ package concentrated_liquidity -import sdk "github.com/cosmos/cosmos-sdk/types" +import ( + fmt "fmt" + + sdk "github.com/cosmos/cosmos-sdk/types" + + types "github.com/osmosis-labs/osmosis/v12/x/concentrated-liquidity/types" +) + +func (k Keeper) Mint(ctx sdk.Context, poolId uint64, owner sdk.AccAddress, tokenIn sdk.Int, lowerTick sdk.Int, upperTick sdk.Int) (numShares sdk.Int, err error) { + // first check and validate arguments + if lowerTick.GTE(types.MaxTick) || lowerTick.LT(types.MinTick) || upperTick.GT(types.MaxTick) { + // TODO: come back to errors + return sdk.Int{}, fmt.Errorf("validation fail") + } + + if tokenIn.IsZero() { + return sdk.Int{}, fmt.Errorf("token in amount is zero") + } + + k.UpdateTickWithNewLiquidity(ctx, poolId, lowerTick, tokenIn) + k.UpdateTickWithNewLiquidity(ctx, poolId, upperTick, tokenIn) + + // update tick with new liquidity + k.updatePositionWithLiquidity(ctx, poolId, owner.String(), lowerTick, upperTick, tokenIn) + + return sdk.Int{}, nil +} func (k Keeper) JoinPoolNoSwap(ctx sdk.Context, tokensIn sdk.Coins, swapFee sdk.Dec) (numShares sdk.Int, err error) { return sdk.Int{}, nil diff --git a/x/concentrated-liquidity/position.go b/x/concentrated-liquidity/position.go new file mode 100644 index 00000000000..6505b3a0b4a --- /dev/null +++ b/x/concentrated-liquidity/position.go @@ -0,0 +1,41 @@ +package concentrated_liquidity + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/osmosis-labs/osmosis/v12/osmoutils" + types "github.com/osmosis-labs/osmosis/v12/x/concentrated-liquidity/types" +) + +func (k Keeper) updatePositionWithLiquidity(ctx sdk.Context, + poolId uint64, + owner string, + lowerTick, upperTick sdk.Int, + liquidityDelta sdk.Int) { + position := k.getPosition(ctx, poolId, owner, lowerTick, upperTick) + + liquidityBefore := position.Liquidity + liquidityAfter := liquidityBefore.Add(liquidityDelta) + position.Liquidity = liquidityAfter + + k.setPosition(ctx, poolId, owner, lowerTick, upperTick, position) +} + +func (k Keeper) getPosition(ctx sdk.Context, poolId uint64, owner string, lowerTick, upperTick sdk.Int) Position { + store := ctx.KVStore(k.storeKey) + position := Position{} + key := types.KeyPosition(poolId, owner, lowerTick, upperTick) + osmoutils.MustGet(store, key, &position) + return position +} + +func (k Keeper) setPosition(ctx sdk.Context, + poolId uint64, + owner string, + lowerTick, upperTick sdk.Int, + position Position) { + store := ctx.KVStore(k.storeKey) + + key := types.KeyPosition(poolId, owner, lowerTick, upperTick) + osmoutils.MustSet(store, key, &position) +} diff --git a/x/concentrated-liquidity/tick.go b/x/concentrated-liquidity/tick.go new file mode 100644 index 00000000000..bc3bd206dc1 --- /dev/null +++ b/x/concentrated-liquidity/tick.go @@ -0,0 +1,37 @@ +package concentrated_liquidity + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/osmosis-labs/osmosis/v12/osmoutils" + types "github.com/osmosis-labs/osmosis/v12/x/concentrated-liquidity/types" +) + +func (k Keeper) UpdateTickWithNewLiquidity(ctx sdk.Context, poolId uint64, tickIndex sdk.Int, liquidityDelta sdk.Int) { + tickInfo := k.getTickInfo(ctx, poolId, tickIndex) + + liquidityBefore := tickInfo.Liquidity + liquidityAfter := liquidityBefore.Add(liquidityDelta) + + tickInfo.Liquidity = liquidityAfter + + if liquidityBefore == sdk.ZeroInt() { + tickInfo.Initialized = true + } + + k.setTickInfo(ctx, poolId, tickIndex, tickInfo) +} + +func (k Keeper) getTickInfo(ctx sdk.Context, poolId uint64, tickIndex sdk.Int) TickInfo { + store := ctx.KVStore(k.storeKey) + tickInfo := TickInfo{} + key := types.KeyTick(poolId, tickIndex) + osmoutils.MustGet(store, key, &tickInfo) + return tickInfo +} + +func (k Keeper) setTickInfo(ctx sdk.Context, poolId uint64, tickIndex sdk.Int, tickInfo TickInfo) { + store := ctx.KVStore(k.storeKey) + key := types.KeyTick(poolId, tickIndex) + osmoutils.MustSet(store, key, &tickInfo) +} diff --git a/x/concentrated-liquidity/types/constants.go b/x/concentrated-liquidity/types/constants.go new file mode 100644 index 00000000000..dc076c217e1 --- /dev/null +++ b/x/concentrated-liquidity/types/constants.go @@ -0,0 +1,11 @@ +package types + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" +) + +// TODO: decide on the values for Max tick and Min tick +var ( + MaxTick = sdk.NewIntFromUint64(887272) + MinTick = MaxTick.Neg() +) diff --git a/x/concentrated-liquidity/types/keys.go b/x/concentrated-liquidity/types/keys.go new file mode 100644 index 00000000000..5c5647fde8c --- /dev/null +++ b/x/concentrated-liquidity/types/keys.go @@ -0,0 +1,34 @@ +package types + +import ( + "fmt" + + sdk "github.com/cosmos/cosmos-sdk/types" +) + +const ( + ModuleName = "twap" + + StoreKey = ModuleName + TransientStoreKey = "transient_" + ModuleName // this is silly we have to do this + RouterKey = ModuleName + + QuerierRoute = ModuleName + // Contract: Coin denoms cannot contain this character + KeySeparator = "|" +) + +var ( + TickPrefix = "tick_prefix" + KeySeparator + PositionPrefix = "position_prefix" + KeySeparator +) + +// KeyTick uses pool Id and tick index +func KeyTick(poolId uint64, tickIndex sdk.Int) []byte { + return []byte(fmt.Sprintf("%s%d%s", TickPrefix, poolId, tickIndex.String())) +} + +// KeyPosition uses pool Id, owner, lower tick and upper tick for keys +func KeyPosition(poolId uint64, address string, lowerTick, upperTick sdk.Int) []byte { + return []byte(fmt.Sprintf("%s%d%s%s%s", PositionPrefix, poolId, address, lowerTick.String(), upperTick.String())) +}