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 1 commit
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 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
6 changes: 5 additions & 1 deletion 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 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"
)