diff --git a/go.sum b/go.sum index 9a63fa29947..6b5c626a2de 100644 --- a/go.sum +++ b/go.sum @@ -940,8 +940,6 @@ github.com/osmosis-labs/go-mutesting v0.0.0-20221208041716-b43bcd97b3b3 h1:Ylmch github.com/osmosis-labs/go-mutesting v0.0.0-20221208041716-b43bcd97b3b3/go.mod h1:lV6KnqXYD/ayTe7310MHtM3I2q8Z6bBfMAi+bhwPYtI= github.com/osmosis-labs/osmosis/osmomath v0.0.3-dev.0.20230516205127-c213fddde069 h1:ZgDrTJ2GCH4CJGbV6rudw4O9rPMAuwWoLVZnG6cUr+A= github.com/osmosis-labs/osmosis/osmomath v0.0.3-dev.0.20230516205127-c213fddde069/go.mod h1:a7lhiXRpn8QJ21OhFpaEnUNErTSIafaYpp02q6uI/Dk= -github.com/osmosis-labs/osmosis/osmoutils v0.0.0-20230516205127-c213fddde069 h1:9C/n+Nx5rre/AHPMlPsQrk1isgydrCNB68aqer86ygE= -github.com/osmosis-labs/osmosis/osmoutils v0.0.0-20230516205127-c213fddde069/go.mod h1:hk/o9/kmTSZmZqwXcSrPuwj/gpRMCqbE/d3vj6teL2A= github.com/osmosis-labs/osmosis/osmoutils v0.0.0-20230529060317-d6d2dda0fb22 h1:I14d+U4gDSL5dHoQ3G+kGLhZP5Zj3mOxMb/97Xflusc= github.com/osmosis-labs/osmosis/osmoutils v0.0.0-20230529060317-d6d2dda0fb22/go.mod h1:GIvgXqD8NOtrpu5bJ052tZxWLFj4ekpi1BMwEHIvXVU= github.com/osmosis-labs/osmosis/x/epochs v0.0.0-20230328024000-175ec88e4304 h1:RIrWLzIiZN5Xd2JOfSOtGZaf6V3qEQYg6EaDTAkMnCo= diff --git a/proto/osmosis/concentrated-liquidity/tickInfo.proto b/proto/osmosis/concentrated-liquidity/tickInfo.proto index 51bbdd48711..0ff02f5c617 100644 --- a/proto/osmosis/concentrated-liquidity/tickInfo.proto +++ b/proto/osmosis/concentrated-liquidity/tickInfo.proto @@ -42,12 +42,21 @@ message TickInfo { (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.DecCoins", (gogoproto.nullable) = false ]; - repeated UptimeTracker uptime_trackers = 4 [ + // uptime_trackers is a container encapsulating the uptime trackers. + // We use a container instead of a "repeated UptimeTracker" directly + // because we need the ability to serialize and deserialize the + // container easily for events when crossing a tick. + UptimeTrackers uptime_trackers = 4 [ (gogoproto.moretags) = "yaml:\"uptime_trackers\"", (gogoproto.nullable) = false ]; } +message UptimeTrackers { + repeated UptimeTracker list = 1 + [ (gogoproto.moretags) = "yaml:\"list\"", (gogoproto.nullable) = false ]; +} + message UptimeTracker { repeated cosmos.base.v1beta1.DecCoin uptime_growth_outside = 1 [ (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.DecCoins", diff --git a/tests/cl-genesis-positions/go.mod b/tests/cl-genesis-positions/go.mod index 5c4eae1be72..b2877a61437 100644 --- a/tests/cl-genesis-positions/go.mod +++ b/tests/cl-genesis-positions/go.mod @@ -6,9 +6,9 @@ require ( github.com/cosmos/cosmos-sdk v0.47.2 github.com/ignite/cli v0.23.0 github.com/osmosis-labs/osmosis/osmomath v0.0.3-dev.0.20230516205127-c213fddde069 - github.com/osmosis-labs/osmosis/osmoutils v0.0.0-20230516205127-c213fddde069 + github.com/osmosis-labs/osmosis/osmoutils v0.0.0-20230529060317-d6d2dda0fb22 // this commit points to https://github.com/osmosis-labs/osmosis/commit/6e8fbee70d9067b69a900cfc7441b5c4185ec495 - github.com/osmosis-labs/osmosis/v15 v15.0.0-20230529161742-5ecd4b4758a1 + github.com/osmosis-labs/osmosis/v15 v15.0.0-20230530235412-9f091596cbcf github.com/tendermint/tendermint v0.34.26 ) diff --git a/tests/cl-genesis-positions/go.sum b/tests/cl-genesis-positions/go.sum index 72ae7a2c760..d0a0c896914 100644 --- a/tests/cl-genesis-positions/go.sum +++ b/tests/cl-genesis-positions/go.sum @@ -699,8 +699,12 @@ github.com/osmosis-labs/osmosis/osmomath v0.0.3-dev.0.20230516205127-c213fddde06 github.com/osmosis-labs/osmosis/osmomath v0.0.3-dev.0.20230516205127-c213fddde069/go.mod h1:a7lhiXRpn8QJ21OhFpaEnUNErTSIafaYpp02q6uI/Dk= github.com/osmosis-labs/osmosis/osmoutils v0.0.0-20230516205127-c213fddde069 h1:9C/n+Nx5rre/AHPMlPsQrk1isgydrCNB68aqer86ygE= github.com/osmosis-labs/osmosis/osmoutils v0.0.0-20230516205127-c213fddde069/go.mod h1:hk/o9/kmTSZmZqwXcSrPuwj/gpRMCqbE/d3vj6teL2A= +github.com/osmosis-labs/osmosis/osmoutils v0.0.0-20230529060317-d6d2dda0fb22 h1:I14d+U4gDSL5dHoQ3G+kGLhZP5Zj3mOxMb/97Xflusc= +github.com/osmosis-labs/osmosis/osmoutils v0.0.0-20230529060317-d6d2dda0fb22/go.mod h1:GIvgXqD8NOtrpu5bJ052tZxWLFj4ekpi1BMwEHIvXVU= github.com/osmosis-labs/osmosis/v15 v15.0.0-20230529161742-5ecd4b4758a1 h1:lXoByLU+isHFXqHZ475nR70jNh+ggMnKkf8sjlrFD4E= github.com/osmosis-labs/osmosis/v15 v15.0.0-20230529161742-5ecd4b4758a1/go.mod h1:WLizb8rE6PDUiu5S/VWqbqFeIps8sCo+EX7zGRdia0o= +github.com/osmosis-labs/osmosis/v15 v15.0.0-20230530235412-9f091596cbcf h1:APgiJVc3pKayuHM3w6QVJmq91yj6c+EhmpgWZPXT4d0= +github.com/osmosis-labs/osmosis/v15 v15.0.0-20230530235412-9f091596cbcf/go.mod h1:ww2QtVh+XW91yTpbyfM4mJBmIRk4AU0PigLL94zr0+8= github.com/osmosis-labs/osmosis/x/epochs v0.0.0-20230328024000-175ec88e4304 h1:RIrWLzIiZN5Xd2JOfSOtGZaf6V3qEQYg6EaDTAkMnCo= github.com/osmosis-labs/osmosis/x/epochs v0.0.0-20230328024000-175ec88e4304/go.mod h1:yPWoJTj5RKrXKUChAicp+G/4Ni/uVEpp27mi/FF/L9c= github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.0-20230331072320-5d6f6cfa2627 h1:A0SwZgp4bmJFbivYJc8mmVhMjrr3EdUZluBYFke11+w= diff --git a/tests/cl-go-client/go.mod b/tests/cl-go-client/go.mod index 47bc960dec2..c49960d6d5e 100644 --- a/tests/cl-go-client/go.mod +++ b/tests/cl-go-client/go.mod @@ -5,7 +5,7 @@ go 1.20 require ( github.com/cosmos/cosmos-sdk v0.47.2 github.com/ignite/cli v0.23.0 - github.com/osmosis-labs/osmosis/v15 v15.0.0-20230529161742-5ecd4b4758a1 + github.com/osmosis-labs/osmosis/v15 v15.0.0-20230530235412-9f091596cbcf ) @@ -87,7 +87,7 @@ require ( github.com/mtibben/percent v0.2.1 // indirect github.com/nxadm/tail v1.4.8 // indirect github.com/osmosis-labs/osmosis/osmomath v0.0.3-dev.0.20230516205127-c213fddde069 // indirect - github.com/osmosis-labs/osmosis/osmoutils v0.0.0-20230516205127-c213fddde069 // indirect + github.com/osmosis-labs/osmosis/osmoutils v0.0.0-20230529060317-d6d2dda0fb22 // indirect github.com/pelletier/go-toml/v2 v2.0.6 // indirect github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5 // indirect github.com/pkg/errors v0.9.1 // indirect diff --git a/tests/cl-go-client/go.sum b/tests/cl-go-client/go.sum index 33c13aefd28..186633f7fa7 100644 --- a/tests/cl-go-client/go.sum +++ b/tests/cl-go-client/go.sum @@ -692,6 +692,7 @@ github.com/osmosis-labs/osmosis/osmomath v0.0.3-dev.0.20230516205127-c213fddde06 github.com/osmosis-labs/osmosis/osmomath v0.0.3-dev.0.20230516205127-c213fddde069/go.mod h1:a7lhiXRpn8QJ21OhFpaEnUNErTSIafaYpp02q6uI/Dk= github.com/osmosis-labs/osmosis/osmoutils v0.0.0-20230516205127-c213fddde069 h1:9C/n+Nx5rre/AHPMlPsQrk1isgydrCNB68aqer86ygE= github.com/osmosis-labs/osmosis/osmoutils v0.0.0-20230516205127-c213fddde069/go.mod h1:hk/o9/kmTSZmZqwXcSrPuwj/gpRMCqbE/d3vj6teL2A= +github.com/osmosis-labs/osmosis/osmoutils v0.0.0-20230529060317-d6d2dda0fb22/go.mod h1:GIvgXqD8NOtrpu5bJ052tZxWLFj4ekpi1BMwEHIvXVU= github.com/osmosis-labs/osmosis/x/epochs v0.0.0-20230328024000-175ec88e4304 h1:RIrWLzIiZN5Xd2JOfSOtGZaf6V3qEQYg6EaDTAkMnCo= github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.0-20230331072320-5d6f6cfa2627 h1:A0SwZgp4bmJFbivYJc8mmVhMjrr3EdUZluBYFke11+w= github.com/osmosis-labs/wasmd v0.31.0-osmo-v16 h1:X747cZYdnqc/+RV48iPVeGprpVb/fUWSaKGsZUWrdbg= diff --git a/x/concentrated-liquidity/genesis_test.go b/x/concentrated-liquidity/genesis_test.go index 782e4a892f4..11323d09514 100644 --- a/x/concentrated-liquidity/genesis_test.go +++ b/x/concentrated-liquidity/genesis_test.go @@ -44,9 +44,11 @@ var ( LiquidityGross: sdk.OneDec(), LiquidityNet: sdk.OneDec(), SpreadRewardGrowthOppositeDirectionOfLastTraversal: testCoins, - UptimeTrackers: []model.UptimeTracker{ - { - UptimeGrowthOutside: testCoins, + UptimeTrackers: model.UptimeTrackers{ + List: []model.UptimeTracker{ + { + UptimeGrowthOutside: testCoins, + }, }, }, } diff --git a/x/concentrated-liquidity/incentives.go b/x/concentrated-liquidity/incentives.go index 67f4f3af888..b9964afd7d1 100644 --- a/x/concentrated-liquidity/incentives.go +++ b/x/concentrated-liquidity/incentives.go @@ -643,8 +643,8 @@ func (k Keeper) GetUptimeGrowthInsideRange(ctx sdk.Context, poolId uint64, lower // Calculate uptime growth between lower and upper ticks // Note that we regard "within range" to mean [lowerTick, upperTick), // inclusive of lowerTick and exclusive of upperTick. - lowerTickUptimeValues := getUptimeTrackerValues(lowerTickInfo.UptimeTrackers) - upperTickUptimeValues := getUptimeTrackerValues(upperTickInfo.UptimeTrackers) + lowerTickUptimeValues := getUptimeTrackerValues(lowerTickInfo.UptimeTrackers.List) + upperTickUptimeValues := getUptimeTrackerValues(upperTickInfo.UptimeTrackers.List) // If current tick is below range, we subtract uptime growth of upper tick from that of lower tick if currentTick < lowerTick { return osmoutils.SubDecCoinArrays(lowerTickUptimeValues, upperTickUptimeValues) diff --git a/x/concentrated-liquidity/keeper_test.go b/x/concentrated-liquidity/keeper_test.go index 0a595ddbdb5..5e60a8b1b81 100644 --- a/x/concentrated-liquidity/keeper_test.go +++ b/x/concentrated-liquidity/keeper_test.go @@ -168,7 +168,9 @@ func (s *KeeperTestSuite) initializeTick(ctx sdk.Context, currentTick int64, tic s.Require().NoError(err) tickInfo.SpreadRewardGrowthOppositeDirectionOfLastTraversal = spreadRewardGrowthOppositeDirectionOfTraversal - tickInfo.UptimeTrackers = uptimeTrackers + tickInfo.UptimeTrackers = model.UptimeTrackers{ + List: uptimeTrackers, + } s.App.ConcentratedLiquidityKeeper.SetTickInfo(ctx, validPoolId, tickIndex, &tickInfo) } @@ -213,9 +215,9 @@ func (s *KeeperTestSuite) addUptimeGrowthInsideRange(ctx sdk.Context, poolId uin // Add to lower tick's uptime trackers lowerTickInfo, err := s.App.ConcentratedLiquidityKeeper.GetTickInfo(ctx, poolId, lowerTick) s.Require().NoError(err) - s.Require().Equal(len(lowerTickInfo.UptimeTrackers), len(uptimeGrowthToAdd)) + s.Require().Equal(len(lowerTickInfo.UptimeTrackers.List), len(uptimeGrowthToAdd)) - newLowerUptimeTrackerValues, err := osmoutils.AddDecCoinArrays(cl.GetUptimeTrackerValues(lowerTickInfo.UptimeTrackers), uptimeGrowthToAdd) + newLowerUptimeTrackerValues, err := osmoutils.AddDecCoinArrays(cl.GetUptimeTrackerValues(lowerTickInfo.UptimeTrackers.List), uptimeGrowthToAdd) s.Require().NoError(err) s.initializeTick(ctx, currentTick, lowerTick, lowerTickInfo.LiquidityGross, lowerTickInfo.SpreadRewardGrowthOppositeDirectionOfLastTraversal, wrapUptimeTrackers(newLowerUptimeTrackerValues), true) @@ -223,9 +225,9 @@ func (s *KeeperTestSuite) addUptimeGrowthInsideRange(ctx sdk.Context, poolId uin // Add to upper tick uptime trackers upperTickInfo, err := s.App.ConcentratedLiquidityKeeper.GetTickInfo(ctx, poolId, upperTick) s.Require().NoError(err) - s.Require().Equal(len(upperTickInfo.UptimeTrackers), len(uptimeGrowthToAdd)) + s.Require().Equal(len(upperTickInfo.UptimeTrackers.List), len(uptimeGrowthToAdd)) - newUpperUptimeTrackerValues, err := osmoutils.AddDecCoinArrays(cl.GetUptimeTrackerValues(upperTickInfo.UptimeTrackers), uptimeGrowthToAdd) + newUpperUptimeTrackerValues, err := osmoutils.AddDecCoinArrays(cl.GetUptimeTrackerValues(upperTickInfo.UptimeTrackers.List), uptimeGrowthToAdd) s.Require().NoError(err) s.initializeTick(ctx, currentTick, upperTick, upperTickInfo.LiquidityGross, upperTickInfo.SpreadRewardGrowthOppositeDirectionOfLastTraversal, wrapUptimeTrackers(newUpperUptimeTrackerValues), false) @@ -258,9 +260,9 @@ func (s *KeeperTestSuite) addUptimeGrowthOutsideRange(ctx sdk.Context, poolId ui // Add to lower tick uptime trackers lowerTickInfo, err := s.App.ConcentratedLiquidityKeeper.GetTickInfo(ctx, poolId, lowerTick) s.Require().NoError(err) - s.Require().Equal(len(lowerTickInfo.UptimeTrackers), len(uptimeGrowthToAdd)) + s.Require().Equal(len(lowerTickInfo.UptimeTrackers.List), len(uptimeGrowthToAdd)) - newLowerUptimeTrackerValues, err := osmoutils.AddDecCoinArrays(cl.GetUptimeTrackerValues(lowerTickInfo.UptimeTrackers), uptimeGrowthToAdd) + newLowerUptimeTrackerValues, err := osmoutils.AddDecCoinArrays(cl.GetUptimeTrackerValues(lowerTickInfo.UptimeTrackers.List), uptimeGrowthToAdd) s.Require().NoError(err) s.initializeTick(ctx, currentTick, lowerTick, lowerTickInfo.LiquidityGross, lowerTickInfo.SpreadRewardGrowthOppositeDirectionOfLastTraversal, wrapUptimeTrackers(newLowerUptimeTrackerValues), true) @@ -268,9 +270,9 @@ func (s *KeeperTestSuite) addUptimeGrowthOutsideRange(ctx sdk.Context, poolId ui // Add to upper tick uptime trackers upperTickInfo, err := s.App.ConcentratedLiquidityKeeper.GetTickInfo(ctx, poolId, upperTick) s.Require().NoError(err) - s.Require().Equal(len(upperTickInfo.UptimeTrackers), len(uptimeGrowthToAdd)) + s.Require().Equal(len(upperTickInfo.UptimeTrackers.List), len(uptimeGrowthToAdd)) - newUpperUptimeTrackerValues, err := osmoutils.AddDecCoinArrays(cl.GetUptimeTrackerValues(upperTickInfo.UptimeTrackers), uptimeGrowthToAdd) + newUpperUptimeTrackerValues, err := osmoutils.AddDecCoinArrays(cl.GetUptimeTrackerValues(upperTickInfo.UptimeTrackers.List), uptimeGrowthToAdd) s.Require().NoError(err) s.initializeTick(ctx, currentTick, upperTick, upperTickInfo.LiquidityGross, upperTickInfo.SpreadRewardGrowthOppositeDirectionOfLastTraversal, wrapUptimeTrackers(newUpperUptimeTrackerValues), false) @@ -278,9 +280,9 @@ func (s *KeeperTestSuite) addUptimeGrowthOutsideRange(ctx sdk.Context, poolId ui // Add to lower tick's uptime trackers lowerTickInfo, err := s.App.ConcentratedLiquidityKeeper.GetTickInfo(ctx, poolId, lowerTick) s.Require().NoError(err) - s.Require().Equal(len(lowerTickInfo.UptimeTrackers), len(uptimeGrowthToAdd)) + s.Require().Equal(len(lowerTickInfo.UptimeTrackers.List), len(uptimeGrowthToAdd)) - newLowerUptimeTrackerValues, err := osmoutils.AddDecCoinArrays(cl.GetUptimeTrackerValues(lowerTickInfo.UptimeTrackers), uptimeGrowthToAdd) + newLowerUptimeTrackerValues, err := osmoutils.AddDecCoinArrays(cl.GetUptimeTrackerValues(lowerTickInfo.UptimeTrackers.List), uptimeGrowthToAdd) s.Require().NoError(err) s.initializeTick(ctx, currentTick, lowerTick, lowerTickInfo.LiquidityGross, lowerTickInfo.SpreadRewardGrowthOppositeDirectionOfLastTraversal, wrapUptimeTrackers(newLowerUptimeTrackerValues), true) diff --git a/x/concentrated-liquidity/model/tickInfo.pb.go b/x/concentrated-liquidity/model/tickInfo.pb.go index af1c024b293..7230c068418 100644 --- a/x/concentrated-liquidity/model/tickInfo.pb.go +++ b/x/concentrated-liquidity/model/tickInfo.pb.go @@ -50,7 +50,11 @@ type TickInfo struct { // then this is just the tick's // spreadRewardGrowthOppositeDirectionOfLastTraversal value. SpreadRewardGrowthOppositeDirectionOfLastTraversal github_com_cosmos_cosmos_sdk_types.DecCoins `protobuf:"bytes,3,rep,name=spread_reward_growth_opposite_direction_of_last_traversal,json=spreadRewardGrowthOppositeDirectionOfLastTraversal,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.DecCoins" json:"spread_reward_growth_opposite_direction_of_last_traversal"` - UptimeTrackers []UptimeTracker `protobuf:"bytes,4,rep,name=uptime_trackers,json=uptimeTrackers,proto3" json:"uptime_trackers" yaml:"uptime_trackers"` + // uptime_trackers is a container encapsulating the uptime trackers. + // We use a container instead of a "repeated UptimeTracker" directly + // because we need the ability to serialize and deserialize the + // container easily for events when crossing a tick. + UptimeTrackers UptimeTrackers `protobuf:"bytes,4,opt,name=uptime_trackers,json=uptimeTrackers,proto3" json:"uptime_trackers" yaml:"uptime_trackers"` } func (m *TickInfo) Reset() { *m = TickInfo{} } @@ -93,10 +97,54 @@ func (m *TickInfo) GetSpreadRewardGrowthOppositeDirectionOfLastTraversal() githu return nil } -func (m *TickInfo) GetUptimeTrackers() []UptimeTracker { +func (m *TickInfo) GetUptimeTrackers() UptimeTrackers { if m != nil { return m.UptimeTrackers } + return UptimeTrackers{} +} + +type UptimeTrackers struct { + List []UptimeTracker `protobuf:"bytes,1,rep,name=list,proto3" json:"list" yaml:"list"` +} + +func (m *UptimeTrackers) Reset() { *m = UptimeTrackers{} } +func (m *UptimeTrackers) String() string { return proto.CompactTextString(m) } +func (*UptimeTrackers) ProtoMessage() {} +func (*UptimeTrackers) Descriptor() ([]byte, []int) { + return fileDescriptor_1ccb7e45032b943a, []int{1} +} +func (m *UptimeTrackers) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *UptimeTrackers) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_UptimeTrackers.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 *UptimeTrackers) XXX_Merge(src proto.Message) { + xxx_messageInfo_UptimeTrackers.Merge(m, src) +} +func (m *UptimeTrackers) XXX_Size() int { + return m.Size() +} +func (m *UptimeTrackers) XXX_DiscardUnknown() { + xxx_messageInfo_UptimeTrackers.DiscardUnknown(m) +} + +var xxx_messageInfo_UptimeTrackers proto.InternalMessageInfo + +func (m *UptimeTrackers) GetList() []UptimeTracker { + if m != nil { + return m.List + } return nil } @@ -108,7 +156,7 @@ func (m *UptimeTracker) Reset() { *m = UptimeTracker{} } func (m *UptimeTracker) String() string { return proto.CompactTextString(m) } func (*UptimeTracker) ProtoMessage() {} func (*UptimeTracker) Descriptor() ([]byte, []int) { - return fileDescriptor_1ccb7e45032b943a, []int{1} + return fileDescriptor_1ccb7e45032b943a, []int{2} } func (m *UptimeTracker) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -146,6 +194,7 @@ func (m *UptimeTracker) GetUptimeGrowthOutside() github_com_cosmos_cosmos_sdk_ty func init() { proto.RegisterType((*TickInfo)(nil), "osmosis.concentratedliquidity.v1beta1.TickInfo") + proto.RegisterType((*UptimeTrackers)(nil), "osmosis.concentratedliquidity.v1beta1.UptimeTrackers") proto.RegisterType((*UptimeTracker)(nil), "osmosis.concentratedliquidity.v1beta1.UptimeTracker") } @@ -154,39 +203,41 @@ func init() { } var fileDescriptor_1ccb7e45032b943a = []byte{ - // 497 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x93, 0xc1, 0x6a, 0xd4, 0x50, - 0x14, 0x86, 0x27, 0xb6, 0x88, 0x46, 0xdb, 0x42, 0xac, 0x12, 0x8b, 0x64, 0x4a, 0x40, 0x29, 0xc8, - 0x24, 0x4c, 0xab, 0x0b, 0x5d, 0xc6, 0x62, 0x15, 0xc4, 0x42, 0x18, 0x37, 0x22, 0x84, 0x9b, 0xe4, - 0xcc, 0xf4, 0x32, 0x49, 0x6e, 0x7a, 0xcf, 0xc9, 0xd4, 0x59, 0xb8, 0x74, 0xef, 0xce, 0x77, 0x70, - 0xed, 0x43, 0xcc, 0xb2, 0x4b, 0x71, 0x31, 0xca, 0xcc, 0x1b, 0xf8, 0x04, 0x92, 0xe4, 0x66, 0x3a, - 0x0e, 0x08, 0x75, 0xe1, 0x2a, 0x39, 0x27, 0xff, 0x39, 0xff, 0xc7, 0x7f, 0x73, 0xf5, 0x8e, 0xc0, - 0x54, 0x20, 0x47, 0x37, 0x12, 0x59, 0x04, 0x19, 0x49, 0x46, 0x10, 0x77, 0x12, 0x7e, 0x5a, 0xf0, - 0x98, 0xd3, 0xd8, 0x25, 0x1e, 0x0d, 0x5f, 0x66, 0x7d, 0xe1, 0xe4, 0x52, 0x90, 0x30, 0xee, 0x2b, - 0xb9, 0xb3, 0x2c, 0x5f, 0xa8, 0x9d, 0x51, 0x37, 0x04, 0x62, 0xdd, 0x9d, 0xbb, 0x51, 0xa5, 0x0b, - 0xaa, 0x21, 0xb7, 0x2e, 0xea, 0x0d, 0x3b, 0xdb, 0x03, 0x31, 0x10, 0x75, 0xbf, 0x7c, 0x53, 0x5d, - 0xab, 0xd6, 0xb8, 0x21, 0x43, 0x70, 0xd5, 0x16, 0x37, 0x12, 0x3c, 0xab, 0xbf, 0xdb, 0x5f, 0xd7, - 0xf5, 0x6b, 0x3d, 0x85, 0x62, 0x9c, 0xea, 0x5b, 0x0b, 0xcb, 0x60, 0x20, 0x05, 0xa2, 0xa9, 0xed, - 0x6a, 0x7b, 0xd7, 0xbd, 0x17, 0x93, 0x69, 0xbb, 0xf5, 0x7d, 0xda, 0x7e, 0x30, 0xe0, 0x74, 0x52, - 0x84, 0x4e, 0x24, 0x52, 0x65, 0xae, 0x1e, 0x1d, 0x8c, 0x87, 0x2e, 0x8d, 0x73, 0x40, 0xe7, 0x10, - 0xa2, 0x5f, 0xd3, 0xf6, 0x9d, 0x31, 0x4b, 0x93, 0xa7, 0xf6, 0xca, 0x3a, 0xdb, 0xdf, 0x5c, 0x74, - 0x8e, 0xca, 0x86, 0x31, 0xd4, 0x37, 0x2e, 0x34, 0x19, 0x90, 0x79, 0xa5, 0x32, 0x7c, 0xfe, 0xcf, - 0x86, 0xdb, 0xab, 0x86, 0x19, 0x90, 0xed, 0xdf, 0x5c, 0xd4, 0xaf, 0x81, 0x8c, 0x89, 0xa6, 0x3f, - 0xc1, 0x5c, 0x02, 0x8b, 0x03, 0x09, 0x67, 0x4c, 0xc6, 0x25, 0xd5, 0x19, 0x9d, 0x04, 0x22, 0xcf, - 0x05, 0x72, 0x82, 0x20, 0xe6, 0x12, 0x22, 0xe2, 0x22, 0x0b, 0x44, 0x3f, 0x48, 0x18, 0x52, 0x40, - 0x92, 0x8d, 0x40, 0x22, 0x4b, 0xcc, 0xb5, 0xdd, 0xb5, 0xbd, 0x1b, 0xfb, 0xf7, 0x1c, 0x95, 0x7a, - 0x99, 0x68, 0x73, 0x2e, 0x25, 0xc3, 0x33, 0xc1, 0x33, 0xef, 0xa0, 0xe4, 0xfe, 0xf2, 0xa3, 0xfd, - 0xf0, 0x72, 0xdc, 0xe5, 0x0c, 0xfa, 0xfb, 0x35, 0x93, 0x5f, 0x21, 0x1d, 0x55, 0x44, 0xc7, 0x0a, - 0xe8, 0xb0, 0xe1, 0x39, 0xee, 0xbf, 0x62, 0x48, 0xbd, 0x06, 0xc6, 0xf8, 0xa0, 0x6f, 0x15, 0x39, - 0xf1, 0x14, 0x4a, 0xc0, 0x68, 0x08, 0x12, 0xcd, 0xf5, 0x8a, 0xef, 0x91, 0x73, 0xa9, 0x3f, 0xc9, - 0x79, 0x53, 0x4d, 0xf7, 0xea, 0x61, 0xcf, 0x2a, 0xb9, 0x2f, 0x8e, 0x6d, 0x65, 0xb5, 0xed, 0x6f, - 0x16, 0xcb, 0x72, 0xb4, 0x3f, 0x6b, 0xfa, 0xc6, 0x1f, 0x1b, 0x8c, 0x8f, 0x9a, 0x7e, 0x5b, 0x8d, - 0x35, 0xa1, 0x16, 0x84, 0x3c, 0x06, 0x53, 0xfb, 0x5f, 0xb9, 0xdd, 0xaa, 0xfd, 0x54, 0x62, 0xb5, - 0x9b, 0xf7, 0x6e, 0x32, 0xb3, 0xb4, 0xf3, 0x99, 0xa5, 0xfd, 0x9c, 0x59, 0xda, 0xa7, 0xb9, 0xd5, - 0x3a, 0x9f, 0x5b, 0xad, 0x6f, 0x73, 0xab, 0xf5, 0xd6, 0x5b, 0xda, 0xad, 0x32, 0xea, 0x24, 0x2c, - 0xc4, 0xa6, 0x70, 0x47, 0xdd, 0xc7, 0xee, 0xfb, 0xbf, 0xdd, 0xd7, 0x54, 0xc4, 0x90, 0x84, 0x57, - 0xab, 0x5b, 0x73, 0xf0, 0x3b, 0x00, 0x00, 0xff, 0xff, 0xe3, 0x54, 0xa1, 0x19, 0xde, 0x03, 0x00, - 0x00, + // 530 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x94, 0x41, 0x8b, 0xd3, 0x40, + 0x14, 0xc7, 0x3b, 0xee, 0x22, 0x3a, 0x75, 0xbb, 0x90, 0x5d, 0x25, 0x2e, 0x92, 0x96, 0x80, 0x52, + 0x90, 0x26, 0xb4, 0xeb, 0x1e, 0xf4, 0x18, 0x17, 0x57, 0x41, 0x5c, 0x08, 0xf5, 0x22, 0x4a, 0x98, + 0x24, 0xd3, 0xee, 0xd0, 0x24, 0x93, 0x9d, 0x79, 0xe9, 0xda, 0x8b, 0x37, 0xef, 0xde, 0xfc, 0x0e, + 0xde, 0xfd, 0x0e, 0x3d, 0xee, 0x51, 0x3c, 0x54, 0x69, 0xbf, 0x81, 0x9f, 0x40, 0x92, 0x4c, 0xba, + 0xdb, 0x82, 0xb0, 0x0a, 0x9e, 0x92, 0x79, 0xf9, 0xbf, 0xff, 0xff, 0xc7, 0x7b, 0x49, 0x70, 0x87, + 0xcb, 0x98, 0x4b, 0x26, 0xed, 0x80, 0x27, 0x01, 0x4d, 0x40, 0x10, 0xa0, 0x61, 0x27, 0x62, 0xa7, + 0x19, 0x0b, 0x19, 0x4c, 0x6c, 0x60, 0xc1, 0xe8, 0x45, 0x32, 0xe0, 0x56, 0x2a, 0x38, 0x70, 0xed, + 0xbe, 0x92, 0x5b, 0x97, 0xe5, 0x4b, 0xb5, 0x35, 0xee, 0xfa, 0x14, 0x48, 0x77, 0xef, 0x6e, 0x50, + 0xe8, 0xbc, 0xa2, 0xc9, 0x2e, 0x0f, 0xa5, 0xc3, 0xde, 0xee, 0x90, 0x0f, 0x79, 0x59, 0xcf, 0xef, + 0x54, 0xd5, 0x28, 0x35, 0xb6, 0x4f, 0x24, 0xb5, 0x95, 0x8b, 0x1d, 0x70, 0x96, 0x94, 0xcf, 0xcd, + 0xaf, 0x9b, 0xf8, 0x46, 0x5f, 0xa1, 0x68, 0xa7, 0x78, 0x7b, 0x19, 0xe9, 0x0d, 0x05, 0x97, 0x52, + 0x47, 0x2d, 0xd4, 0xbe, 0xe9, 0x3c, 0x9f, 0xce, 0x9a, 0xb5, 0xef, 0xb3, 0xe6, 0x83, 0x21, 0x83, + 0x93, 0xcc, 0xb7, 0x02, 0x1e, 0xab, 0x70, 0x75, 0xe9, 0xc8, 0x70, 0x64, 0xc3, 0x24, 0xa5, 0xd2, + 0x3a, 0xa4, 0xc1, 0xaf, 0x59, 0xf3, 0xce, 0x84, 0xc4, 0xd1, 0x13, 0x73, 0xcd, 0xce, 0x74, 0x1b, + 0xcb, 0xca, 0x51, 0x5e, 0xd0, 0x46, 0x78, 0xeb, 0x42, 0x93, 0x50, 0xd0, 0xaf, 0x15, 0x81, 0xcf, + 0xfe, 0x3a, 0x70, 0x77, 0x3d, 0x30, 0xa1, 0x60, 0xba, 0xb7, 0x96, 0xe7, 0x57, 0x14, 0xb4, 0x29, + 0xc2, 0x8f, 0x65, 0x2a, 0x28, 0x09, 0x3d, 0x41, 0xcf, 0x88, 0x08, 0x73, 0xaa, 0x33, 0x38, 0xf1, + 0x78, 0x9a, 0x72, 0xc9, 0x80, 0x7a, 0x21, 0x13, 0x34, 0x00, 0xc6, 0x13, 0x8f, 0x0f, 0xbc, 0x88, + 0x48, 0xf0, 0x40, 0x90, 0x31, 0x15, 0x92, 0x44, 0xfa, 0x46, 0x6b, 0xa3, 0x5d, 0xef, 0xdd, 0xb3, + 0xd4, 0xd4, 0xf3, 0x89, 0x56, 0x7b, 0xc9, 0x19, 0x9e, 0x72, 0x96, 0x38, 0xfb, 0x39, 0xf7, 0x97, + 0x1f, 0xcd, 0x87, 0x57, 0xe3, 0xce, 0x7b, 0xa4, 0xdb, 0x2b, 0x99, 0xdc, 0x02, 0xe9, 0xa8, 0x20, + 0x3a, 0x56, 0x40, 0x87, 0x15, 0xcf, 0xf1, 0xe0, 0x25, 0x91, 0xd0, 0xaf, 0x60, 0xb4, 0x0f, 0x78, + 0x3b, 0x4b, 0x81, 0xc5, 0x34, 0x07, 0x0c, 0x46, 0x54, 0x48, 0x7d, 0xb3, 0x85, 0xda, 0xf5, 0xde, + 0x81, 0x75, 0xa5, 0x37, 0xc9, 0x7a, 0x5d, 0x74, 0xf7, 0x55, 0xb3, 0x63, 0xe4, 0xe0, 0x17, 0x7b, + 0x5b, 0xf3, 0x36, 0xdd, 0x46, 0xb6, 0xa2, 0x37, 0x39, 0x6e, 0xac, 0x3a, 0x68, 0xef, 0xf0, 0x66, + 0xc4, 0x24, 0xe8, 0xa8, 0x18, 0xd3, 0xa3, 0x7f, 0xc1, 0x70, 0x76, 0x14, 0x45, 0xbd, 0x5a, 0xa6, + 0x04, 0xd3, 0x2d, 0x6c, 0xcd, 0xcf, 0x08, 0x6f, 0xad, 0x88, 0xb5, 0x8f, 0x08, 0xdf, 0x56, 0x9c, + 0xd5, 0x1a, 0x33, 0x90, 0x2c, 0xa4, 0x0a, 0xe1, 0x3f, 0x6c, 0x6a, 0xa7, 0xcc, 0x53, 0x3b, 0x2a, + 0xd3, 0x9c, 0xb7, 0xd3, 0xb9, 0x81, 0xce, 0xe7, 0x06, 0xfa, 0x39, 0x37, 0xd0, 0xa7, 0x85, 0x51, + 0x3b, 0x5f, 0x18, 0xb5, 0x6f, 0x0b, 0xa3, 0xf6, 0xc6, 0xb9, 0xe4, 0xad, 0xc6, 0xd1, 0x89, 0x88, + 0x2f, 0xab, 0x83, 0x3d, 0xee, 0x1e, 0xd8, 0xef, 0xff, 0xf4, 0x87, 0x88, 0x79, 0x48, 0x23, 0xff, + 0x7a, 0xf1, 0x9d, 0xee, 0xff, 0x0e, 0x00, 0x00, 0xff, 0xff, 0x33, 0x05, 0x30, 0xcd, 0x50, 0x04, + 0x00, 0x00, } func (m *TickInfo) Marshal() (dAtA []byte, err error) { @@ -209,20 +260,16 @@ func (m *TickInfo) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if len(m.UptimeTrackers) > 0 { - for iNdEx := len(m.UptimeTrackers) - 1; iNdEx >= 0; iNdEx-- { - { - size, err := m.UptimeTrackers[iNdEx].MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintTickInfo(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x22 + { + size, err := m.UptimeTrackers.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err } + i -= size + i = encodeVarintTickInfo(dAtA, i, uint64(size)) } + i-- + dAtA[i] = 0x22 if len(m.SpreadRewardGrowthOppositeDirectionOfLastTraversal) > 0 { for iNdEx := len(m.SpreadRewardGrowthOppositeDirectionOfLastTraversal) - 1; iNdEx >= 0; iNdEx-- { { @@ -260,6 +307,43 @@ func (m *TickInfo) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +func (m *UptimeTrackers) 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 *UptimeTrackers) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *UptimeTrackers) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.List) > 0 { + for iNdEx := len(m.List) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.List[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTickInfo(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + func (m *UptimeTracker) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) @@ -324,8 +408,19 @@ func (m *TickInfo) Size() (n int) { n += 1 + l + sovTickInfo(uint64(l)) } } - if len(m.UptimeTrackers) > 0 { - for _, e := range m.UptimeTrackers { + l = m.UptimeTrackers.Size() + n += 1 + l + sovTickInfo(uint64(l)) + return n +} + +func (m *UptimeTrackers) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.List) > 0 { + for _, e := range m.List { l = e.Size() n += 1 + l + sovTickInfo(uint64(l)) } @@ -514,8 +609,91 @@ func (m *TickInfo) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.UptimeTrackers = append(m.UptimeTrackers, UptimeTracker{}) - if err := m.UptimeTrackers[len(m.UptimeTrackers)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + if err := m.UptimeTrackers.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTickInfo(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTickInfo + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *UptimeTrackers) 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 ErrIntOverflowTickInfo + } + 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: UptimeTrackers: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: UptimeTrackers: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field List", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTickInfo + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTickInfo + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTickInfo + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.List = append(m.List, UptimeTracker{}) + if err := m.List[len(m.List)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex diff --git a/x/concentrated-liquidity/store_test.go b/x/concentrated-liquidity/store_test.go index 49e0f56c90e..bdb09780601 100644 --- a/x/concentrated-liquidity/store_test.go +++ b/x/concentrated-liquidity/store_test.go @@ -21,7 +21,7 @@ var ( LiquidityGross: DefaultLiquidityAmt, LiquidityNet: DefaultLiquidityAmt, SpreadRewardGrowthOppositeDirectionOfLastTraversal: DefaultSpreadRewardAccumCoins, - UptimeTrackers: wrapUptimeTrackers(getExpectedUptimes().hundredTokensMultiDenom), + UptimeTrackers: model.UptimeTrackers{wrapUptimeTrackers(getExpectedUptimes().hundredTokensMultiDenom)}, } defaultTick = genesis.FullTick{ diff --git a/x/concentrated-liquidity/tick.go b/x/concentrated-liquidity/tick.go index 136df801e03..170ba9bdf04 100644 --- a/x/concentrated-liquidity/tick.go +++ b/x/concentrated-liquidity/tick.go @@ -2,6 +2,7 @@ package concentrated_liquidity import ( "fmt" + "strconv" "github.com/cosmos/cosmos-sdk/store/prefix" storetypes "github.com/cosmos/cosmos-sdk/store/types" @@ -87,13 +88,24 @@ func (k Keeper) crossTick(ctx sdk.Context, poolId uint64, tickIndex int64, tickI // For each supported uptime, subtract tick's uptime growth outside from the respective uptime accumulator // This is functionally equivalent to "flipping" the trackers once the tick is crossed - updatedUptimeTrackers := tickInfo.UptimeTrackers + updatedUptimeTrackers := tickInfo.UptimeTrackers.List for uptimeId := range uptimeAccums { updatedUptimeTrackers[uptimeId].UptimeGrowthOutside = uptimeAccums[uptimeId].GetValue().Sub(updatedUptimeTrackers[uptimeId].UptimeGrowthOutside) } k.SetTickInfo(ctx, poolId, tickIndex, tickInfo) + ctx.EventManager().EmitEvents(sdk.Events{ + sdk.NewEvent( + types.TypeEvtCrossTick, + sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory), + sdk.NewAttribute(types.AttributeKeyPoolId, strconv.FormatUint(poolId, 10)), + sdk.NewAttribute(types.AttributeKeyTickIndex, strconv.FormatInt(tickIndex, 10)), + sdk.NewAttribute(types.AttributeKeySpreadRewardGrowthOppositeDirectionOfLastTraversal, tickInfo.SpreadRewardGrowthOppositeDirectionOfLastTraversal.String()), + sdk.NewAttribute(types.AttributeKeyUptimeGrowthOppositeDirectionOfLastTraversal, tickInfo.UptimeTrackers.String()), + ), + }) + return tickInfo.LiquidityNet, nil } @@ -132,7 +144,7 @@ func (k Keeper) GetTickInfo(ctx sdk.Context, poolId uint64, tickIndex int64) (ti initialUptimeTrackers = append(initialUptimeTrackers, model.UptimeTracker{UptimeGrowthOutside: uptimeTrackerValue}) } - return model.TickInfo{LiquidityGross: sdk.ZeroDec(), LiquidityNet: sdk.ZeroDec(), SpreadRewardGrowthOppositeDirectionOfLastTraversal: initialSpreadRewardGrowthOppositeDirectionOfLastTraversal, UptimeTrackers: initialUptimeTrackers}, nil + return model.TickInfo{LiquidityGross: sdk.ZeroDec(), LiquidityNet: sdk.ZeroDec(), SpreadRewardGrowthOppositeDirectionOfLastTraversal: initialSpreadRewardGrowthOppositeDirectionOfLastTraversal, UptimeTrackers: model.UptimeTrackers{List: initialUptimeTrackers}}, nil } if err != nil { return tickStruct, err diff --git a/x/concentrated-liquidity/tick_test.go b/x/concentrated-liquidity/tick_test.go index 1e47dbb1d02..9de31230f0f 100644 --- a/x/concentrated-liquidity/tick_test.go +++ b/x/concentrated-liquidity/tick_test.go @@ -336,10 +336,12 @@ func (s *KeeperTestSuite) TestInitOrUpdateTick() { func (s *KeeperTestSuite) TestGetTickInfo() { var ( - preInitializedTickIndex = DefaultCurrTick + 2 - expectedUptimes = getExpectedUptimes() - emptyUptimeTrackers = wrapUptimeTrackers(expectedUptimes.emptyExpectedAccumValues) - varyingTokensAndDenoms = wrapUptimeTrackers(expectedUptimes.varyingTokensMultiDenom) + preInitializedTickIndex = DefaultCurrTick + 2 + expectedUptimes = getExpectedUptimes() + emptyUptimeTrackers = wrapUptimeTrackers(expectedUptimes.emptyExpectedAccumValues) + emptyUptimeTrackersModel = model.UptimeTrackers{emptyUptimeTrackers} + varyingTokensAndDenoms = wrapUptimeTrackers(expectedUptimes.varyingTokensMultiDenom) + varyingTokensAndDenomsModel = model.UptimeTrackers{varyingTokensAndDenoms} ) tests := []struct { @@ -355,7 +357,7 @@ func (s *KeeperTestSuite) TestGetTickInfo() { poolToGet: validPoolId, tickToGet: preInitializedTickIndex, // Note that SpreadRewardGrowthOutside and UptimeGrowthOutside(s) are not updated. - expectedTickInfo: model.TickInfo{LiquidityGross: DefaultLiquidityAmt, LiquidityNet: DefaultLiquidityAmt.Neg(), UptimeTrackers: emptyUptimeTrackers}, + expectedTickInfo: model.TickInfo{LiquidityGross: DefaultLiquidityAmt, LiquidityNet: DefaultLiquidityAmt.Neg(), UptimeTrackers: emptyUptimeTrackersModel}, }, { name: "Get tick info on existing pool and existing tick with init but zero global uptime accums", @@ -364,7 +366,7 @@ func (s *KeeperTestSuite) TestGetTickInfo() { preInitUptimeAccumValues: expectedUptimes.varyingTokensMultiDenom, // Note that neither SpreadRewardGrowthOutside nor UptimeGrowthOutsides are updated. // We expect uptime trackers to be initialized to zero since tick > active tick - expectedTickInfo: model.TickInfo{LiquidityGross: DefaultLiquidityAmt, LiquidityNet: DefaultLiquidityAmt.Neg(), UptimeTrackers: emptyUptimeTrackers}, + expectedTickInfo: model.TickInfo{LiquidityGross: DefaultLiquidityAmt, LiquidityNet: DefaultLiquidityAmt.Neg(), UptimeTrackers: emptyUptimeTrackersModel}, }, { name: "Get tick info on existing pool and existing tick with nonzero global uptime accums", @@ -373,7 +375,7 @@ func (s *KeeperTestSuite) TestGetTickInfo() { preInitUptimeAccumValues: expectedUptimes.varyingTokensMultiDenom, // Note that both SpreadRewardGrowthOutside and UptimeGrowthOutsides are updated. // We expect uptime trackers to be initialized to global accums since tick <= active tick - expectedTickInfo: model.TickInfo{LiquidityGross: sdk.ZeroDec(), LiquidityNet: sdk.ZeroDec(), SpreadRewardGrowthOppositeDirectionOfLastTraversal: sdk.NewDecCoins(oneEth), UptimeTrackers: varyingTokensAndDenoms}, + expectedTickInfo: model.TickInfo{LiquidityGross: sdk.ZeroDec(), LiquidityNet: sdk.ZeroDec(), SpreadRewardGrowthOppositeDirectionOfLastTraversal: sdk.NewDecCoins(oneEth), UptimeTrackers: varyingTokensAndDenomsModel}, }, { name: "Get tick info for active tick on existing pool with existing tick", @@ -381,21 +383,21 @@ func (s *KeeperTestSuite) TestGetTickInfo() { tickToGet: DefaultCurrTick, preInitUptimeAccumValues: expectedUptimes.varyingTokensMultiDenom, // Both spread reward growth and uptime trackers are set to global since tickToGet <= current tick - expectedTickInfo: model.TickInfo{LiquidityGross: sdk.ZeroDec(), LiquidityNet: sdk.ZeroDec(), SpreadRewardGrowthOppositeDirectionOfLastTraversal: sdk.NewDecCoins(oneEth), UptimeTrackers: varyingTokensAndDenoms}, + expectedTickInfo: model.TickInfo{LiquidityGross: sdk.ZeroDec(), LiquidityNet: sdk.ZeroDec(), SpreadRewardGrowthOppositeDirectionOfLastTraversal: sdk.NewDecCoins(oneEth), UptimeTrackers: varyingTokensAndDenomsModel}, }, { name: "Get tick info on existing pool with no existing tick (cur pool tick > tick)", poolToGet: validPoolId, tickToGet: DefaultCurrTick + 1, // Note that SpreadRewardGrowthOutside and UptimeGrowthOutside(s) are not initialized. - expectedTickInfo: model.TickInfo{LiquidityGross: sdk.ZeroDec(), LiquidityNet: sdk.ZeroDec(), UptimeTrackers: emptyUptimeTrackers}, + expectedTickInfo: model.TickInfo{LiquidityGross: sdk.ZeroDec(), LiquidityNet: sdk.ZeroDec(), UptimeTrackers: emptyUptimeTrackersModel}, }, { name: "Get tick info on existing pool with no existing tick (cur pool tick == tick), initialized spread reward growth outside", poolToGet: validPoolId, tickToGet: DefaultCurrTick, // Note that SpreadRewardGrowthOutside and UptimeGrowthOutside(s) are initialized. - expectedTickInfo: model.TickInfo{LiquidityGross: sdk.ZeroDec(), LiquidityNet: sdk.ZeroDec(), SpreadRewardGrowthOppositeDirectionOfLastTraversal: sdk.NewDecCoins(oneEth), UptimeTrackers: emptyUptimeTrackers}, + expectedTickInfo: model.TickInfo{LiquidityGross: sdk.ZeroDec(), LiquidityNet: sdk.ZeroDec(), SpreadRewardGrowthOppositeDirectionOfLastTraversal: sdk.NewDecCoins(oneEth), UptimeTrackers: emptyUptimeTrackersModel}, }, { name: "Get tick info on a non-existing pool with no existing tick", @@ -650,7 +652,10 @@ func (s *KeeperTestSuite) TestCrossTick() { s.Require().Equal(test.expectedTickSpreadRewardGrowthOppositeDirectionOfLastTraversal, tickInfo.SpreadRewardGrowthOppositeDirectionOfLastTraversal) // ensure tick being entered has properly updated uptime trackers - s.Require().Equal(test.expectedUptimeTrackers, tickInfo.UptimeTrackers) + s.Require().Equal(test.expectedUptimeTrackers, tickInfo.UptimeTrackers.List) + + // ensure the event is emitted with updated tick accumulators. + s.AssertEventEmitted(s.Ctx, types.TypeEvtCrossTick, 1) } }) } diff --git a/x/concentrated-liquidity/types/events.go b/x/concentrated-liquidity/types/events.go index 64f5f137884..aaf8d9d0099 100644 --- a/x/concentrated-liquidity/types/events.go +++ b/x/concentrated-liquidity/types/events.go @@ -11,35 +11,39 @@ const ( TypeEvtCreateIncentive = "create_incentive" TypeEvtFungifyChargedPosition = "fungify_charged_position" TypeEvtMoveRewards = "move_rewards" + TypeEvtCrossTick = "cross_tick" - AttributeValueCategory = ModuleName - AttributeKeyPositionId = "position_id" - AttributeKeyNewPositionId = "new_position_id" - AttributeKeyPoolId = "pool_id" - AttributeAmount0 = "amount0" - AttributeAmount1 = "amount1" - AttributeKeySpreadFactor = "spread_factor" - AttributeKeyTokensIn = "tokens_in" - AttributeKeyTokensOut = "tokens_out" - AttributeKeyForfeitedTokens = "forfeited_tokens" - AttributeLiquidity = "liquidity" - AttributeJoinTime = "join_time" - AttributeLowerTick = "lower_tick" - AttributeUpperTick = "upper_tick" - TypeEvtPoolJoined = "pool_joined" - TypeEvtPoolExited = "pool_exited" - TypeEvtTokenSwapped = "token_swapped" - AttributeIncentiveCoin = "incentive_coin" - AttributeIncentiveEmissionRate = "incentive_emission_rate" - AttributeIncentiveStartTime = "incentive_start_time" - AttributeIncentiveMinUptime = "incentive_min_uptime" - AttributeInputPositionIds = "input_position_ids" - AttributeOutputPositionId = "output_position_id" - AttributePoolAccumName = "pool_accum_name" - AttributeOldPositionAccumName = "old_position_accum_name" - AttributeNewPositionAccumName = "new_position_accum_name" - AttributeGlobalGrowth = "global_growth" - AttributeInsideGrowth = "inside_growth" - AttributeMovedRewards = "moved_rewards" - AttributeClaimableIncentives = "claimable_incentives" + AttributeValueCategory = ModuleName + AttributeKeyPositionId = "position_id" + AttributeKeyNewPositionId = "new_position_id" + AttributeKeyPoolId = "pool_id" + AttributeAmount0 = "amount0" + AttributeAmount1 = "amount1" + AttributeKeySpreadFactor = "spread_factor" + AttributeKeyTokensIn = "tokens_in" + AttributeKeyTokensOut = "tokens_out" + AttributeKeyForfeitedTokens = "forfeited_tokens" + AttributeLiquidity = "liquidity" + AttributeJoinTime = "join_time" + AttributeLowerTick = "lower_tick" + AttributeUpperTick = "upper_tick" + TypeEvtPoolJoined = "pool_joined" + TypeEvtPoolExited = "pool_exited" + TypeEvtTokenSwapped = "token_swapped" + AttributeIncentiveCoin = "incentive_coin" + AttributeIncentiveEmissionRate = "incentive_emission_rate" + AttributeIncentiveStartTime = "incentive_start_time" + AttributeIncentiveMinUptime = "incentive_min_uptime" + AttributeInputPositionIds = "input_position_ids" + AttributeOutputPositionId = "output_position_id" + AttributePoolAccumName = "pool_accum_name" + AttributeOldPositionAccumName = "old_position_accum_name" + AttributeNewPositionAccumName = "new_position_accum_name" + AttributeGlobalGrowth = "global_growth" + AttributeInsideGrowth = "inside_growth" + AttributeMovedRewards = "moved_rewards" + AttributeClaimableIncentives = "claimable_incentives" + AttributeKeyTickIndex = "tick_idx" + AttributeKeySpreadRewardGrowthOppositeDirectionOfLastTraversal = "spread_reward_growth" + AttributeKeyUptimeGrowthOppositeDirectionOfLastTraversal = "uptime_growth" )