From 0b01611d896786aaaa9576c3a55cdf889ba9247d Mon Sep 17 00:00:00 2001 From: kruspy Date: Tue, 17 Oct 2023 11:51:50 +0200 Subject: [PATCH 01/17] msg_server events --- x/liquidstakeibc/keeper/msg_server.go | 40 ++++++++++++++------ x/liquidstakeibc/spec/README.md | 53 +++++++++++++++++---------- x/liquidstakeibc/types/events.go | 5 +-- 3 files changed, 64 insertions(+), 34 deletions(-) diff --git a/x/liquidstakeibc/keeper/msg_server.go b/x/liquidstakeibc/keeper/msg_server.go index d7629bef3..3af6e4b18 100644 --- a/x/liquidstakeibc/keeper/msg_server.go +++ b/x/liquidstakeibc/keeper/msg_server.go @@ -402,10 +402,14 @@ func (k msgServer) LiquidStake( ctx.EventManager().EmitEvents(sdktypes.Events{ sdktypes.NewEvent( types.EventTypeLiquidStake, + sdktypes.NewAttribute(types.AttributeChainID, hostChain.ChainId), sdktypes.NewAttribute(types.AttributeDelegatorAddress, delegatorAddress.String()), - sdktypes.NewAttribute(types.AttributeAmount, depositAmount.String()), - sdktypes.NewAttribute(types.AttributeAmountReceived, mintToken.Sub(protocolFee).String()), - sdktypes.NewAttribute(types.AttributePstakeDepositFee, protocolFee.String()), + sdktypes.NewAttribute(types.AttributeInputAmount, + sdktypes.NewCoin(hostChain.HostDenom, msg.Amount.Amount).String()), + sdktypes.NewAttribute(types.AttributeOutputAmount, + sdktypes.NewCoin(hostChain.MintDenom(), mintToken.Sub(protocolFee).Amount).String()), + sdktypes.NewAttribute(types.AttributePstakeDepositFee, + sdktypes.NewCoin(hostChain.MintDenom(), protocolFee.Amount).String()), ), sdktypes.NewEvent( sdktypes.EventTypeMessage, @@ -532,10 +536,14 @@ func (k msgServer) LiquidStakeLSM( ctx.EventManager().EmitEvents(sdktypes.Events{ sdktypes.NewEvent( types.EventTypeLiquidStakeLSM, + sdktypes.NewAttribute(types.AttributeChainID, hc.ChainId), sdktypes.NewAttribute(types.AttributeDelegatorAddress, delegator.String()), - sdktypes.NewAttribute(types.AttributeAmount, depositAmount.String()), - sdktypes.NewAttribute(types.AttributeAmountReceived, mintToken.Sub(protocolFee).String()), - sdktypes.NewAttribute(types.AttributePstakeDepositFee, protocolFee.String()), + sdktypes.NewAttribute(types.AttributeInputAmount, + sdktypes.NewCoin(hc.HostDenom, delegation.Amount).String()), + sdktypes.NewAttribute(types.AttributeOutputAmount, + sdktypes.NewCoin(hc.MintDenom(), mintToken.Sub(protocolFee).Amount).String()), + sdktypes.NewAttribute(types.AttributePstakeDepositFee, + sdktypes.NewCoin(hc.MintDenom(), protocolFee.Amount).String()), ), sdktypes.NewEvent( sdktypes.EventTypeMessage, @@ -649,10 +657,14 @@ func (k msgServer) LiquidUnstake( ctx.EventManager().EmitEvents(sdktypes.Events{ sdktypes.NewEvent( types.EventTypeLiquidUnstake, + sdktypes.NewAttribute(types.AttributeChainID, hc.ChainId), sdktypes.NewAttribute(types.AttributeDelegatorAddress, msg.GetDelegatorAddress()), - sdktypes.NewAttribute(types.AttributeAmountReceived, msg.Amount.String()), - sdktypes.NewAttribute(types.AttributePstakeUnstakeFee, feeAmount.String()), - sdktypes.NewAttribute(types.AttributeUnstakeAmount, unbondAmount.String()), + sdktypes.NewAttribute(types.AttributeInputAmount, + sdktypes.NewCoin(hc.MintDenom(), msg.Amount.Amount).String()), + sdktypes.NewAttribute(types.AttributeOutputAmount, + sdktypes.NewCoin(hc.HostDenom, unbondAmount.Amount).String()), + sdktypes.NewAttribute(types.AttributePstakeUnstakeFee, + sdktypes.NewCoin(hc.MintDenom(), feeAmount).String()), sdktypes.NewAttribute(types.AttributeUnstakeEpoch, strconv.FormatInt(unbondingEpoch, 10)), ), sdktypes.NewEvent( @@ -811,10 +823,14 @@ func (k msgServer) Redeem( ctx.EventManager().EmitEvents(sdktypes.Events{ sdktypes.NewEvent( types.EventTypeRedeem, + sdktypes.NewAttribute(types.AttributeChainID, hc.ChainId), sdktypes.NewAttribute(types.AttributeDelegatorAddress, redeemAddress.String()), - sdktypes.NewAttribute(types.AttributeAmount, msg.Amount.String()), - sdktypes.NewAttribute(types.AttributeAmountReceived, redeemToken.String()), - sdktypes.NewAttribute(types.AttributePstakeRedeemFee, fee.String()), + sdktypes.NewAttribute(types.AttributeInputAmount, + sdktypes.NewCoin(hc.MintDenom(), msg.Amount.Amount).String()), + sdktypes.NewAttribute(types.AttributeOutputAmount, + sdktypes.NewCoin(hc.HostDenom, redeemToken.Amount).String()), + sdktypes.NewAttribute(types.AttributePstakeRedeemFee, + sdktypes.NewCoin(hc.MintDenom(), fee.Amount).String()), ), sdktypes.NewEvent( sdktypes.EventTypeMessage, diff --git a/x/liquidstakeibc/spec/README.md b/x/liquidstakeibc/spec/README.md index 526ac44ff..b6ac295d5 100644 --- a/x/liquidstakeibc/spec/README.md +++ b/x/liquidstakeibc/spec/README.md @@ -557,33 +557,48 @@ List of the events emitted by the module. |:-------------|:-------------------|:--------------------| | message | module | liquidstakeibc | | message | sender | {delegator_address} | +| liquid-stake | chain-id | {chain_id} | | liquid-stake | address | {delegator_address} | -| liquid-stake | amount | {staked_amount} | -| liquid-stake | received | {amount_received} | +| liquid-stake | input-amount | {staked_amount} | +| liquid-stake | output-amount | {amount_received} | | liquid-stake | pstake-deposit-fee | {deposit_fee} | +### LiquidStakeLSM + +| Type | Attribute Key | Attribute Value | +|:-----------------|:-------------------|:--------------------| +| message | module | liquidstakeibc | +| message | sender | {delegator_address} | +| liquid-stake-lsm | chain-id | {chain_id} | +| liquid-stake-lsm | address | {delegator_address} | +| liquid-stake-lsm | input-amount | {staked_amount} | +| liquid-stake-lsm | output-amount | {amount_received} | +| liquid-stake-lsm | pstake-deposit-fee | {deposit_fee} | + ### LiquidUnstake -| Type | Attribute Key | Attribute Value | -|:----------------|:--------------------|:---------------------| -| message | module | liquidstakeibc | -| message | sender | {delegator_address} | -| liquid-unstake | address | {delegator_address} | -| liquid-unstake | pstake-unstake-fee | {unstake_fee} | -| liquid-unstake | received | {amount_received} | -| liquid-unstake | undelegation-amount | {undelegated_amount} | -| liquid-unstake | undelegation-epoch | {undelegation_epoch} | +| Type | Attribute Key | Attribute Value | +|:---------------|:-------------------|:---------------------| +| message | module | liquidstakeibc | +| message | sender | {delegator_address} | +| liquid-unstake | chain-id | {chain_id} | +| liquid-unstake | address | {delegator_address} | +| liquid-unstake | input-amount | {amount_received} | +| liquid-unstake | output-amount | {undelegated_amount} | +| liquid-unstake | pstake-unstake-fee | {unstake_fee} | +| liquid-unstake | undelegation-epoch | {undelegation_epoch} | ### Redeem -| Type | Attribute Key | Attribute Value | -|:----------------|:-------------------|:--------------------| -| message | module | liquidstakeibc | -| message | sender | {delegator_address} | -| liquid-unstake | address | {delegator_address} | -| liquid-unstake | amount | {redeem_amount} | -| liquid-unstake | received | {amount_received} | -| liquid-unstake | pstake-redeem-fee | {redeem_fee} | +| Type | Attribute Key | Attribute Value | +|:--------|:------------------|:--------------------| +| message | module | liquidstakeibc | +| message | sender | {delegator_address} | +| redeem | chain-id | {chain_id} | +| redeem | address | {delegator_address} | +| redeem | input-amount | {redeem_amount} | +| redeem | output-amount | {amount_received} | +| redeem | pstake-redeem-fee | {redeem_fee} | ### UpdateParams diff --git a/x/liquidstakeibc/types/events.go b/x/liquidstakeibc/types/events.go index 0fc3d6cad..10edbef5b 100644 --- a/x/liquidstakeibc/types/events.go +++ b/x/liquidstakeibc/types/events.go @@ -11,15 +11,14 @@ const ( EventTypeUpdateParams = "update_params" EventTypeChainDisabled = "chain_disabled" - AttributeAmount = "amount" - AttributeAmountReceived = "received" + AttributeInputAmount = "input-amount" + AttributeOutputAmount = "output-amount" AttributeDelegatorAddress = "address" AttributePstakeDepositFee = "pstake-deposit-fee" AttributePstakeUnstakeFee = "pstake-unstake-fee" AttributePstakeRedeemFee = "pstake-redeem-fee" AttributeChainID = "chain-id" AttributeCValue = "c-value" - AttributeUnstakeAmount = "undelegation-amount" AttributeUnstakeEpoch = "undelegation-epoch" AttributeValidatorAddress = "validator-address" AttributeExistingDelegation = "existing-delegation" From 7e3856de6ea5cf69eec9e50eb1cea19d44d791e4 Mon Sep 17 00:00:00 2001 From: kruspy Date: Tue, 17 Oct 2023 11:58:17 +0200 Subject: [PATCH 02/17] active flag event --- x/liquidstakeibc/keeper/keeper.go | 3 ++- x/liquidstakeibc/types/events.go | 9 +++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/x/liquidstakeibc/keeper/keeper.go b/x/liquidstakeibc/keeper/keeper.go index d24a76f5d..12c3d071c 100644 --- a/x/liquidstakeibc/keeper/keeper.go +++ b/x/liquidstakeibc/keeper/keeper.go @@ -322,7 +322,8 @@ func (k *Keeper) UpdateCValues(ctx sdk.Context) { sdk.NewEvent( types.EventTypeChainDisabled, sdk.NewAttribute(types.AttributeChainID, hc.ChainId), - sdk.NewAttribute(types.AttributeCValue, hc.CValue.String()), + sdk.NewAttribute(types.AttributeOldCValue, hc.LastCValue.String()), + sdk.NewAttribute(types.AttributeNewCValue, hc.CValue.String()), ), ) } diff --git a/x/liquidstakeibc/types/events.go b/x/liquidstakeibc/types/events.go index 10edbef5b..7a812ecc4 100644 --- a/x/liquidstakeibc/types/events.go +++ b/x/liquidstakeibc/types/events.go @@ -5,11 +5,11 @@ const ( EventTypeLiquidStakeLSM = "liquid-stake-lsm" EventTypeLiquidUnstake = "liquid-unstake" EventTypeRedeem = "redeem" - EventTypePacket = "ics27_packet" + EventTypePacket = "ics27-packet" EventTypeTimeout = "timeout" EventTypeSlashing = "slashing" - EventTypeUpdateParams = "update_params" - EventTypeChainDisabled = "chain_disabled" + EventTypeUpdateParams = "update-params" + EventTypeChainDisabled = "chain-disabled" AttributeInputAmount = "input-amount" AttributeOutputAmount = "output-amount" @@ -18,7 +18,8 @@ const ( AttributePstakeUnstakeFee = "pstake-unstake-fee" AttributePstakeRedeemFee = "pstake-redeem-fee" AttributeChainID = "chain-id" - AttributeCValue = "c-value" + AttributeNewCValue = "new-c-value" + AttributeOldCValue = "old-c-value" AttributeUnstakeEpoch = "undelegation-epoch" AttributeValidatorAddress = "validator-address" AttributeExistingDelegation = "existing-delegation" From 052fc307c25ca37509aeeb5679858b8b3ec21166 Mon Sep 17 00:00:00 2001 From: kruspy Date: Tue, 17 Oct 2023 17:32:35 +0200 Subject: [PATCH 03/17] validator update events --- x/liquidstakeibc/keeper/host_chain.go | 50 +++++++++++++++++++ x/liquidstakeibc/types/events.go | 69 ++++++++++++++++----------- 2 files changed, 90 insertions(+), 29 deletions(-) diff --git a/x/liquidstakeibc/keeper/host_chain.go b/x/liquidstakeibc/keeper/host_chain.go index 70d0ec329..c942d70ad 100644 --- a/x/liquidstakeibc/keeper/host_chain.go +++ b/x/liquidstakeibc/keeper/host_chain.go @@ -2,6 +2,7 @@ package keeper import ( "fmt" + "strconv" "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" @@ -62,6 +63,17 @@ func (k *Keeper) ProcessHostChainValidatorUpdates( val.UnbondingEpoch = 0 } + // emit the status update event + ctx.EventManager().EmitEvent( + sdk.NewEvent( + types.EventTypeValidatorStatusUpdate, + sdk.NewAttribute(types.AttributeChainID, hc.ChainId), + sdk.NewAttribute(types.AttributeValidatorAddress, val.OperatorAddress), + sdk.NewAttribute(types.AttributeKeyValidatorOldStatus, val.Status), + sdk.NewAttribute(types.AttributeKeyValidatorNewStatus, validator.Status.String()), + ), + ) + val.Status = validator.Status.String() k.SetHostChainValidator(ctx, hc, val) } @@ -84,6 +96,17 @@ func (k *Keeper) ProcessHostChainValidatorUpdates( } } + // emit the exchange rate event + ctx.EventManager().EmitEvent( + sdk.NewEvent( + types.EventTypeValidatorExchangeRateUpdate, + sdk.NewAttribute(types.AttributeChainID, hc.ChainId), + sdk.NewAttribute(types.AttributeValidatorAddress, val.OperatorAddress), + sdk.NewAttribute(types.AttributeKeyValidatorOldExchangeRate, val.ExchangeRate.String()), + sdk.NewAttribute(types.AttributeKeyValidatorNewExchangeRate, exchangeRate.String()), + ), + ) + val.ExchangeRate = exchangeRate k.SetHostChainValidator(ctx, hc, val) } @@ -108,6 +131,9 @@ func (k *Keeper) ProcessHostChainValidatorUpdates( validatorHasEnoughBond = validator.LiquidShares.LT(validator.ValidatorBondShares.Mul(hc.Params.LsmBondFactor)) } + // save the old delegable flag for event purposes + oldDelegableFlag := val.Delegable + // update the validator if its delegable status has changed val.Delegable = validatorHasRoomForDelegations && validatorHasEnoughBond k.SetHostChainValidator(ctx, hc, val) @@ -122,6 +148,18 @@ func (k *Keeper) ProcessHostChainValidatorUpdates( // if the validator is not delegable, no messages will be generated for it, so there is nothing else to do if !val.Delegable { + // emit the delegable status event + if oldDelegableFlag != val.Delegable { + ctx.EventManager().EmitEvent( + sdk.NewEvent( + types.EventTypeValidatorDelegableStateUpdate, + sdk.NewAttribute(types.AttributeChainID, hc.ChainId), + sdk.NewAttribute(types.AttributeValidatorAddress, val.OperatorAddress), + sdk.NewAttribute(types.AttributeKeyValidatorDelegable, strconv.FormatBool(val.Delegable)), + ), + ) + } + return nil } @@ -173,6 +211,18 @@ func (k *Keeper) ProcessHostChainValidatorUpdates( // recalculate the delegable state of the validator with the new flag val.Delegable = validatorHasRoomForDelegations && validatorHasEnoughBond && validatorHasEnoughRoom k.SetHostChainValidator(ctx, hc, val) + + // emit the delegable status event + if oldDelegableFlag != val.Delegable { + ctx.EventManager().EmitEvent( + sdk.NewEvent( + types.EventTypeValidatorDelegableStateUpdate, + sdk.NewAttribute(types.AttributeChainID, hc.ChainId), + sdk.NewAttribute(types.AttributeValidatorAddress, val.OperatorAddress), + sdk.NewAttribute(types.AttributeKeyValidatorDelegable, strconv.FormatBool(val.Delegable)), + ), + ) + } } return nil diff --git a/x/liquidstakeibc/types/events.go b/x/liquidstakeibc/types/events.go index 7a812ecc4..beceae54e 100644 --- a/x/liquidstakeibc/types/events.go +++ b/x/liquidstakeibc/types/events.go @@ -1,34 +1,45 @@ package types const ( - EventTypeLiquidStake = "liquid-stake" - EventTypeLiquidStakeLSM = "liquid-stake-lsm" - EventTypeLiquidUnstake = "liquid-unstake" - EventTypeRedeem = "redeem" - EventTypePacket = "ics27-packet" - EventTypeTimeout = "timeout" - EventTypeSlashing = "slashing" - EventTypeUpdateParams = "update-params" - EventTypeChainDisabled = "chain-disabled" + EventTypeLiquidStake = "liquid_stake" + EventTypeLiquidStakeLSM = "liquid_stake_lsm" + EventTypeLiquidUnstake = "liquid_unstake" + EventTypeRedeem = "redeem" + EventTypePacket = "ics27_packet" + EventTypeTimeout = "timeout" + EventTypeSlashing = "slashing" + EventTypeUpdateParams = "update_params" + EventTypeChainDisabled = "chain_disabled" + EventTypeValidatorStatusUpdate = "validator_status_update" + EventTypeValidatorExchangeRateUpdate = "validator_exchange_rate_update" + EventTypeValidatorDelegableStateUpdate = "validator_delegable_state_update" + EventTypeValidatorWeightUpdate = "validator_weight_update" - AttributeInputAmount = "input-amount" - AttributeOutputAmount = "output-amount" - AttributeDelegatorAddress = "address" - AttributePstakeDepositFee = "pstake-deposit-fee" - AttributePstakeUnstakeFee = "pstake-unstake-fee" - AttributePstakeRedeemFee = "pstake-redeem-fee" - AttributeChainID = "chain-id" - AttributeNewCValue = "new-c-value" - AttributeOldCValue = "old-c-value" - AttributeUnstakeEpoch = "undelegation-epoch" - AttributeValidatorAddress = "validator-address" - AttributeExistingDelegation = "existing-delegation" - AttributeUpdatedDelegation = "updated-delegation" - AttributeSlashedAmount = "slashed-amount" - AttributeKeyAuthority = "authority" - AttributeKeyUpdatedParams = "updated_params" - AttributeKeyAck = "acknowledgement" - AttributeKeyAckSuccess = "success" - AttributeKeyAckError = "error" - AttributeValueCategory = ModuleName + AttributeInputAmount = "input_amount" + AttributeOutputAmount = "output_amount" + AttributeDelegatorAddress = "address" + AttributePstakeDepositFee = "pstake_deposit_fee" + AttributePstakeUnstakeFee = "pstake_unstake_fee" + AttributePstakeRedeemFee = "pstake_redeem_fee" + AttributeChainID = "chain_id" + AttributeNewCValue = "new_c_value" + AttributeOldCValue = "old_c_value" + AttributeUnstakeEpoch = "undelegation_epoch" + AttributeValidatorAddress = "validator_address" + AttributeExistingDelegation = "existing_delegation" + AttributeUpdatedDelegation = "updated_delegation" + AttributeSlashedAmount = "slashed_amount" + AttributeKeyAuthority = "authority" + AttributeKeyUpdatedParams = "updated_params" + AttributeKeyAck = "acknowledgement" + AttributeKeyAckSuccess = "success" + AttributeKeyAckError = "error" + AttributeKeyValidatorNewStatus = "validator_new_status" + AttributeKeyValidatorOldStatus = "validator_old_status" + AttributeKeyValidatorNewExchangeRate = "validator_new_exchange_rate" + AttributeKeyValidatorOldExchangeRate = "validator_old_exchange_rate" + AttributeKeyValidatorNewWeight = "validator_new_weight" + AttributeKeyValidatorOldWeight = "validator_old_weight" + AttributeKeyValidatorDelegable = "validator_delegable" + AttributeValueCategory = ModuleName ) From 30d4cd9c84df413615cb1d6fc310ea03c43547d6 Mon Sep 17 00:00:00 2001 From: kruspy Date: Tue, 17 Oct 2023 19:32:18 +0200 Subject: [PATCH 04/17] delegation events --- x/liquidstakeibc/keeper/abci.go | 19 +++++++++++++++++++ x/liquidstakeibc/keeper/msg_server.go | 2 +- x/liquidstakeibc/types/events.go | 9 +++++---- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/x/liquidstakeibc/keeper/abci.go b/x/liquidstakeibc/keeper/abci.go index 6297cc09e..131f3d6fd 100644 --- a/x/liquidstakeibc/keeper/abci.go +++ b/x/liquidstakeibc/keeper/abci.go @@ -1,7 +1,10 @@ package keeper import ( + "encoding/base64" + "encoding/json" "fmt" + "strconv" "time" sdk "github.com/cosmos/cosmos-sdk/types" @@ -82,11 +85,27 @@ func (k *Keeper) DoDelegate(ctx sdk.Context, hc *types.HostChain) { } // if everything went well, update the deposit states and set the sequence id + lastEpoch := 0 // highest epoch among deposits, used for event emission for _, deposit := range deposits { deposit.IbcSequenceId = sequenceID deposit.State = types.Deposit_DEPOSIT_DELEGATING k.SetDeposit(ctx, deposit) + + lastEpoch = int(deposit.Epoch) } + + // emit the delegation event + encMsgs, _ := json.Marshal(&messages) + ctx.EventManager().EmitEvent( + sdk.NewEvent( + types.EventTypeDoDelegation, + sdk.NewAttribute(types.AttributeChainID, hc.ChainId), + sdk.NewAttribute(types.AttributeEpoch, strconv.Itoa(lastEpoch)), + sdk.NewAttribute(types.AttributeTotalDelegatedAmount, sdk.NewCoin(hc.HostDenom, totalDepositDelegation).String()), + sdk.NewAttribute(types.AttributeICAMessages, base64.StdEncoding.EncodeToString(encMsgs)), + sdk.NewAttribute(types.AttributeIBCSequenceID, sequenceID), + ), + ) } func (k *Keeper) DoClaim(ctx sdk.Context, hc *types.HostChain) { diff --git a/x/liquidstakeibc/keeper/msg_server.go b/x/liquidstakeibc/keeper/msg_server.go index 3af6e4b18..139aa1990 100644 --- a/x/liquidstakeibc/keeper/msg_server.go +++ b/x/liquidstakeibc/keeper/msg_server.go @@ -665,7 +665,7 @@ func (k msgServer) LiquidUnstake( sdktypes.NewCoin(hc.HostDenom, unbondAmount.Amount).String()), sdktypes.NewAttribute(types.AttributePstakeUnstakeFee, sdktypes.NewCoin(hc.MintDenom(), feeAmount).String()), - sdktypes.NewAttribute(types.AttributeUnstakeEpoch, strconv.FormatInt(unbondingEpoch, 10)), + sdktypes.NewAttribute(types.AttributeEpoch, strconv.FormatInt(unbondingEpoch, 10)), ), sdktypes.NewEvent( sdktypes.EventTypeMessage, diff --git a/x/liquidstakeibc/types/events.go b/x/liquidstakeibc/types/events.go index beceae54e..0d81c3030 100644 --- a/x/liquidstakeibc/types/events.go +++ b/x/liquidstakeibc/types/events.go @@ -13,7 +13,7 @@ const ( EventTypeValidatorStatusUpdate = "validator_status_update" EventTypeValidatorExchangeRateUpdate = "validator_exchange_rate_update" EventTypeValidatorDelegableStateUpdate = "validator_delegable_state_update" - EventTypeValidatorWeightUpdate = "validator_weight_update" + EventTypeDoDelegation = "send_delegation" AttributeInputAmount = "input_amount" AttributeOutputAmount = "output_amount" @@ -24,7 +24,7 @@ const ( AttributeChainID = "chain_id" AttributeNewCValue = "new_c_value" AttributeOldCValue = "old_c_value" - AttributeUnstakeEpoch = "undelegation_epoch" + AttributeEpoch = "epoch_number" AttributeValidatorAddress = "validator_address" AttributeExistingDelegation = "existing_delegation" AttributeUpdatedDelegation = "updated_delegation" @@ -38,8 +38,9 @@ const ( AttributeKeyValidatorOldStatus = "validator_old_status" AttributeKeyValidatorNewExchangeRate = "validator_new_exchange_rate" AttributeKeyValidatorOldExchangeRate = "validator_old_exchange_rate" - AttributeKeyValidatorNewWeight = "validator_new_weight" - AttributeKeyValidatorOldWeight = "validator_old_weight" AttributeKeyValidatorDelegable = "validator_delegable" + AttributeTotalDelegatedAmount = "total_delegated_amount" + AttributeIBCSequenceID = "ibc_sequence_id" + AttributeICAMessages = "ica_messages" AttributeValueCategory = ModuleName ) From 1fa8f373a887c6f5cad312d5c5737469de13310c Mon Sep 17 00:00:00 2001 From: kruspy Date: Wed, 18 Oct 2023 12:15:48 +0200 Subject: [PATCH 05/17] claim events --- x/liquidstakeibc/keeper/abci.go | 19 ++++++++++++++++--- x/liquidstakeibc/types/events.go | 3 +++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/x/liquidstakeibc/keeper/abci.go b/x/liquidstakeibc/keeper/abci.go index 131f3d6fd..d3cbafa9a 100644 --- a/x/liquidstakeibc/keeper/abci.go +++ b/x/liquidstakeibc/keeper/abci.go @@ -85,13 +85,13 @@ func (k *Keeper) DoDelegate(ctx sdk.Context, hc *types.HostChain) { } // if everything went well, update the deposit states and set the sequence id - lastEpoch := 0 // highest epoch among deposits, used for event emission + lastEpoch := int64(0) // highest epoch among deposits, used for event emission for _, deposit := range deposits { deposit.IbcSequenceId = sequenceID deposit.State = types.Deposit_DEPOSIT_DELEGATING k.SetDeposit(ctx, deposit) - lastEpoch = int(deposit.Epoch) + lastEpoch = deposit.Epoch } // emit the delegation event @@ -100,7 +100,7 @@ func (k *Keeper) DoDelegate(ctx sdk.Context, hc *types.HostChain) { sdk.NewEvent( types.EventTypeDoDelegation, sdk.NewAttribute(types.AttributeChainID, hc.ChainId), - sdk.NewAttribute(types.AttributeEpoch, strconv.Itoa(lastEpoch)), + sdk.NewAttribute(types.AttributeEpoch, strconv.FormatInt(lastEpoch, 10)), sdk.NewAttribute(types.AttributeTotalDelegatedAmount, sdk.NewCoin(hc.HostDenom, totalDepositDelegation).String()), sdk.NewAttribute(types.AttributeICAMessages, base64.StdEncoding.EncodeToString(encMsgs)), sdk.NewAttribute(types.AttributeIBCSequenceID, sequenceID), @@ -133,12 +133,15 @@ func (k *Keeper) DoClaim(ctx sdk.Context, hc *types.HostChain) { } var claimableCoins sdk.Coins + var eventAmount sdk.Coin // used for claim events switch unbonding.State { case types.Unbonding_UNBONDING_CLAIMABLE: claimableCoins = sdk.NewCoins(sdk.NewCoin(hc.IBCDenom(), userUnbonding.UnbondAmount.Amount)) + eventAmount = sdk.NewCoin(hc.HostDenom, userUnbonding.UnbondAmount.Amount) unbonding.UnbondAmount = unbonding.UnbondAmount.Sub(userUnbonding.UnbondAmount) case types.Unbonding_UNBONDING_FAILED: claimableCoins = sdk.NewCoins(sdk.NewCoin(hc.MintDenom(), userUnbonding.StkAmount.Amount)) + eventAmount = sdk.NewCoin(hc.MintDenom(), userUnbonding.StkAmount.Amount) unbonding.BurnAmount = unbonding.BurnAmount.Sub(userUnbonding.StkAmount) } @@ -167,6 +170,16 @@ func (k *Keeper) DoClaim(ctx sdk.Context, hc *types.HostChain) { } k.DeleteUserUnbonding(ctx, userUnbonding) + + ctx.EventManager().EmitEvent( + sdk.NewEvent( + types.EventTypeClaimedUnbondings, + sdk.NewAttribute(types.AttributeChainID, hc.ChainId), + sdk.NewAttribute(types.AttributeEpoch, strconv.FormatInt(epochNumber, 10)), + sdk.NewAttribute(types.AttributeClaimAmount, eventAmount.String()), + sdk.NewAttribute(types.AttributeClaimAddress, userUnbonding.Address), + ), + ) } } } diff --git a/x/liquidstakeibc/types/events.go b/x/liquidstakeibc/types/events.go index 0d81c3030..0d1632bfb 100644 --- a/x/liquidstakeibc/types/events.go +++ b/x/liquidstakeibc/types/events.go @@ -14,6 +14,7 @@ const ( EventTypeValidatorExchangeRateUpdate = "validator_exchange_rate_update" EventTypeValidatorDelegableStateUpdate = "validator_delegable_state_update" EventTypeDoDelegation = "send_delegation" + EventTypeClaimedUnbondings = "claimed_unbondings" AttributeInputAmount = "input_amount" AttributeOutputAmount = "output_amount" @@ -42,5 +43,7 @@ const ( AttributeTotalDelegatedAmount = "total_delegated_amount" AttributeIBCSequenceID = "ibc_sequence_id" AttributeICAMessages = "ica_messages" + AttributeClaimAmount = "claimed_amount" + AttributeClaimAddress = "claim_address" AttributeValueCategory = ModuleName ) From d5f4b9051cfabbe08b343c53ddb575463f0a928b Mon Sep 17 00:00:00 2001 From: kruspy Date: Wed, 18 Oct 2023 12:29:03 +0200 Subject: [PATCH 06/17] lsm untokenize events --- x/liquidstakeibc/keeper/abci.go | 11 +++++++++++ x/liquidstakeibc/types/events.go | 1 + 2 files changed, 12 insertions(+) diff --git a/x/liquidstakeibc/keeper/abci.go b/x/liquidstakeibc/keeper/abci.go index d3cbafa9a..59986e885 100644 --- a/x/liquidstakeibc/keeper/abci.go +++ b/x/liquidstakeibc/keeper/abci.go @@ -338,4 +338,15 @@ func (k *Keeper) DoRedeemLSMTokens(ctx sdk.Context, hc *types.HostChain) { "sequence-id", sequenceID, ) + + // emit the untokenize event + encMsgs, _ := json.Marshal(&messages) + ctx.EventManager().EmitEvent( + sdk.NewEvent( + types.EventTypeRedeemTokensForShares, + sdk.NewAttribute(types.AttributeChainID, hc.ChainId), + sdk.NewAttribute(types.AttributeICAMessages, base64.StdEncoding.EncodeToString(encMsgs)), + sdk.NewAttribute(types.AttributeIBCSequenceID, sequenceID), + ), + ) } diff --git a/x/liquidstakeibc/types/events.go b/x/liquidstakeibc/types/events.go index 0d1632bfb..e5e659145 100644 --- a/x/liquidstakeibc/types/events.go +++ b/x/liquidstakeibc/types/events.go @@ -15,6 +15,7 @@ const ( EventTypeValidatorDelegableStateUpdate = "validator_delegable_state_update" EventTypeDoDelegation = "send_delegation" EventTypeClaimedUnbondings = "claimed_unbondings" + EventTypeRedeemTokensForShares = "redeem_lsm_tokens_shares" AttributeInputAmount = "input_amount" AttributeOutputAmount = "output_amount" From 44106cec8538a305fdd349ecfd2777105b70a0fa Mon Sep 17 00:00:00 2001 From: kruspy Date: Wed, 18 Oct 2023 14:21:16 +0200 Subject: [PATCH 07/17] epoch events --- x/liquidstakeibc/keeper/hooks.go | 63 +++++++++++++++++++++++++++++++ x/liquidstakeibc/keeper/keeper.go | 15 ++++++++ x/liquidstakeibc/types/events.go | 17 +++++++++ 3 files changed, 95 insertions(+) diff --git a/x/liquidstakeibc/keeper/hooks.go b/x/liquidstakeibc/keeper/hooks.go index 4420f5ec9..63b7e73ad 100644 --- a/x/liquidstakeibc/keeper/hooks.go +++ b/x/liquidstakeibc/keeper/hooks.go @@ -1,10 +1,14 @@ package keeper import ( + "encoding/base64" + "encoding/json" "fmt" + "strconv" "time" errorsmod "cosmossdk.io/errors" + "cosmossdk.io/math" "github.com/cosmos/cosmos-sdk/telemetry" sdk "github.com/cosmos/cosmos-sdk/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" @@ -474,6 +478,16 @@ func (k *Keeper) DepositWorkflow(ctx sdk.Context, epoch int64) { deposit.State = liquidstakeibctypes.Deposit_DEPOSIT_SENT deposit.IbcSequenceId = k.GetTransactionSequenceID(hc.ChannelId, msgTransferResponse.Sequence) k.SetDeposit(ctx, deposit) + + ctx.EventManager().EmitEvent( + sdk.NewEvent( + liquidstakeibctypes.EventTypeDelegationWorkflow, + sdk.NewAttribute(liquidstakeibctypes.AttributeChainID, hc.ChainId), + sdk.NewAttribute(liquidstakeibctypes.AttributeEpoch, strconv.FormatInt(deposit.Epoch, 10)), + sdk.NewAttribute(liquidstakeibctypes.AttributeTotalEpochDepositAmount, sdk.NewCoin(hc.HostDenom, deposit.Amount.Amount).String()), + sdk.NewAttribute(liquidstakeibctypes.AttributeIBCSequenceID, deposit.IbcSequenceId), + ), + ) } } @@ -545,6 +559,20 @@ func (k *Keeper) UndelegationWorkflow(ctx sdk.Context, epoch int64) { unbonding.IbcSequenceId = sequenceID unbonding.State = liquidstakeibctypes.Unbonding_UNBONDING_INITIATED k.SetUnbonding(ctx, unbonding) + + // emit the unbonding event + encMsgs, _ := json.Marshal(&messages) + ctx.EventManager().EmitEvent( + sdk.NewEvent( + liquidstakeibctypes.EventTypeUndelegationWorkflow, + sdk.NewAttribute(liquidstakeibctypes.AttributeChainID, hc.ChainId), + sdk.NewAttribute(liquidstakeibctypes.AttributeEpoch, strconv.FormatInt(epoch, 10)), + sdk.NewAttribute(liquidstakeibctypes.AttributeTotalEpochUnbondingAmount, sdk.NewCoin(hc.HostDenom, unbonding.UnbondAmount.Amount).String()), + sdk.NewAttribute(liquidstakeibctypes.AttributeTotalEpochBurnAmount, sdk.NewCoin(hc.HostDenom, unbonding.BurnAmount.Amount).String()), + sdk.NewAttribute(liquidstakeibctypes.AttributeICAMessages, base64.StdEncoding.EncodeToString(encMsgs)), + sdk.NewAttribute(liquidstakeibctypes.AttributeIBCSequenceID, sequenceID), + ), + ) } } @@ -619,6 +647,18 @@ func (k *Keeper) ValidatorUndelegationWorkflow(ctx sdk.Context, epoch int64) { "epoch", epoch, ) + + // emit the validator unbonding event + ctx.EventManager().EmitEvent( + sdk.NewEvent( + liquidstakeibctypes.EventTypeValidatorUndelegationWorkflow, + sdk.NewAttribute(liquidstakeibctypes.AttributeChainID, hc.ChainId), + sdk.NewAttribute(liquidstakeibctypes.AttributeEpoch, strconv.FormatInt(epoch, 10)), + sdk.NewAttribute(liquidstakeibctypes.AttributeValidatorAddress, validatorUnbonding.ValidatorAddress), + sdk.NewAttribute(liquidstakeibctypes.AttributeValidatorUnbondingAmount, sdk.NewCoin(hc.HostDenom, validatorUnbonding.Amount.Amount).String()), + sdk.NewAttribute(liquidstakeibctypes.AttributeIBCSequenceID, sequenceID), + ), + ) } } } @@ -661,6 +701,17 @@ func (k *Keeper) RewardsWorkflow(ctx sdk.Context, epoch int64) { ) continue } + + // emit the rewards event + encMsgs, _ := json.Marshal(&messages) + ctx.EventManager().EmitEvent( + sdk.NewEvent( + liquidstakeibctypes.EventTypeRewardsWorkflow, + sdk.NewAttribute(liquidstakeibctypes.AttributeChainID, hc.ChainId), + sdk.NewAttribute(liquidstakeibctypes.AttributeEpoch, strconv.FormatInt(epoch, 10)), + sdk.NewAttribute(liquidstakeibctypes.AttributeICAMessages, base64.StdEncoding.EncodeToString(encMsgs)), + ), + ) } if hc.RewardsAccount != nil && @@ -685,6 +736,7 @@ func (k *Keeper) LSMWorkflow(ctx sdk.Context) { } // attempt to transfer all available LSM deposits + totalLSMDepositsSharesAmount := math.LegacyZeroDec() for _, deposit := range k.GetTransferableLSMDeposits(ctx, hc.ChainId) { clientState, err := k.GetClientState(ctx, hc.ConnectionId) if err != nil { @@ -732,6 +784,17 @@ func (k *Keeper) LSMWorkflow(ctx sdk.Context) { liquidstakeibctypes.LSMDeposit_DEPOSIT_SENT, k.GetTransactionSequenceID(hc.ChannelId, msgTransferResponse.Sequence), ) + + totalLSMDepositsSharesAmount = totalLSMDepositsSharesAmount.Add(deposit.Shares) } + + // emit the validator unbonding event + ctx.EventManager().EmitEvent( + sdk.NewEvent( + liquidstakeibctypes.EventTypeLSMWorkflow, + sdk.NewAttribute(liquidstakeibctypes.AttributeChainID, hc.ChainId), + sdk.NewAttribute(liquidstakeibctypes.AttributeLSMDepositsSharesAmount, totalLSMDepositsSharesAmount.String()), + ), + ) } } diff --git a/x/liquidstakeibc/keeper/keeper.go b/x/liquidstakeibc/keeper/keeper.go index 12c3d071c..99b59d14f 100644 --- a/x/liquidstakeibc/keeper/keeper.go +++ b/x/liquidstakeibc/keeper/keeper.go @@ -303,6 +303,21 @@ func (k *Keeper) UpdateCValues(ctx sdk.Context) { hc.CValue = cValue k.SetHostChain(ctx, hc) + ctx.EventManager().EmitEvent( + sdk.NewEvent( + types.EventTypeCValueUpdate, + sdk.NewAttribute(types.AttributeChainID, hc.ChainId), + sdk.NewAttribute(types.AttributeModuleMintedAmount, sdk.NewCoin(hc.MintDenom(), mintedAmount).String()), + sdk.NewAttribute(types.AttributeModuleLSMTokenizedAmount, sdk.NewCoin(hc.HostDenom, tokenizedStakedAmount).String()), + sdk.NewAttribute(types.AttributeModuleStakedAmount, sdk.NewCoin(hc.HostDenom, stakedAmount).String()), + sdk.NewAttribute(types.AttributeModuleAmountOnPersistence, sdk.NewCoin(hc.HostDenom, amountOnPersistence).String()), + sdk.NewAttribute(types.AttributeModuleAmountOnHostChain, sdk.NewCoin(hc.HostDenom, amountOnHostChain).String()), + sdk.NewAttribute(types.AttributeModuleUnbondingAmount, sdk.NewCoin(hc.HostDenom, totalUnbondingAmount).String()), + sdk.NewAttribute(types.AttributeOldCValue, hc.LastCValue.String()), + sdk.NewAttribute(types.AttributeNewCValue, hc.CValue.String()), + ), + ) + defer func() { cValueFloat, _ := hc.CValue.Float64() telemetry.ModuleSetGauge(types.ModuleName, float32(cValueFloat), hc.ChainId, "c_value") diff --git a/x/liquidstakeibc/types/events.go b/x/liquidstakeibc/types/events.go index e5e659145..2195dff99 100644 --- a/x/liquidstakeibc/types/events.go +++ b/x/liquidstakeibc/types/events.go @@ -16,6 +16,12 @@ const ( EventTypeDoDelegation = "send_delegation" EventTypeClaimedUnbondings = "claimed_unbondings" EventTypeRedeemTokensForShares = "redeem_lsm_tokens_shares" + EventTypeCValueUpdate = "c_value_update" + EventTypeDelegationWorkflow = "delegation_workflow" + EventTypeUndelegationWorkflow = "undelegation_workflow" + EventTypeValidatorUndelegationWorkflow = "validator_undelegation_workflow" + EventTypeRewardsWorkflow = "rewards_workflow" + EventTypeLSMWorkflow = "lsm_workflow" AttributeInputAmount = "input_amount" AttributeOutputAmount = "output_amount" @@ -46,5 +52,16 @@ const ( AttributeICAMessages = "ica_messages" AttributeClaimAmount = "claimed_amount" AttributeClaimAddress = "claim_address" + AttributeModuleMintedAmount = "minted_amount" + AttributeModuleLSMTokenizedAmount = "lsm_tokenized_amount" + AttributeModuleStakedAmount = "staked_amount" + AttributeModuleAmountOnPersistence = "amount_on_persistence" + AttributeModuleAmountOnHostChain = "amount_on_host_chain" + AttributeModuleUnbondingAmount = "unbonding_amount" + AttributeTotalEpochDepositAmount = "deposit_amount" + AttributeTotalEpochUnbondingAmount = "unbonding_amount" + AttributeTotalEpochBurnAmount = "burn_amount" + AttributeValidatorUnbondingAmount = "validator_unbonding_amount" + AttributeLSMDepositsSharesAmount = "lsm_deposits_shares_amount" AttributeValueCategory = ModuleName ) From 0fa68e275a6d23295b207238e45757e7553fea16 Mon Sep 17 00:00:00 2001 From: kruspy Date: Wed, 18 Oct 2023 17:02:52 +0200 Subject: [PATCH 08/17] icq events --- x/liquidstakeibc/keeper/icq.go | 9 +++++++++ x/liquidstakeibc/types/events.go | 8 +++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/x/liquidstakeibc/keeper/icq.go b/x/liquidstakeibc/keeper/icq.go index 4aec2d360..59870ae7b 100644 --- a/x/liquidstakeibc/keeper/icq.go +++ b/x/liquidstakeibc/keeper/icq.go @@ -171,6 +171,15 @@ func RewardsAccountBalanceCallback(k Keeper, ctx sdk.Context, data []byte, query if err != nil { return fmt.Errorf("could not send ICA rewards transfer: %w", err) } + + ctx.EventManager().EmitEvent( + sdk.NewEvent( + types.EventTypeRewardsTransfer, + sdk.NewAttribute(types.AttributeChainID, hc.ChainId), + sdk.NewAttribute(types.AttributeRewardsTransferAmount, sdk.NewCoin(hc.HostDenom, autocompoundRewards.Amount).String()), + sdk.NewAttribute(types.AttributeRewardsBalanceAmount, sdk.NewCoin(hc.HostDenom, hc.RewardsAccount.Balance.Amount.Sub(autocompoundRewards.Amount)).String()), + ), + ) } k.SetHostChain(ctx, hc) diff --git a/x/liquidstakeibc/types/events.go b/x/liquidstakeibc/types/events.go index 2195dff99..a00aef509 100644 --- a/x/liquidstakeibc/types/events.go +++ b/x/liquidstakeibc/types/events.go @@ -7,7 +7,7 @@ const ( EventTypeRedeem = "redeem" EventTypePacket = "ics27_packet" EventTypeTimeout = "timeout" - EventTypeSlashing = "slashing" + EventTypeSlashing = "validator_slash" EventTypeUpdateParams = "update_params" EventTypeChainDisabled = "chain_disabled" EventTypeValidatorStatusUpdate = "validator_status_update" @@ -22,6 +22,8 @@ const ( EventTypeValidatorUndelegationWorkflow = "validator_undelegation_workflow" EventTypeRewardsWorkflow = "rewards_workflow" EventTypeLSMWorkflow = "lsm_workflow" + EventTypeRewardsTransfer = "rewards_transfer" + EventTypeValidatorSlash = "validator_slash" AttributeInputAmount = "input_amount" AttributeOutputAmount = "output_amount" @@ -63,5 +65,9 @@ const ( AttributeTotalEpochBurnAmount = "burn_amount" AttributeValidatorUnbondingAmount = "validator_unbonding_amount" AttributeLSMDepositsSharesAmount = "lsm_deposits_shares_amount" + AttributeRewardsTransferAmount = "rewards_transfer_amount" + AttributeRewardsBalanceAmount = "rewards_balance_amount" + AttributeSlashAmount = "slash_amount" + AttributeNewDelegatedAmount = "new_delegated_amount" AttributeValueCategory = ModuleName ) From 6a0e4b416700cc32b0d857ca94f1e50dd5f70d35 Mon Sep 17 00:00:00 2001 From: kruspy Date: Wed, 18 Oct 2023 17:35:08 +0200 Subject: [PATCH 09/17] IBC transfer events --- x/liquidstakeibc/keeper/hooks.go | 28 +++++++ x/liquidstakeibc/keeper/icq.go | 4 +- x/liquidstakeibc/types/events.go | 140 ++++++++++++++++--------------- 3 files changed, 103 insertions(+), 69 deletions(-) diff --git a/x/liquidstakeibc/keeper/hooks.go b/x/liquidstakeibc/keeper/hooks.go index 63b7e73ad..6e3852e72 100644 --- a/x/liquidstakeibc/keeper/hooks.go +++ b/x/liquidstakeibc/keeper/hooks.go @@ -182,6 +182,16 @@ func (k *Keeper) OnRecvIBCTransferPacket( unbonding.IbcSequenceId = "" unbonding.State = liquidstakeibctypes.Unbonding_UNBONDING_CLAIMABLE k.SetUnbonding(ctx, unbonding) + + // emit event for the received transfer + ctx.EventManager().EmitEvents(sdk.Events{ + sdk.NewEvent( + liquidstakeibctypes.EventTypeUnbondingMaturedReceived, + sdk.NewAttribute(liquidstakeibctypes.AttributeChainID, hc.ChainId), + sdk.NewAttribute(liquidstakeibctypes.AttributeEpoch, strconv.FormatInt(unbonding.EpochNumber, 10)), + sdk.NewAttribute(liquidstakeibctypes.AttributeUnbondingMaturedAmount, sdk.NewCoin(hc.HostDenom, unbonding.UnbondAmount.Amount).String()), + ), + }) } } @@ -224,6 +234,14 @@ func (k *Keeper) OnRecvIBCTransferPacket( deposit.Amount.Amount = deposit.Amount.Amount.Add(transferAmount) k.SetDeposit(ctx, deposit) + + ctx.EventManager().EmitEvents(sdk.Events{ + sdk.NewEvent( + liquidstakeibctypes.EventTypeValidatorUnbondingMaturedReceived, + sdk.NewAttribute(liquidstakeibctypes.AttributeChainID, hc.ChainId), + sdk.NewAttribute(liquidstakeibctypes.AttributeValidatorUnbondingMaturedAmount, sdk.NewCoin(hc.HostDenom, transferAmount).String()), + ), + }) } // the transfer is part of the autocompounding process @@ -287,6 +305,16 @@ func (k *Keeper) OnRecvIBCTransferPacket( // update the deposit deposit.Amount.Amount = deposit.Amount.Amount.Add(transferAmount.Sub(feeAmount.TruncateInt())) k.SetDeposit(ctx, deposit) + + // emit autocompound received event + ctx.EventManager().EmitEvents(sdk.Events{ + sdk.NewEvent( + liquidstakeibctypes.EventAutocompoundRewardsReceived, + sdk.NewAttribute(liquidstakeibctypes.AttributeChainID, hc.ChainId), + sdk.NewAttribute(liquidstakeibctypes.AttributeValidatorUnbondingMaturedAmount, sdk.NewCoin(hc.HostDenom, transferAmount).String()), + sdk.NewAttribute(liquidstakeibctypes.AttributePstakeAutocompoundFee, sdk.NewCoin(hc.HostDenom, feeAmount.TruncateInt()).String()), + ), + }) } return nil diff --git a/x/liquidstakeibc/keeper/icq.go b/x/liquidstakeibc/keeper/icq.go index 59870ae7b..0796ed02a 100644 --- a/x/liquidstakeibc/keeper/icq.go +++ b/x/liquidstakeibc/keeper/icq.go @@ -108,11 +108,13 @@ func DelegationCallback(k Keeper, ctx sdk.Context, data []byte, query icqtypes.Q ctx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( types.EventTypeSlashing, + sdk.NewAttribute(types.AttributeChainID, hc.ChainId), sdk.NewAttribute(types.AttributeValidatorAddress, validator.OperatorAddress), sdk.NewAttribute(types.AttributeExistingDelegation, validator.DelegatedAmount.String()), sdk.NewAttribute(types.AttributeUpdatedDelegation, delegatedAmount.String()), sdk.NewAttribute(types.AttributeSlashedAmount, slashedAmount.String()), - )}) + ), + }) } return nil diff --git a/x/liquidstakeibc/types/events.go b/x/liquidstakeibc/types/events.go index a00aef509..e709f44e9 100644 --- a/x/liquidstakeibc/types/events.go +++ b/x/liquidstakeibc/types/events.go @@ -1,73 +1,77 @@ package types const ( - EventTypeLiquidStake = "liquid_stake" - EventTypeLiquidStakeLSM = "liquid_stake_lsm" - EventTypeLiquidUnstake = "liquid_unstake" - EventTypeRedeem = "redeem" - EventTypePacket = "ics27_packet" - EventTypeTimeout = "timeout" - EventTypeSlashing = "validator_slash" - EventTypeUpdateParams = "update_params" - EventTypeChainDisabled = "chain_disabled" - EventTypeValidatorStatusUpdate = "validator_status_update" - EventTypeValidatorExchangeRateUpdate = "validator_exchange_rate_update" - EventTypeValidatorDelegableStateUpdate = "validator_delegable_state_update" - EventTypeDoDelegation = "send_delegation" - EventTypeClaimedUnbondings = "claimed_unbondings" - EventTypeRedeemTokensForShares = "redeem_lsm_tokens_shares" - EventTypeCValueUpdate = "c_value_update" - EventTypeDelegationWorkflow = "delegation_workflow" - EventTypeUndelegationWorkflow = "undelegation_workflow" - EventTypeValidatorUndelegationWorkflow = "validator_undelegation_workflow" - EventTypeRewardsWorkflow = "rewards_workflow" - EventTypeLSMWorkflow = "lsm_workflow" - EventTypeRewardsTransfer = "rewards_transfer" - EventTypeValidatorSlash = "validator_slash" + EventTypeLiquidStake = "liquid_stake" + EventTypeLiquidStakeLSM = "liquid_stake_lsm" + EventTypeLiquidUnstake = "liquid_unstake" + EventTypeRedeem = "redeem" + EventTypePacket = "ics27_packet" + EventTypeTimeout = "timeout" + EventTypeSlashing = "validator_slash" + EventTypeUpdateParams = "update_params" + EventTypeChainDisabled = "chain_disabled" + EventTypeValidatorStatusUpdate = "validator_status_update" + EventTypeValidatorExchangeRateUpdate = "validator_exchange_rate_update" + EventTypeValidatorDelegableStateUpdate = "validator_delegable_state_update" + EventTypeDoDelegation = "send_delegation" + EventTypeClaimedUnbondings = "claimed_unbondings" + EventTypeRedeemTokensForShares = "redeem_lsm_tokens_shares" + EventTypeCValueUpdate = "c_value_update" + EventTypeDelegationWorkflow = "delegation_workflow" + EventTypeUndelegationWorkflow = "undelegation_workflow" + EventTypeValidatorUndelegationWorkflow = "validator_undelegation_workflow" + EventTypeRewardsWorkflow = "rewards_workflow" + EventTypeLSMWorkflow = "lsm_workflow" + EventTypeRewardsTransfer = "rewards_transfer" + EventTypeUnbondingMaturedReceived = "unbonding_matured" + EventTypeValidatorUnbondingMaturedReceived = "validator_unbonding_matured" + EventAutocompoundRewardsReceived = "autocompound_rewards_received" - AttributeInputAmount = "input_amount" - AttributeOutputAmount = "output_amount" - AttributeDelegatorAddress = "address" - AttributePstakeDepositFee = "pstake_deposit_fee" - AttributePstakeUnstakeFee = "pstake_unstake_fee" - AttributePstakeRedeemFee = "pstake_redeem_fee" - AttributeChainID = "chain_id" - AttributeNewCValue = "new_c_value" - AttributeOldCValue = "old_c_value" - AttributeEpoch = "epoch_number" - AttributeValidatorAddress = "validator_address" - AttributeExistingDelegation = "existing_delegation" - AttributeUpdatedDelegation = "updated_delegation" - AttributeSlashedAmount = "slashed_amount" - AttributeKeyAuthority = "authority" - AttributeKeyUpdatedParams = "updated_params" - AttributeKeyAck = "acknowledgement" - AttributeKeyAckSuccess = "success" - AttributeKeyAckError = "error" - AttributeKeyValidatorNewStatus = "validator_new_status" - AttributeKeyValidatorOldStatus = "validator_old_status" - AttributeKeyValidatorNewExchangeRate = "validator_new_exchange_rate" - AttributeKeyValidatorOldExchangeRate = "validator_old_exchange_rate" - AttributeKeyValidatorDelegable = "validator_delegable" - AttributeTotalDelegatedAmount = "total_delegated_amount" - AttributeIBCSequenceID = "ibc_sequence_id" - AttributeICAMessages = "ica_messages" - AttributeClaimAmount = "claimed_amount" - AttributeClaimAddress = "claim_address" - AttributeModuleMintedAmount = "minted_amount" - AttributeModuleLSMTokenizedAmount = "lsm_tokenized_amount" - AttributeModuleStakedAmount = "staked_amount" - AttributeModuleAmountOnPersistence = "amount_on_persistence" - AttributeModuleAmountOnHostChain = "amount_on_host_chain" - AttributeModuleUnbondingAmount = "unbonding_amount" - AttributeTotalEpochDepositAmount = "deposit_amount" - AttributeTotalEpochUnbondingAmount = "unbonding_amount" - AttributeTotalEpochBurnAmount = "burn_amount" - AttributeValidatorUnbondingAmount = "validator_unbonding_amount" - AttributeLSMDepositsSharesAmount = "lsm_deposits_shares_amount" - AttributeRewardsTransferAmount = "rewards_transfer_amount" - AttributeRewardsBalanceAmount = "rewards_balance_amount" - AttributeSlashAmount = "slash_amount" - AttributeNewDelegatedAmount = "new_delegated_amount" - AttributeValueCategory = ModuleName + AttributeInputAmount = "input_amount" + AttributeOutputAmount = "output_amount" + AttributeDelegatorAddress = "address" + AttributePstakeDepositFee = "pstake_deposit_fee" + AttributePstakeUnstakeFee = "pstake_unstake_fee" + AttributePstakeRedeemFee = "pstake_redeem_fee" + AttributePstakeAutocompoundFee = "autocompound_fee" + AttributeChainID = "chain_id" + AttributeNewCValue = "new_c_value" + AttributeOldCValue = "old_c_value" + AttributeEpoch = "epoch_number" + AttributeValidatorAddress = "validator_address" + AttributeExistingDelegation = "existing_delegation" + AttributeUpdatedDelegation = "updated_delegation" + AttributeSlashedAmount = "slashed_amount" + AttributeKeyAuthority = "authority" + AttributeKeyUpdatedParams = "updated_params" + AttributeKeyAck = "acknowledgement" + AttributeKeyAckSuccess = "success" + AttributeKeyAckError = "error" + AttributeKeyValidatorNewStatus = "validator_new_status" + AttributeKeyValidatorOldStatus = "validator_old_status" + AttributeKeyValidatorNewExchangeRate = "validator_new_exchange_rate" + AttributeKeyValidatorOldExchangeRate = "validator_old_exchange_rate" + AttributeKeyValidatorDelegable = "validator_delegable" + AttributeTotalDelegatedAmount = "total_delegated_amount" + AttributeIBCSequenceID = "ibc_sequence_id" + AttributeICAMessages = "ica_messages" + AttributeClaimAmount = "claimed_amount" + AttributeClaimAddress = "claim_address" + AttributeModuleMintedAmount = "minted_amount" + AttributeModuleLSMTokenizedAmount = "lsm_tokenized_amount" + AttributeModuleStakedAmount = "staked_amount" + AttributeModuleAmountOnPersistence = "amount_on_persistence" + AttributeModuleAmountOnHostChain = "amount_on_host_chain" + AttributeModuleUnbondingAmount = "unbonding_amount" + AttributeTotalEpochDepositAmount = "deposit_amount" + AttributeTotalEpochUnbondingAmount = "unbonding_amount" + AttributeTotalEpochBurnAmount = "burn_amount" + AttributeValidatorUnbondingAmount = "validator_unbonding_amount" + AttributeLSMDepositsSharesAmount = "lsm_deposits_shares_amount" + AttributeRewardsTransferAmount = "rewards_transfer_amount" + AttributeRewardsBalanceAmount = "rewards_balance_amount" + AttributeUnbondingMaturedAmount = "unbonding_matured_amount" + AttributeValidatorUnbondingMaturedAmount = "validator_unbonding_matured_amount" + AttributeAutocompoundTransfer = "autocompound_transfer_amount" + AttributeValueCategory = ModuleName ) From bd588f37672070ec73c2032dca60732ca1805948 Mon Sep 17 00:00:00 2001 From: kruspy Date: Wed, 18 Oct 2023 18:14:24 +0200 Subject: [PATCH 10/17] ICA events --- x/liquidstakeibc/keeper/hooks.go | 68 +++++++++++++++++++++++++------- x/liquidstakeibc/keeper/ibc.go | 10 +++++ x/liquidstakeibc/keeper/icq.go | 4 +- x/liquidstakeibc/types/events.go | 8 ++++ 4 files changed, 74 insertions(+), 16 deletions(-) diff --git a/x/liquidstakeibc/keeper/hooks.go b/x/liquidstakeibc/keeper/hooks.go index 6e3852e72..670959c0f 100644 --- a/x/liquidstakeibc/keeper/hooks.go +++ b/x/liquidstakeibc/keeper/hooks.go @@ -184,14 +184,14 @@ func (k *Keeper) OnRecvIBCTransferPacket( k.SetUnbonding(ctx, unbonding) // emit event for the received transfer - ctx.EventManager().EmitEvents(sdk.Events{ + ctx.EventManager().EmitEvent( sdk.NewEvent( liquidstakeibctypes.EventTypeUnbondingMaturedReceived, sdk.NewAttribute(liquidstakeibctypes.AttributeChainID, hc.ChainId), sdk.NewAttribute(liquidstakeibctypes.AttributeEpoch, strconv.FormatInt(unbonding.EpochNumber, 10)), sdk.NewAttribute(liquidstakeibctypes.AttributeUnbondingMaturedAmount, sdk.NewCoin(hc.HostDenom, unbonding.UnbondAmount.Amount).String()), ), - }) + ) } } @@ -235,13 +235,13 @@ func (k *Keeper) OnRecvIBCTransferPacket( deposit.Amount.Amount = deposit.Amount.Amount.Add(transferAmount) k.SetDeposit(ctx, deposit) - ctx.EventManager().EmitEvents(sdk.Events{ + ctx.EventManager().EmitEvent( sdk.NewEvent( liquidstakeibctypes.EventTypeValidatorUnbondingMaturedReceived, sdk.NewAttribute(liquidstakeibctypes.AttributeChainID, hc.ChainId), sdk.NewAttribute(liquidstakeibctypes.AttributeValidatorUnbondingMaturedAmount, sdk.NewCoin(hc.HostDenom, transferAmount).String()), ), - }) + ) } // the transfer is part of the autocompounding process @@ -307,14 +307,14 @@ func (k *Keeper) OnRecvIBCTransferPacket( k.SetDeposit(ctx, deposit) // emit autocompound received event - ctx.EventManager().EmitEvents(sdk.Events{ + ctx.EventManager().EmitEvent( sdk.NewEvent( liquidstakeibctypes.EventAutocompoundRewardsReceived, sdk.NewAttribute(liquidstakeibctypes.AttributeChainID, hc.ChainId), - sdk.NewAttribute(liquidstakeibctypes.AttributeValidatorUnbondingMaturedAmount, sdk.NewCoin(hc.HostDenom, transferAmount).String()), + sdk.NewAttribute(liquidstakeibctypes.AttributeAutocompoundTransfer, sdk.NewCoin(hc.HostDenom, transferAmount).String()), sdk.NewAttribute(liquidstakeibctypes.AttributePstakeAutocompoundFee, sdk.NewCoin(hc.HostDenom, feeAmount.TruncateInt()).String()), ), - }) + ) } return nil @@ -390,6 +390,28 @@ func (k *Keeper) OnAcknowledgementIBCTransferPacket( // mark tokenized LSM token delegations as received and add the IBC sequence lsmDeposits := k.GetLSMDepositsFromIbcSequenceID(ctx, k.GetTransactionSequenceID(packet.SourceChannel, packet.Sequence)) k.UpdateLSMDepositsStateAndSequence(ctx, lsmDeposits, liquidstakeibctypes.LSMDeposit_DEPOSIT_RECEIVED, "") + + // emit the deposit transfer received event + denom := data.GetDenom() + hc, found := k.GetHostChainFromHostDenom(ctx, denom) + if !found { + return nil + } + + eventType := "" + if len(deposits) > 0 { + eventType = liquidstakeibctypes.EventStakingDepositTransferReceived + } else { + eventType = liquidstakeibctypes.EventLSMDepositTransferReceived + } + + ctx.EventManager().EmitEvent( + sdk.NewEvent( + eventType, + sdk.NewAttribute(liquidstakeibctypes.AttributeChainID, hc.ChainId), + sdk.NewAttribute(liquidstakeibctypes.AttributeIBCSequenceID, k.GetTransactionSequenceID(packet.SourceChannel, packet.Sequence)), + ), + ) } return nil @@ -413,15 +435,33 @@ func (k *Keeper) OnTimeoutIBCTransferPacket( // just take action when the transfer has been, send from the deposit module account if data.GetSender() == authtypes.NewModuleAddress(liquidstakeibctypes.DepositModuleAccount).String() { // revert the state of the deposits that timed out - k.RevertDepositsState( - ctx, - k.GetDepositsWithSequenceID(ctx, k.GetTransactionSequenceID(packet.SourceChannel, packet.Sequence)), - ) + deposits := k.GetDepositsWithSequenceID(ctx, k.GetTransactionSequenceID(packet.SourceChannel, packet.Sequence)) + k.RevertDepositsState(ctx, deposits) // revert the state of the LSM deposits that timed out - k.RevertLSMDepositsState( - ctx, - k.GetLSMDepositsFromIbcDenom(ctx, k.GetTransactionSequenceID(packet.SourceChannel, packet.Sequence)), + lsmDeposits := k.GetLSMDepositsFromIbcDenom(ctx, k.GetTransactionSequenceID(packet.SourceChannel, packet.Sequence)) + k.RevertLSMDepositsState(ctx, lsmDeposits) + + // emit the deposit transfer timeout event + denom := data.GetDenom() + hc, found := k.GetHostChainFromHostDenom(ctx, denom) + if !found { + return nil + } + + eventType := "" + if len(deposits) > 0 { + eventType = liquidstakeibctypes.EventStakingDepositTransferTimeout + } else { + eventType = liquidstakeibctypes.EventLSMDepositTransferTimeout + } + + ctx.EventManager().EmitEvent( + sdk.NewEvent( + eventType, + sdk.NewAttribute(liquidstakeibctypes.AttributeChainID, hc.ChainId), + sdk.NewAttribute(liquidstakeibctypes.AttributeIBCSequenceID, k.GetTransactionSequenceID(packet.SourceChannel, packet.Sequence)), + ), ) } diff --git a/x/liquidstakeibc/keeper/ibc.go b/x/liquidstakeibc/keeper/ibc.go index 472ad0747..9fef44cb0 100644 --- a/x/liquidstakeibc/keeper/ibc.go +++ b/x/liquidstakeibc/keeper/ibc.go @@ -106,6 +106,16 @@ func (k *Keeper) OnChanOpenAck( address, ) + ctx.EventManager().EmitEvent( + sdk.NewEvent( + types.EventICAChannelCreated, + sdk.NewAttribute(types.AttributeChainID, hc.ChainId), + sdk.NewAttribute(types.AttributeICAChannelID, channelID), + sdk.NewAttribute(types.AttributeICAPortOwner, portOwner), + sdk.NewAttribute(types.AttributeICAAddress, address), + ), + ) + return nil } diff --git a/x/liquidstakeibc/keeper/icq.go b/x/liquidstakeibc/keeper/icq.go index 0796ed02a..1e49d8bf6 100644 --- a/x/liquidstakeibc/keeper/icq.go +++ b/x/liquidstakeibc/keeper/icq.go @@ -105,7 +105,7 @@ func DelegationCallback(k Keeper, ctx sdk.Context, data []byte, query icqtypes.Q validator.DelegatedAmount = delegatedAmount.TruncateInt() k.SetHostChainValidator(ctx, hc, validator) - ctx.EventManager().EmitEvents(sdk.Events{ + ctx.EventManager().EmitEvent( sdk.NewEvent( types.EventTypeSlashing, sdk.NewAttribute(types.AttributeChainID, hc.ChainId), @@ -114,7 +114,7 @@ func DelegationCallback(k Keeper, ctx sdk.Context, data []byte, query icqtypes.Q sdk.NewAttribute(types.AttributeUpdatedDelegation, delegatedAmount.String()), sdk.NewAttribute(types.AttributeSlashedAmount, slashedAmount.String()), ), - }) + ) } return nil diff --git a/x/liquidstakeibc/types/events.go b/x/liquidstakeibc/types/events.go index e709f44e9..dac68d7c8 100644 --- a/x/liquidstakeibc/types/events.go +++ b/x/liquidstakeibc/types/events.go @@ -26,6 +26,11 @@ const ( EventTypeUnbondingMaturedReceived = "unbonding_matured" EventTypeValidatorUnbondingMaturedReceived = "validator_unbonding_matured" EventAutocompoundRewardsReceived = "autocompound_rewards_received" + EventStakingDepositTransferReceived = "staking_deposit_received" + EventStakingDepositTransferTimeout = "staking_deposit_timeout" + EventLSMDepositTransferReceived = "lsm_deposit_received" + EventLSMDepositTransferTimeout = "lsm_deposit_timeout" + EventICAChannelCreated = "ica_channel_created" AttributeInputAmount = "input_amount" AttributeOutputAmount = "output_amount" @@ -73,5 +78,8 @@ const ( AttributeUnbondingMaturedAmount = "unbonding_matured_amount" AttributeValidatorUnbondingMaturedAmount = "validator_unbonding_matured_amount" AttributeAutocompoundTransfer = "autocompound_transfer_amount" + AttributeICAPortOwner = "ica_port_owner" + AttributeICAChannelID = "ica_channel_id" + AttributeICAAddress = "ica_address" AttributeValueCategory = ModuleName ) From b02d893ab504d506b1191a19787ad8c6d3a021a2 Mon Sep 17 00:00:00 2001 From: kruspy Date: Wed, 18 Oct 2023 19:22:57 +0200 Subject: [PATCH 11/17] IBC transfer ack events --- x/liquidstakeibc/keeper/hooks.go | 93 ++++++++++++++++++-------------- 1 file changed, 53 insertions(+), 40 deletions(-) diff --git a/x/liquidstakeibc/keeper/hooks.go b/x/liquidstakeibc/keeper/hooks.go index 670959c0f..2199d2c01 100644 --- a/x/liquidstakeibc/keeper/hooks.go +++ b/x/liquidstakeibc/keeper/hooks.go @@ -385,33 +385,36 @@ func (k *Keeper) OnAcknowledgementIBCTransferPacket( "channel", packet.SourceChannel, ) + + // emit events for the deposits received + ctx.EventManager().EmitEvent( + sdk.NewEvent( + liquidstakeibctypes.EventStakingDepositTransferReceived, + sdk.NewAttribute(liquidstakeibctypes.AttributeChainID, hc.ChainId), + sdk.NewAttribute(liquidstakeibctypes.AttributeIBCSequenceID, k.GetTransactionSequenceID(packet.SourceChannel, packet.Sequence)), + ), + ) } // mark tokenized LSM token delegations as received and add the IBC sequence lsmDeposits := k.GetLSMDepositsFromIbcSequenceID(ctx, k.GetTransactionSequenceID(packet.SourceChannel, packet.Sequence)) k.UpdateLSMDepositsStateAndSequence(ctx, lsmDeposits, liquidstakeibctypes.LSMDeposit_DEPOSIT_RECEIVED, "") - // emit the deposit transfer received event - denom := data.GetDenom() - hc, found := k.GetHostChainFromHostDenom(ctx, denom) - if !found { - return nil - } + // emit events for the lsm deposits received + for _, lsmDeposit := range lsmDeposits { + hc, found := k.GetHostChain(ctx, lsmDeposit.ChainId) + if !found { + return fmt.Errorf("host chain with id %s is not registered", lsmDeposit.ChainId) + } - eventType := "" - if len(deposits) > 0 { - eventType = liquidstakeibctypes.EventStakingDepositTransferReceived - } else { - eventType = liquidstakeibctypes.EventLSMDepositTransferReceived + ctx.EventManager().EmitEvent( + sdk.NewEvent( + liquidstakeibctypes.EventLSMDepositTransferReceived, + sdk.NewAttribute(liquidstakeibctypes.AttributeChainID, hc.ChainId), + sdk.NewAttribute(liquidstakeibctypes.AttributeIBCSequenceID, k.GetTransactionSequenceID(packet.SourceChannel, packet.Sequence)), + ), + ) } - - ctx.EventManager().EmitEvent( - sdk.NewEvent( - eventType, - sdk.NewAttribute(liquidstakeibctypes.AttributeChainID, hc.ChainId), - sdk.NewAttribute(liquidstakeibctypes.AttributeIBCSequenceID, k.GetTransactionSequenceID(packet.SourceChannel, packet.Sequence)), - ), - ) } return nil @@ -438,31 +441,41 @@ func (k *Keeper) OnTimeoutIBCTransferPacket( deposits := k.GetDepositsWithSequenceID(ctx, k.GetTransactionSequenceID(packet.SourceChannel, packet.Sequence)) k.RevertDepositsState(ctx, deposits) + // emit events for the deposits that timed out + for _, deposit := range deposits { + hc, found := k.GetHostChain(ctx, deposit.ChainId) + if !found { + return fmt.Errorf("host chain with id %s is not registered", deposit.ChainId) + } + + ctx.EventManager().EmitEvent( + sdk.NewEvent( + liquidstakeibctypes.EventStakingDepositTransferTimeout, + sdk.NewAttribute(liquidstakeibctypes.AttributeChainID, hc.ChainId), + sdk.NewAttribute(liquidstakeibctypes.AttributeIBCSequenceID, k.GetTransactionSequenceID(packet.SourceChannel, packet.Sequence)), + ), + ) + } + // revert the state of the LSM deposits that timed out lsmDeposits := k.GetLSMDepositsFromIbcDenom(ctx, k.GetTransactionSequenceID(packet.SourceChannel, packet.Sequence)) k.RevertLSMDepositsState(ctx, lsmDeposits) - // emit the deposit transfer timeout event - denom := data.GetDenom() - hc, found := k.GetHostChainFromHostDenom(ctx, denom) - if !found { - return nil - } + // emit events for the lsm deposits that timed out + for _, lsmDeposit := range lsmDeposits { + hc, found := k.GetHostChain(ctx, lsmDeposit.ChainId) + if !found { + return fmt.Errorf("host chain with id %s is not registered", lsmDeposit.ChainId) + } - eventType := "" - if len(deposits) > 0 { - eventType = liquidstakeibctypes.EventStakingDepositTransferTimeout - } else { - eventType = liquidstakeibctypes.EventLSMDepositTransferTimeout + ctx.EventManager().EmitEvent( + sdk.NewEvent( + liquidstakeibctypes.EventLSMDepositTransferTimeout, + sdk.NewAttribute(liquidstakeibctypes.AttributeChainID, hc.ChainId), + sdk.NewAttribute(liquidstakeibctypes.AttributeIBCSequenceID, k.GetTransactionSequenceID(packet.SourceChannel, packet.Sequence)), + ), + ) } - - ctx.EventManager().EmitEvent( - sdk.NewEvent( - eventType, - sdk.NewAttribute(liquidstakeibctypes.AttributeChainID, hc.ChainId), - sdk.NewAttribute(liquidstakeibctypes.AttributeIBCSequenceID, k.GetTransactionSequenceID(packet.SourceChannel, packet.Sequence)), - ), - ) } k.Logger(ctx).Info( @@ -514,7 +527,7 @@ func (k *Keeper) DepositWorkflow(ctx sdk.Context, epoch int64) { timeoutHeight := clienttypes.NewHeight( clientState.GetLatestHeight().GetRevisionNumber(), - clientState.GetLatestHeight().GetRevisionHeight()+liquidstakeibctypes.IBCTimeoutHeightIncrement, + clientState.GetLatestHeight().GetRevisionHeight()+1, ) msg := ibctransfertypes.NewMsgTransfer( @@ -814,7 +827,7 @@ func (k *Keeper) LSMWorkflow(ctx sdk.Context) { timeoutHeight := clienttypes.NewHeight( clientState.GetLatestHeight().GetRevisionNumber(), - clientState.GetLatestHeight().GetRevisionHeight()+liquidstakeibctypes.IBCTimeoutHeightIncrement, + clientState.GetLatestHeight().GetRevisionHeight()+1, ) // craft the IBC message From bfe372d81478ddb2d635545d57162910b5bedced Mon Sep 17 00:00:00 2001 From: kruspy Date: Thu, 19 Oct 2023 15:00:00 +0200 Subject: [PATCH 12/17] ica events --- x/liquidstakeibc/keeper/hooks.go | 4 +- x/liquidstakeibc/keeper/ibc.go | 153 ++++++++++++++++++++++++ x/liquidstakeibc/keeper/ica_handlers.go | 62 ++++++++++ x/liquidstakeibc/types/events.go | 74 +++++++----- 4 files changed, 261 insertions(+), 32 deletions(-) diff --git a/x/liquidstakeibc/keeper/hooks.go b/x/liquidstakeibc/keeper/hooks.go index a1ecec9e9..eed175d53 100644 --- a/x/liquidstakeibc/keeper/hooks.go +++ b/x/liquidstakeibc/keeper/hooks.go @@ -527,7 +527,7 @@ func (k *Keeper) DepositWorkflow(ctx sdk.Context, epoch int64) { timeoutHeight := clienttypes.NewHeight( clientState.GetLatestHeight().GetRevisionNumber(), - clientState.GetLatestHeight().GetRevisionHeight()+1, + clientState.GetLatestHeight().GetRevisionHeight()+liquidstakeibctypes.IBCTimeoutHeightIncrement, ) msg := ibctransfertypes.NewMsgTransfer( @@ -827,7 +827,7 @@ func (k *Keeper) LSMWorkflow(ctx sdk.Context) { timeoutHeight := clienttypes.NewHeight( clientState.GetLatestHeight().GetRevisionNumber(), - clientState.GetLatestHeight().GetRevisionHeight()+1, + clientState.GetLatestHeight().GetRevisionHeight()+liquidstakeibctypes.IBCTimeoutHeightIncrement, ) // craft the IBC message diff --git a/x/liquidstakeibc/keeper/ibc.go b/x/liquidstakeibc/keeper/ibc.go index 9fef44cb0..fb77cbe8a 100644 --- a/x/liquidstakeibc/keeper/ibc.go +++ b/x/liquidstakeibc/keeper/ibc.go @@ -226,11 +226,83 @@ func (k *Keeper) handleUnsuccessfulAck( case sdk.MsgTypeURL(&stakingtypes.MsgDelegate{}): // revert all the deposits for that sequence back to the previous state k.RevertDepositsState(ctx, k.GetDepositsWithSequenceID(ctx, k.GetTransactionSequenceID(channel, sequence))) + + // parse the delegate message to emit the delegate error event + parsedMsg, ok := msg.(*stakingtypes.MsgDelegate) + if !ok { + k.Logger(ctx).Error( + "Could not parse MsgDelegate while handling unsuccessful ack.", + "sequence-id", + k.GetTransactionSequenceID(channel, sequence), + ) + continue + } + + // get the host chain using the delegator address + hc, found := k.GetHostChainFromDelegatorAddress(ctx, parsedMsg.DelegatorAddress) + if !found { + k.Logger(ctx).Error( + "Could not find host chain for ICA delegator address.", + "delegator-address", + parsedMsg.DelegatorAddress, + "sequence-id", + k.GetTransactionSequenceID(channel, sequence), + ) + continue + } + + // emit an event for the delegation confirmation + ctx.EventManager().EmitEvent( + sdk.NewEvent( + types.EventUnsuccessfulDelegation, + sdk.NewAttribute(types.AttributeChainID, hc.ChainId), + sdk.NewAttribute(types.AttributeDelegatorAddress, parsedMsg.DelegatorAddress), + sdk.NewAttribute(types.AttributeValidatorAddress, parsedMsg.ValidatorAddress), + sdk.NewAttribute(types.AttributeDelegatedAmount, sdk.NewCoin(hc.HostDenom, parsedMsg.Amount.Amount).String()), + sdk.NewAttribute(types.AttributeIBCSequenceID, k.GetTransactionSequenceID(channel, sequence)), + ), + ) case sdk.MsgTypeURL(&stakingtypes.MsgUndelegate{}): // mark all the unbondings for the previous epoch as failed k.FailAllUnbondingsForSequenceID(ctx, k.GetTransactionSequenceID(channel, sequence)) // delete all validator unbondings so they can be picked up again k.DeleteValidatorUnbondingsForSequenceID(ctx, k.GetTransactionSequenceID(channel, sequence)) + + // parse the undelegate message to emit the undelegate error event + parsedMsg, ok := msg.(*stakingtypes.MsgUndelegate) + if !ok { + k.Logger(ctx).Error( + "Could not parse MsgUndelegate while handling unsuccessful ack.", + "sequence-id", + k.GetTransactionSequenceID(channel, sequence), + ) + continue + } + + // get the host chain using the delegator address + hc, found := k.GetHostChainFromDelegatorAddress(ctx, parsedMsg.DelegatorAddress) + if !found { + k.Logger(ctx).Error( + "Could not find host chain for ICA delegator address.", + "delegator-address", + parsedMsg.DelegatorAddress, + "sequence-id", + k.GetTransactionSequenceID(channel, sequence), + ) + continue + } + + // emit an event for the undelegation confirmation + ctx.EventManager().EmitEvent( + sdk.NewEvent( + types.EventUnsuccessfulUndelegation, + sdk.NewAttribute(types.AttributeChainID, hc.ChainId), + sdk.NewAttribute(types.AttributeDelegatorAddress, parsedMsg.DelegatorAddress), + sdk.NewAttribute(types.AttributeValidatorAddress, parsedMsg.ValidatorAddress), + sdk.NewAttribute(types.AttributeUndelegatedAmount, sdk.NewCoin(hc.HostDenom, parsedMsg.Amount.Amount).String()), + sdk.NewAttribute(types.AttributeIBCSequenceID, k.GetTransactionSequenceID(channel, sequence)), + ), + ) case sdk.MsgTypeURL(&ibctransfertypes.MsgTransfer{}): unbondings := k.FilterUnbondings( ctx, @@ -254,6 +326,52 @@ func (k *Keeper) handleUnsuccessfulAck( validatorUnbonding.IbcSequenceId = "" k.SetValidatorUnbonding(ctx, validatorUnbonding) } + + // parse the transfer message to emit the transfer error event + parsedMsg, ok := msg.(*ibctransfertypes.MsgTransfer) + if !ok { + k.Logger(ctx).Error( + "Could not parse MsgTransfer while handling unsuccessful ack.", + "sequence-id", + k.GetTransactionSequenceID(channel, sequence), + ) + continue + } + + // get the host chain using the delegator address + hc, found := k.GetHostChainFromDelegatorAddress(ctx, parsedMsg.Sender) + if !found { + k.Logger(ctx).Error( + "Could not find host chain for ICA delegator address.", + "delegator-address", + parsedMsg.Sender, + "sequence-id", + k.GetTransactionSequenceID(channel, sequence), + ) + continue + } + + // if the response is for an unbonding transfer, emit the unbonding transfer error event + if len(unbondings) > 0 { + ctx.EventManager().EmitEvent( + sdk.NewEvent( + types.EventUnsuccessfulUndelegationTransfer, + sdk.NewAttribute(types.AttributeChainID, hc.ChainId), + sdk.NewAttribute(types.AttributeIBCSequenceID, k.GetTransactionSequenceID(channel, sequence)), + ), + ) + } + + // if the response is from a validator unbonding transfer, emit the validator unbonding transfer error event + if len(validatorUnbondings) > 0 { + ctx.EventManager().EmitEvent( + sdk.NewEvent( + types.EventUnsuccessfulValidatorUndelegationTransfer, + sdk.NewAttribute(types.AttributeChainID, hc.ChainId), + sdk.NewAttribute(types.AttributeIBCSequenceID, k.GetTransactionSequenceID(channel, sequence)), + ), + ) + } case sdk.MsgTypeURL(&stakingtypes.MsgRedeemTokensForShares{}): deposits := k.FilterLSMDeposits( ctx, @@ -264,6 +382,41 @@ func (k *Keeper) handleUnsuccessfulAck( // revert the state of the deposit, so it will be retried k.RevertLSMDepositsState(ctx, deposits) + + // parse the transfer message to emit the redeem error event + parsedMsg, ok := msg.(*stakingtypes.MsgRedeemTokensForShares) + if !ok { + k.Logger(ctx).Error( + "Could not parse MsgRedeemTokensForShares while handling unsuccessful ack.", + "sequence-id", + k.GetTransactionSequenceID(channel, sequence), + ) + continue + } + + // get the host chain using the delegator address + hc, found := k.GetHostChainFromDelegatorAddress(ctx, parsedMsg.DelegatorAddress) + if !found { + k.Logger(ctx).Error( + "Could not find host chain for ICA delegator address.", + "delegator-address", + parsedMsg.DelegatorAddress, + "sequence-id", + k.GetTransactionSequenceID(channel, sequence), + ) + continue + } + + // emit an event for the redeem error + ctx.EventManager().EmitEvent( + sdk.NewEvent( + types.EventUnsuccessfulLSMRedeem, + sdk.NewAttribute(types.AttributeChainID, hc.ChainId), + sdk.NewAttribute(types.AttributeDelegatorAddress, parsedMsg.DelegatorAddress), + sdk.NewAttribute(types.AttributeRedeemedAmount, sdk.NewCoin(hc.HostDenom, parsedMsg.Amount.Amount).String()), + sdk.NewAttribute(types.AttributeIBCSequenceID, k.GetTransactionSequenceID(channel, sequence)), + ), + ) } } diff --git a/x/liquidstakeibc/keeper/ica_handlers.go b/x/liquidstakeibc/keeper/ica_handlers.go index 449465dd8..884e5fa30 100644 --- a/x/liquidstakeibc/keeper/ica_handlers.go +++ b/x/liquidstakeibc/keeper/ica_handlers.go @@ -57,6 +57,18 @@ func (k *Keeper) HandleDelegateResponse(ctx sdk.Context, msg sdk.Msg, channel st k.SetHostChain(ctx, hc) + // emit an event for the delegation confirmation + ctx.EventManager().EmitEvent( + sdk.NewEvent( + types.EventSuccessfulDelegation, + sdk.NewAttribute(types.AttributeChainID, hc.ChainId), + sdk.NewAttribute(types.AttributeDelegatorAddress, parsedMsg.DelegatorAddress), + sdk.NewAttribute(types.AttributeValidatorAddress, parsedMsg.ValidatorAddress), + sdk.NewAttribute(types.AttributeDelegatedAmount, sdk.NewCoin(hc.HostDenom, parsedMsg.Amount.Amount).String()), + sdk.NewAttribute(types.AttributeIBCSequenceID, k.GetTransactionSequenceID(channel, sequence)), + ), + ) + k.Logger(ctx).Info( "Received delegation acknowledgement", "delegator", @@ -133,6 +145,15 @@ func (k *Keeper) HandleUndelegateResponse( unbonding.State = types.Unbonding_UNBONDING_MATURING k.SetUnbonding(ctx, unbonding) + // emit an event for the burned coins + ctx.EventManager().EmitEvent( + sdk.NewEvent( + types.EventBurn, + sdk.NewAttribute(types.AttributeChainID, hc.ChainId), + sdk.NewAttribute(types.AttributeTotalEpochBurnAmount, sdk.NewCoin(hc.MintDenom(), unbonding.BurnAmount.Amount).String()), + ), + ) + k.Logger(ctx).Info( "Received unbonding acknowledgement", "delegator", @@ -169,6 +190,18 @@ func (k *Keeper) HandleUndelegateResponse( ) } + // emit an event for the undelegation confirmation + ctx.EventManager().EmitEvent( + sdk.NewEvent( + types.EventSuccessfulUndelegation, + sdk.NewAttribute(types.AttributeChainID, hc.ChainId), + sdk.NewAttribute(types.AttributeDelegatorAddress, parsedMsg.DelegatorAddress), + sdk.NewAttribute(types.AttributeValidatorAddress, parsedMsg.ValidatorAddress), + sdk.NewAttribute(types.AttributeUndelegatedAmount, sdk.NewCoin(hc.HostDenom, parsedMsg.Amount.Amount).String()), + sdk.NewAttribute(types.AttributeIBCSequenceID, k.GetTransactionSequenceID(channel, sequence)), + ), + ) + return nil } @@ -214,6 +247,15 @@ func (k *Keeper) HandleMsgTransfer( unbonding.IbcSequenceId = k.GetTransactionSequenceID(hc.ChannelId, resp.Sequence) k.SetUnbonding(ctx, unbonding) } + + // emit the transfer ack event + ctx.EventManager().EmitEvent( + sdk.NewEvent( + types.EventSuccessfulUndelegationTransfer, + sdk.NewAttribute(types.AttributeChainID, hc.ChainId), + sdk.NewAttribute(types.AttributeIBCSequenceID, k.GetTransactionSequenceID(hc.ChannelId, resp.Sequence)), + ), + ) } if parsedMsg.Sender == hc.DelegationAccount.Address && @@ -229,6 +271,15 @@ func (k *Keeper) HandleMsgTransfer( for _, validatorUnbonding := range validatorUnbondings { k.DeleteValidatorUnbonding(ctx, validatorUnbonding) } + + // emit the transfer ack event + ctx.EventManager().EmitEvent( + sdk.NewEvent( + types.EventSuccessfulValidatorUndelegationTransfer, + sdk.NewAttribute(types.AttributeChainID, hc.ChainId), + sdk.NewAttribute(types.AttributeIBCSequenceID, k.GetTransactionSequenceID(hc.ChannelId, resp.Sequence)), + ), + ) } return nil @@ -292,6 +343,17 @@ func (k *Keeper) HandleMsgRedeemTokensForShares( k.SetHostChain(ctx, hc) + // emit an event for the redeem confirmation + ctx.EventManager().EmitEvent( + sdk.NewEvent( + types.EventSuccessfulLSMRedeem, + sdk.NewAttribute(types.AttributeChainID, hc.ChainId), + sdk.NewAttribute(types.AttributeDelegatorAddress, parsedMsg.DelegatorAddress), + sdk.NewAttribute(types.AttributeRedeemedAmount, sdk.NewCoin(hc.HostDenom, parsedMsg.Amount.Amount).String()), + sdk.NewAttribute(types.AttributeIBCSequenceID, k.GetTransactionSequenceID(channel, sequence)), + ), + ) + k.Logger(ctx).Info( "Received lsm token redeem acknowledgement", "delegator", diff --git a/x/liquidstakeibc/types/events.go b/x/liquidstakeibc/types/events.go index dac68d7c8..0ce8dda79 100644 --- a/x/liquidstakeibc/types/events.go +++ b/x/liquidstakeibc/types/events.go @@ -1,36 +1,47 @@ package types const ( - EventTypeLiquidStake = "liquid_stake" - EventTypeLiquidStakeLSM = "liquid_stake_lsm" - EventTypeLiquidUnstake = "liquid_unstake" - EventTypeRedeem = "redeem" - EventTypePacket = "ics27_packet" - EventTypeTimeout = "timeout" - EventTypeSlashing = "validator_slash" - EventTypeUpdateParams = "update_params" - EventTypeChainDisabled = "chain_disabled" - EventTypeValidatorStatusUpdate = "validator_status_update" - EventTypeValidatorExchangeRateUpdate = "validator_exchange_rate_update" - EventTypeValidatorDelegableStateUpdate = "validator_delegable_state_update" - EventTypeDoDelegation = "send_delegation" - EventTypeClaimedUnbondings = "claimed_unbondings" - EventTypeRedeemTokensForShares = "redeem_lsm_tokens_shares" - EventTypeCValueUpdate = "c_value_update" - EventTypeDelegationWorkflow = "delegation_workflow" - EventTypeUndelegationWorkflow = "undelegation_workflow" - EventTypeValidatorUndelegationWorkflow = "validator_undelegation_workflow" - EventTypeRewardsWorkflow = "rewards_workflow" - EventTypeLSMWorkflow = "lsm_workflow" - EventTypeRewardsTransfer = "rewards_transfer" - EventTypeUnbondingMaturedReceived = "unbonding_matured" - EventTypeValidatorUnbondingMaturedReceived = "validator_unbonding_matured" - EventAutocompoundRewardsReceived = "autocompound_rewards_received" - EventStakingDepositTransferReceived = "staking_deposit_received" - EventStakingDepositTransferTimeout = "staking_deposit_timeout" - EventLSMDepositTransferReceived = "lsm_deposit_received" - EventLSMDepositTransferTimeout = "lsm_deposit_timeout" - EventICAChannelCreated = "ica_channel_created" + EventTypeLiquidStake = "liquid_stake" + EventTypeLiquidStakeLSM = "liquid_stake_lsm" + EventTypeLiquidUnstake = "liquid_unstake" + EventTypeRedeem = "redeem" + EventTypePacket = "ics27_packet" + EventTypeTimeout = "timeout" + EventTypeSlashing = "validator_slash" + EventTypeUpdateParams = "update_params" + EventTypeChainDisabled = "chain_disabled" + EventTypeValidatorStatusUpdate = "validator_status_update" + EventTypeValidatorExchangeRateUpdate = "validator_exchange_rate_update" + EventTypeValidatorDelegableStateUpdate = "validator_delegable_state_update" + EventTypeDoDelegation = "send_delegation" + EventTypeClaimedUnbondings = "claimed_unbondings" + EventTypeRedeemTokensForShares = "redeem_lsm_tokens_shares" + EventTypeCValueUpdate = "c_value_update" + EventTypeDelegationWorkflow = "delegation_workflow" + EventTypeUndelegationWorkflow = "undelegation_workflow" + EventTypeValidatorUndelegationWorkflow = "validator_undelegation_workflow" + EventTypeRewardsWorkflow = "rewards_workflow" + EventTypeLSMWorkflow = "lsm_workflow" + EventTypeRewardsTransfer = "rewards_transfer" + EventTypeUnbondingMaturedReceived = "unbonding_matured" + EventTypeValidatorUnbondingMaturedReceived = "validator_unbonding_matured" + EventAutocompoundRewardsReceived = "autocompound_rewards_received" + EventStakingDepositTransferReceived = "staking_deposit_received" + EventStakingDepositTransferTimeout = "staking_deposit_timeout" + EventLSMDepositTransferReceived = "lsm_deposit_received" + EventLSMDepositTransferTimeout = "lsm_deposit_timeout" + EventICAChannelCreated = "ica_channel_created" + EventSuccessfulDelegation = "successful_delegation" + EventSuccessfulUndelegation = "successful_undelegation" + EventBurn = "stk-burn" + EventSuccessfulUndelegationTransfer = "successful_undelegation_transfer" + EventSuccessfulValidatorUndelegationTransfer = "successful_validator_undelegation_transfer" + EventSuccessfulLSMRedeem = "successful_lsm_redeem" + EventUnsuccessfulDelegation = "unsuccessful_delegation" + EventUnsuccessfulUndelegation = "unsuccessful_undelegation" + EventUnsuccessfulUndelegationTransfer = "unsuccessful_undelegation_transfer" + EventUnsuccessfulValidatorUndelegationTransfer = "unsuccessful_validator_undelegation_transfer" + EventUnsuccessfulLSMRedeem = "unsuccessful_lsm_redeem" AttributeInputAmount = "input_amount" AttributeOutputAmount = "output_amount" @@ -81,5 +92,8 @@ const ( AttributeICAPortOwner = "ica_port_owner" AttributeICAChannelID = "ica_channel_id" AttributeICAAddress = "ica_address" + AttributeDelegatedAmount = "delegated_amount" + AttributeUndelegatedAmount = "undelegated_amount" + AttributeRedeemedAmount = "redeemed_amount" AttributeValueCategory = ModuleName ) From 6839e385fc8b43789f9c5e09bc18c2f1d9d09d54 Mon Sep 17 00:00:00 2001 From: kruspy Date: Thu, 19 Oct 2023 16:03:04 +0200 Subject: [PATCH 13/17] burn event --- x/liquidstakeibc/keeper/msg_server.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/x/liquidstakeibc/keeper/msg_server.go b/x/liquidstakeibc/keeper/msg_server.go index 139aa1990..75f44256c 100644 --- a/x/liquidstakeibc/keeper/msg_server.go +++ b/x/liquidstakeibc/keeper/msg_server.go @@ -832,6 +832,11 @@ func (k msgServer) Redeem( sdktypes.NewAttribute(types.AttributePstakeRedeemFee, sdktypes.NewCoin(hc.MintDenom(), fee.Amount).String()), ), + sdktypes.NewEvent( + types.EventBurn, + sdktypes.NewAttribute(types.AttributeChainID, hc.ChainId), + sdktypes.NewAttribute(types.AttributeTotalEpochBurnAmount, sdktypes.NewCoin(hc.MintDenom(), stkAmount.Amount).String()), + ), sdktypes.NewEvent( sdktypes.EventTypeMessage, sdktypes.NewAttribute(sdktypes.AttributeKeyModule, types.AttributeValueCategory), From 2c637dce20261c8087677369b3d402c95e10a459 Mon Sep 17 00:00:00 2001 From: kruspy Date: Thu, 19 Oct 2023 16:09:57 +0200 Subject: [PATCH 14/17] linting --- x/liquidstakeibc/types/events.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x/liquidstakeibc/types/events.go b/x/liquidstakeibc/types/events.go index 0ce8dda79..9540ec144 100644 --- a/x/liquidstakeibc/types/events.go +++ b/x/liquidstakeibc/types/events.go @@ -15,7 +15,7 @@ const ( EventTypeValidatorDelegableStateUpdate = "validator_delegable_state_update" EventTypeDoDelegation = "send_delegation" EventTypeClaimedUnbondings = "claimed_unbondings" - EventTypeRedeemTokensForShares = "redeem_lsm_tokens_shares" + EventTypeRedeemTokensForShares = "redeem_lsm_tokens_shares" //nolint:gosec EventTypeCValueUpdate = "c_value_update" EventTypeDelegationWorkflow = "delegation_workflow" EventTypeUndelegationWorkflow = "undelegation_workflow" @@ -74,7 +74,7 @@ const ( AttributeClaimAmount = "claimed_amount" AttributeClaimAddress = "claim_address" AttributeModuleMintedAmount = "minted_amount" - AttributeModuleLSMTokenizedAmount = "lsm_tokenized_amount" + AttributeModuleLSMTokenizedAmount = "lsm_tokenized_amount" //nolint:gosec AttributeModuleStakedAmount = "staked_amount" AttributeModuleAmountOnPersistence = "amount_on_persistence" AttributeModuleAmountOnHostChain = "amount_on_host_chain" From c33b7923ad0f1e7f033677ac873ddb67e5a25627 Mon Sep 17 00:00:00 2001 From: kruspy Date: Thu, 19 Oct 2023 16:28:15 +0200 Subject: [PATCH 15/17] changelog --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ed510d35a..e5ea8f43c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,6 +36,12 @@ Ref: https://keepachangelog.com/en/1.0.0/ ## [Unreleased] +### Features + +- [#667](https://github.com/persistenceOne/pstake-native/pull/667) Monitoring Events. + +### Bug Fixes + - [#665](https://github.com/persistenceOne/pstake-native/pull/665) LSM deposit timeout fix. ## [v2.4.0] - 2023-09-13 From fa29c6986bc3f85f22fee68d9825235d5fe77f87 Mon Sep 17 00:00:00 2001 From: kruspy Date: Fri, 20 Oct 2023 13:44:17 +0200 Subject: [PATCH 16/17] changelog --- CHANGELOG.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ababd6ee7..3b90310c0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,9 +40,12 @@ Ref: https://keepachangelog.com/en/1.0.0/ - [#667](https://github.com/persistenceOne/pstake-native/pull/667) Monitoring Events. -### Bug Fixes +### Improvements - [#668](https://github.com/persistenceOne/pstake-native/pull/668) Update ICA timeout. + +### Bug Fixes + - [#665](https://github.com/persistenceOne/pstake-native/pull/665) LSM deposit timeout fix. ## [v2.4.0] - 2023-09-13 From c06039d8b1d8a4d13ed74bcc2c618b7e49d24c4f Mon Sep 17 00:00:00 2001 From: kruspy Date: Fri, 20 Oct 2023 14:17:17 +0200 Subject: [PATCH 17/17] add individual event delegations --- x/liquidstakeibc/keeper/abci.go | 14 ++++++++++---- x/liquidstakeibc/types/events.go | 1 + 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/x/liquidstakeibc/keeper/abci.go b/x/liquidstakeibc/keeper/abci.go index 59986e885..acdbfcb95 100644 --- a/x/liquidstakeibc/keeper/abci.go +++ b/x/liquidstakeibc/keeper/abci.go @@ -85,13 +85,21 @@ func (k *Keeper) DoDelegate(ctx sdk.Context, hc *types.HostChain) { } // if everything went well, update the deposit states and set the sequence id - lastEpoch := int64(0) // highest epoch among deposits, used for event emission for _, deposit := range deposits { deposit.IbcSequenceId = sequenceID deposit.State = types.Deposit_DEPOSIT_DELEGATING k.SetDeposit(ctx, deposit) - lastEpoch = deposit.Epoch + // emit the delegation event for every deposit + ctx.EventManager().EmitEvent( + sdk.NewEvent( + types.EventTypeDoDelegationDeposit, + sdk.NewAttribute(types.AttributeChainID, hc.ChainId), + sdk.NewAttribute(types.AttributeEpoch, strconv.FormatInt(deposit.Epoch, 10)), + sdk.NewAttribute(types.AttributeDelegatedAmount, sdk.NewCoin(hc.HostDenom, deposit.Amount.Amount).String()), + sdk.NewAttribute(types.AttributeIBCSequenceID, sequenceID), + ), + ) } // emit the delegation event @@ -100,10 +108,8 @@ func (k *Keeper) DoDelegate(ctx sdk.Context, hc *types.HostChain) { sdk.NewEvent( types.EventTypeDoDelegation, sdk.NewAttribute(types.AttributeChainID, hc.ChainId), - sdk.NewAttribute(types.AttributeEpoch, strconv.FormatInt(lastEpoch, 10)), sdk.NewAttribute(types.AttributeTotalDelegatedAmount, sdk.NewCoin(hc.HostDenom, totalDepositDelegation).String()), sdk.NewAttribute(types.AttributeICAMessages, base64.StdEncoding.EncodeToString(encMsgs)), - sdk.NewAttribute(types.AttributeIBCSequenceID, sequenceID), ), ) } diff --git a/x/liquidstakeibc/types/events.go b/x/liquidstakeibc/types/events.go index 9540ec144..f3e19c944 100644 --- a/x/liquidstakeibc/types/events.go +++ b/x/liquidstakeibc/types/events.go @@ -14,6 +14,7 @@ const ( EventTypeValidatorExchangeRateUpdate = "validator_exchange_rate_update" EventTypeValidatorDelegableStateUpdate = "validator_delegable_state_update" EventTypeDoDelegation = "send_delegation" + EventTypeDoDelegationDeposit = "send_individual_delegation" EventTypeClaimedUnbondings = "claimed_unbondings" EventTypeRedeemTokensForShares = "redeem_lsm_tokens_shares" //nolint:gosec EventTypeCValueUpdate = "c_value_update"