Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add additional events in x/lockup, x/superfluid, x/concentratedliquidity #8494

Merged
merged 2 commits into from
Jul 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* [#8375](https://github.com/osmosis-labs/osmosis/pull/8375) Enforce sub-authenticator to be greater than 1

### State Compatible
* [#8494](https://github.com/osmosis-labs/osmosis/pull/8494) Add additional events in x/lockup, x/superfluid, x/concentratedliquidity

## v25.2.0

Expand Down
1 change: 1 addition & 0 deletions x/concentrated-liquidity/lp.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,7 @@ func (k Keeper) addToPosition(ctx sdk.Context, owner sdk.AccAddress, positionId
types.TypeEvtAddToPosition,
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
sdk.NewAttribute(sdk.AttributeKeySender, owner.String()),
sdk.NewAttribute(types.AttributeKeyPoolId, strconv.FormatUint(positionId, 10)),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix the attribute value.

The attribute types.AttributeKeyPoolId should be set to position.PoolId instead of positionId.

-	sdk.NewAttribute(types.AttributeKeyPoolId, strconv.FormatUint(positionId, 10)),
+	sdk.NewAttribute(types.AttributeKeyPoolId, strconv.FormatUint(position.PoolId, 10)),
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
sdk.NewAttribute(types.AttributeKeyPoolId, strconv.FormatUint(positionId, 10)),
sdk.NewAttribute(types.AttributeKeyPoolId, strconv.FormatUint(position.PoolId, 10)),

sdk.NewAttribute(types.AttributeKeyPositionId, strconv.FormatUint(positionId, 10)),
sdk.NewAttribute(types.AttributeKeyNewPositionId, strconv.FormatUint(newPositionData.ID, 10)),
sdk.NewAttribute(types.AttributeAmount0, newPositionData.Amount0.String()),
Expand Down
2 changes: 2 additions & 0 deletions x/lockup/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ func createBeginUnlockEvent(lock *types.PeriodLock) sdk.Event {
types.TypeEvtBeginUnlock,
sdk.NewAttribute(types.AttributePeriodLockID, osmoutils.Uint64ToString(lock.ID)),
sdk.NewAttribute(types.AttributePeriodLockOwner, lock.Owner),
sdk.NewAttribute(types.AttributePeriodLockDenom, lock.Coins[0].Denom),
sdk.NewAttribute(types.AttributePeriodLockAmount, lock.Coins[0].Amount.String()),
sdk.NewAttribute(types.AttributePeriodLockDuration, lock.Duration.String()),
sdk.NewAttribute(types.AttributePeriodLockUnlockTime, lock.EndTime.String()),
)
Expand Down
1 change: 1 addition & 0 deletions x/lockup/types/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const (
AttributePeriodLockID = "period_lock_id"
AttributePeriodLockOwner = "owner"
AttributePeriodLockAmount = "amount"
AttributePeriodLockDenom = "denom"
AttributePeriodLockDuration = "duration"
AttributePeriodLockUnlockTime = "unlock_time"
AttributeUnlockedCoins = "unlocked_coins"
Expand Down
1 change: 1 addition & 0 deletions x/superfluid/keeper/concentrated_liquidity.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ func (k Keeper) addToConcentratedLiquiditySuperfluidPosition(ctx sdk.Context, se
sdk.NewEvent(
types.TypeEvtAddToConcentratedLiquiditySuperfluidPosition,
sdk.NewAttribute(sdk.AttributeKeySender, sender.String()),
sdk.NewAttribute(types.AttributeKeyPoolId, strconv.FormatUint(position.PoolId, 10)),
sdk.NewAttribute(types.AttributePositionId, strconv.FormatUint(positionId, 10)),
sdk.NewAttribute(types.AttributeNewPositionId, strconv.FormatUint(positionData.ID, 10)),
sdk.NewAttribute(types.AttributeAmount0, positionData.Amount0.String()),
Expand Down
16 changes: 10 additions & 6 deletions x/superfluid/keeper/internal/events/emit.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,22 @@ func newRemoveSuperfluidAssetEvent(denom string) sdk.Event {
)
}

func EmitSuperfluidDelegateEvent(ctx sdk.Context, lockId uint64, valAddress string) {
func EmitSuperfluidDelegateEvent(ctx sdk.Context, lockId uint64, valAddress string, lockCoins sdk.Coins) {
if ctx.EventManager() == nil {
return
}

ctx.EventManager().EmitEvents(sdk.Events{
newSuperfluidDelegateEvent(lockId, valAddress),
newSuperfluidDelegateEvent(lockId, valAddress, lockCoins),
})
}

func newSuperfluidDelegateEvent(lockId uint64, valAddress string) sdk.Event {
func newSuperfluidDelegateEvent(lockId uint64, valAddress string, lockCoins sdk.Coins) sdk.Event {
return sdk.NewEvent(
types.TypeEvtSuperfluidDelegate,
sdk.NewAttribute(types.AttributeLockId, osmoutils.Uint64ToString(lockId)),
sdk.NewAttribute(types.AttributeLockAmount, lockCoins[0].Amount.String()),
sdk.NewAttribute(types.AttributeLockDenom, lockCoins[0].Denom),
sdk.NewAttribute(types.AttributeValidator, valAddress),
)
}
Expand Down Expand Up @@ -99,20 +101,22 @@ func newSuperfluidIncreaseDelegationEvent(lockId uint64, amount sdk.Coins) sdk.E
)
}

func EmitSuperfluidUndelegateEvent(ctx sdk.Context, lockId uint64) {
func EmitSuperfluidUndelegateEvent(ctx sdk.Context, lockId uint64, lockCoins sdk.Coins) {
if ctx.EventManager() == nil {
return
}

ctx.EventManager().EmitEvents(sdk.Events{
newSuperfluidUndelegateEvent(lockId),
newSuperfluidUndelegateEvent(lockId, lockCoins),
})
}

func newSuperfluidUndelegateEvent(lockId uint64) sdk.Event {
func newSuperfluidUndelegateEvent(lockId uint64, lockCoins sdk.Coins) sdk.Event {
return sdk.NewEvent(
types.TypeEvtSuperfluidUndelegate,
sdk.NewAttribute(types.AttributeLockId, fmt.Sprintf("%d", lockId)),
sdk.NewAttribute(types.AttributeLockAmount, lockCoins[0].Amount.String()),
sdk.NewAttribute(types.AttributeLockDenom, lockCoins[0].Denom),
)
}

Expand Down
61 changes: 34 additions & 27 deletions x/superfluid/keeper/internal/events/emit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,16 @@ func (suite *SuperfluidEventsTestSuite) TestEmitRemoveSuperfluidAsset() {

func (suite *SuperfluidEventsTestSuite) TestEmitSuperfluidDelegateEvent() {
testcases := map[string]struct {
ctx sdk.Context
lockID uint64
valAddr string
ctx sdk.Context
lockID uint64
valAddr string
lockCoins sdk.Coins
}{
"basic valid": {
ctx: suite.CreateTestContext(),
lockID: 1,
valAddr: sdk.AccAddress([]byte(addressString)).String(),
ctx: suite.CreateTestContext(),
lockID: 1,
valAddr: sdk.AccAddress([]byte(addressString)).String(),
lockCoins: sdk.NewCoins(sdk.NewInt64Coin("foo", 10)),
},
"context with no event manager": {
ctx: sdk.Context{},
Expand All @@ -131,25 +133,26 @@ func (suite *SuperfluidEventsTestSuite) TestEmitSuperfluidDelegateEvent() {

for name, tc := range testcases {
suite.Run(name, func() {
expectedEvents := sdk.Events{
sdk.NewEvent(
types.TypeEvtSuperfluidDelegate,
sdk.NewAttribute(types.AttributeLockId, fmt.Sprintf("%d", tc.lockID)),
sdk.NewAttribute(types.AttributeValidator, tc.valAddr),
),
}

hasNoEventManager := tc.ctx.EventManager() == nil

// System under test.
events.EmitSuperfluidDelegateEvent(tc.ctx, tc.lockID, tc.valAddr)
events.EmitSuperfluidDelegateEvent(tc.ctx, tc.lockID, tc.valAddr, tc.lockCoins)

// Assertions
if hasNoEventManager {
// If there is no event manager on context, this is a no-op.
return
}

expectedEvents := sdk.Events{
sdk.NewEvent(
types.TypeEvtSuperfluidDelegate,
sdk.NewAttribute(types.AttributeLockId, fmt.Sprintf("%d", tc.lockID)),
sdk.NewAttribute(types.AttributeLockAmount, tc.lockCoins[0].Amount.String()),
sdk.NewAttribute(types.AttributeLockDenom, tc.lockCoins[0].Denom),
sdk.NewAttribute(types.AttributeValidator, tc.valAddr),
),
}
eventManager := tc.ctx.EventManager()
actualEvents := eventManager.Events()
suite.Equal(expectedEvents, actualEvents)
Expand Down Expand Up @@ -255,12 +258,14 @@ func (suite *SuperfluidEventsTestSuite) TestEmitSuperfluidIncreaseDelegationEven

func (suite *SuperfluidEventsTestSuite) TestEmitSuperfluidUndelegateEvent() {
testcases := map[string]struct {
ctx sdk.Context
lockID uint64
ctx sdk.Context
lockID uint64
lockCoins sdk.Coins
}{
"basic valid": {
ctx: suite.CreateTestContext(),
lockID: 1,
ctx: suite.CreateTestContext(),
lockID: 1,
lockCoins: sdk.NewCoins(sdk.NewInt64Coin("foo", 10)),
},
"context with no event manager": {
ctx: sdk.Context{},
Expand All @@ -269,24 +274,26 @@ func (suite *SuperfluidEventsTestSuite) TestEmitSuperfluidUndelegateEvent() {

for name, tc := range testcases {
suite.Run(name, func() {
expectedEvents := sdk.Events{
sdk.NewEvent(
types.TypeEvtSuperfluidUndelegate,
sdk.NewAttribute(types.AttributeLockId, fmt.Sprintf("%d", tc.lockID)),
),
}

hasNoEventManager := tc.ctx.EventManager() == nil

// System under test.
events.EmitSuperfluidUndelegateEvent(tc.ctx, tc.lockID)
events.EmitSuperfluidUndelegateEvent(tc.ctx, tc.lockID, tc.lockCoins)

// Assertions
if hasNoEventManager {
// If there is no event manager on context, this is a no-op.
return
}

expectedEvents := sdk.Events{
sdk.NewEvent(
types.TypeEvtSuperfluidUndelegate,
sdk.NewAttribute(types.AttributeLockId, fmt.Sprintf("%d", tc.lockID)),
sdk.NewAttribute(types.AttributeLockAmount, tc.lockCoins[0].Amount.String()),
sdk.NewAttribute(types.AttributeLockDenom, tc.lockCoins[0].Denom),
),
}

eventManager := tc.ctx.EventManager()
actualEvents := eventManager.Events()
suite.Equal(expectedEvents, actualEvents)
Expand Down
12 changes: 10 additions & 2 deletions x/superfluid/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ func (server msgServer) SuperfluidDelegate(goCtx context.Context, msg *types.Msg

err := server.keeper.SuperfluidDelegate(ctx, msg.Sender, msg.LockId, msg.ValAddr)
if err == nil {
events.EmitSuperfluidDelegateEvent(ctx, msg.LockId, msg.ValAddr)
lock, err := server.keeper.lk.GetLockByID(ctx, msg.LockId)
if err != nil {
return &types.MsgSuperfluidDelegateResponse{}, err
}
events.EmitSuperfluidDelegateEvent(ctx, msg.LockId, msg.ValAddr, lock.Coins)
}
return &types.MsgSuperfluidDelegateResponse{}, err
}
Expand All @@ -62,7 +66,11 @@ func (server msgServer) SuperfluidUndelegate(goCtx context.Context, msg *types.M

err := server.keeper.SuperfluidUndelegate(ctx, msg.Sender, msg.LockId)
if err == nil {
events.EmitSuperfluidUndelegateEvent(ctx, msg.LockId)
lock, err := server.keeper.lk.GetLockByID(ctx, msg.LockId)
if err != nil {
return &types.MsgSuperfluidUndelegateResponse{}, err
}
events.EmitSuperfluidUndelegateEvent(ctx, msg.LockId, lock.Coins)
}
return &types.MsgSuperfluidUndelegateResponse{}, err
}
Expand Down
2 changes: 2 additions & 0 deletions x/superfluid/types/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ const (
AttributeDenom = "denom"
AttributeSuperfluidAssetType = "superfluid_asset_type"
AttributeLockId = "lock_id"
AttributeLockAmount = "lock_amount"
AttributeLockDenom = "lock_denom"
AttributeValidator = "validator"
AttributeAmount = "amount"
)