From 353c386e079b0ce7f15f0ce7e12e678301792744 Mon Sep 17 00:00:00 2001 From: Chandragupta Singh Date: Mon, 14 Nov 2022 02:48:05 +0530 Subject: [PATCH 1/6] events added in vault, auction, liquidation --- scripts/comdex_local_setup/states.py | 6 ++-- x/auction/abci.go | 43 ++++++++++++++++++++++++++++ x/auction/keeper/dutch.go | 20 +++++++++++-- x/auction/types/events.go | 18 ++++++++++++ x/liquidation/abci.go | 13 +++++++++ x/liquidation/types/events.go | 7 +++++ x/vault/keeper/msg_server.go | 31 ++++++++++++++++++++ x/vault/types/events.go | 16 +++++++++++ 8 files changed, 148 insertions(+), 6 deletions(-) create mode 100644 x/auction/types/events.go create mode 100644 x/liquidation/types/events.go create mode 100644 x/vault/types/events.go diff --git a/scripts/comdex_local_setup/states.py b/scripts/comdex_local_setup/states.py index 4bc52758f..91de33eab 100644 --- a/scripts/comdex_local_setup/states.py +++ b/scripts/comdex_local_setup/states.py @@ -674,9 +674,9 @@ "msg_add_e_s_m_trigger_params": { "app_id": 1, "target_value": {"amount": "200", "denom": "uharbor"}, - "cool_off_period": 7200, - "asset_id": [4,13], - "rates": [1000000,1000000], + "cool_off_period": 180, + "asset_id": [4,3,13], + "rates": [1000000,1000000,1000000], } } ], diff --git a/x/auction/abci.go b/x/auction/abci.go index d3c07c5a0..da350ec8e 100644 --- a/x/auction/abci.go +++ b/x/auction/abci.go @@ -1,6 +1,7 @@ package auction import ( + "fmt" "github.com/comdex-official/comdex/x/auction/expected" "github.com/cosmos/cosmos-sdk/telemetry" sdk "github.com/cosmos/cosmos-sdk/types" @@ -25,6 +26,21 @@ func BeginBlocker(ctx sdk.Context, k keeper.Keeper, assetKeeper expected.AssetKe _ = utils.ApplyFuncIfNoError(ctx, func(ctx sdk.Context) error { err1 := k.SurplusActivator(ctx, data, killSwitchParams, status) if err1 != nil { + ctx.EventManager().EmitEvent( + sdk.NewEvent( + types.EventTypeSurplusActivator, + sdk.NewAttribute(types.DataAppID, fmt.Sprintf("%d", data.AppId)), + sdk.NewAttribute(types.DataAssetID, fmt.Sprintf("%d", data.AssetId)), + sdk.NewAttribute(types.DataAssetOutOraclePrice, fmt.Sprintf("%t", data.AssetOutOraclePrice)), + sdk.NewAttribute(types.DataAssetOutPrice, fmt.Sprintf("%d", data.AssetOutPrice)), + sdk.NewAttribute(types.DatIsAuctionActive, fmt.Sprintf("%t", data.IsAuctionActive)), + sdk.NewAttribute(types.DataIsDebtAuction, fmt.Sprintf("%t", data.IsDebtAuction)), + sdk.NewAttribute(types.DataIsDistributor, fmt.Sprintf("%t", data.IsDistributor)), + sdk.NewAttribute(types.DataIsSurplusAuction, fmt.Sprintf("%t", data.IsSurplusAuction)), + sdk.NewAttribute(types.KillSwitchParamsBreakerEnabled, fmt.Sprintf("%t", killSwitchParams.BreakerEnable)), + sdk.NewAttribute(types.Status, fmt.Sprintf("%t", status)), + ), + ) ctx.Logger().Error("error in surplus activator") return err1 } @@ -33,6 +49,21 @@ func BeginBlocker(ctx sdk.Context, k keeper.Keeper, assetKeeper expected.AssetKe _ = utils.ApplyFuncIfNoError(ctx, func(ctx sdk.Context) error { err2 := k.DebtActivator(ctx, data, killSwitchParams, status) if err2 != nil { + ctx.EventManager().EmitEvent( + sdk.NewEvent( + types.EventTypeDebtActivator, + sdk.NewAttribute(types.DataAppID, fmt.Sprintf("%d", data.AppId)), + sdk.NewAttribute(types.DataAssetID, fmt.Sprintf("%d", data.AssetId)), + sdk.NewAttribute(types.DataAssetOutOraclePrice, fmt.Sprintf("%t", data.AssetOutOraclePrice)), + sdk.NewAttribute(types.DataAssetOutPrice, fmt.Sprintf("%d", data.AssetOutPrice)), + sdk.NewAttribute(types.DatIsAuctionActive, fmt.Sprintf("%t", data.IsAuctionActive)), + sdk.NewAttribute(types.DataIsDebtAuction, fmt.Sprintf("%t", data.IsDebtAuction)), + sdk.NewAttribute(types.DataIsDistributor, fmt.Sprintf("%t", data.IsDistributor)), + sdk.NewAttribute(types.DataIsSurplusAuction, fmt.Sprintf("%t", data.IsSurplusAuction)), + sdk.NewAttribute(types.KillSwitchParamsBreakerEnabled, fmt.Sprintf("%t", killSwitchParams.BreakerEnable)), + sdk.NewAttribute(types.Status, fmt.Sprintf("%t", status)), + ), + ) ctx.Logger().Error("error in debt activator") return err2 } @@ -47,11 +78,23 @@ func BeginBlocker(ctx sdk.Context, k keeper.Keeper, assetKeeper expected.AssetKe for _, app := range apps { err4 := k.RestartDutch(ctx, app.Id) if err4 != nil { + ctx.EventManager().EmitEvent( + sdk.NewEvent( + types.EventTypeRestartDutch, + sdk.NewAttribute(types.DataAppID, fmt.Sprintf("%d", app.Id)), + ), + ) ctx.Logger().Error("error in restart dutch activator") } err6 := k.RestartLendDutch(ctx, app.Id) if err6 != nil { + ctx.EventManager().EmitEvent( + sdk.NewEvent( + types.EventTypeRestartLendDutch, + sdk.NewAttribute(types.DataAppID, fmt.Sprintf("%d", app.Id)), + ), + ) ctx.Logger().Error("error in restart lend dutch activator") } } diff --git a/x/auction/keeper/dutch.go b/x/auction/keeper/dutch.go index 20b1cf75f..9c89e7fb9 100644 --- a/x/auction/keeper/dutch.go +++ b/x/auction/keeper/dutch.go @@ -510,7 +510,9 @@ func (k Keeper) RestartDutchAuctions(ctx sdk.Context, appID uint64) error { // if exists append in existing // close auction func call inflowLeft := dutchAuction.InflowTokenTargetAmount.Amount.Sub(dutchAuction.InflowTokenCurrentAmount.Amount) - vaultID, userExists := k.vault.GetUserAppExtendedPairMappingData(ctx, string(dutchAuction.VaultOwner), dutchAuction.AppId, lockedVault.ExtendedPairId) + penaltyCoin := sdk.NewCoin(dutchAuction.InflowTokenCurrentAmount.Denom, sdk.ZeroInt()) + penaltyAmt := dutchAuction.InflowTokenTargetAmount.Amount.Sub(lockedVault.AmountOut) + vaultID, userExists := k.vault.GetUserAppExtendedPairMappingData(ctx, dutchAuction.VaultOwner.String(), dutchAuction.AppId, lockedVault.ExtendedPairId) if userExists { vaultData, _ := k.vault.GetVault(ctx, vaultID.VaultId) if dutchAuction.OutflowTokenCurrentAmount.Amount.GT(sdk.ZeroInt()) { @@ -521,7 +523,7 @@ func (k Keeper) RestartDutchAuctions(ctx sdk.Context, appID uint64) error { } // append to existing vault vaultData.AmountIn = vaultData.AmountIn.Add(dutchAuction.OutflowTokenCurrentAmount.Amount) - vaultData.AmountOut = vaultData.AmountOut.Add(inflowLeft) + vaultData.AmountOut = vaultData.AmountOut.Add(inflowLeft).Sub(penaltyAmt) k.vault.SetVault(ctx, vaultData) } else { if dutchAuction.OutflowTokenCurrentAmount.Amount.GT(sdk.ZeroInt()) { @@ -531,13 +533,25 @@ func (k Keeper) RestartDutchAuctions(ctx sdk.Context, appID uint64) error { } } // create new vault done - err := k.vault.CreateNewVault(ctx, dutchAuction.VaultOwner.String(), lockedVault.AppId, lockedVault.ExtendedPairId, dutchAuction.OutflowTokenCurrentAmount.Amount, inflowLeft) + err := k.vault.CreateNewVault(ctx, dutchAuction.VaultOwner.String(), lockedVault.AppId, lockedVault.ExtendedPairId, dutchAuction.OutflowTokenCurrentAmount.Amount, inflowLeft.Sub(penaltyAmt)) if err != nil { return err } length := k.vault.GetLengthOfVault(ctx) k.vault.SetLengthOfVault(ctx, length+1) } + // send penalty + if penaltyCoin.Amount.GT(sdk.ZeroInt()) { + err := k.bank.SendCoinsFromModuleToModule(ctx, auctiontypes.ModuleName, collectortypes.ModuleName, sdk.NewCoins(penaltyCoin)) + if err != nil { + return err + } + } + // call increase function in collector + err := k.collector.SetNetFeeCollectedData(ctx, dutchAuction.AppId, dutchAuction.AssetInId, penaltyCoin.Amount) + if err != nil { + return err + } dutchAuction.AuctionStatus = auctiontypes.AuctionEnded diff --git a/x/auction/types/events.go b/x/auction/types/events.go new file mode 100644 index 000000000..4de7db8ed --- /dev/null +++ b/x/auction/types/events.go @@ -0,0 +1,18 @@ +package types + +const ( + EventTypeSurplusActivator = "surplus_activator" + EventTypeDebtActivator = "debt_activator" + EventTypeRestartDutch = "restart_dutch" + EventTypeRestartLendDutch = "restart_lend_dutch" + DataAppID = "data_app_id" + DataAssetID = "data_asset_id" + DataAssetOutOraclePrice = "data_asset_out_oracle_price" + DataAssetOutPrice = "data_asset_out_price" + DatIsAuctionActive = "data_is_auction_active" + DataIsDebtAuction = "data_is_debt_auction" + DataIsDistributor = "data_is_distributor" + DataIsSurplusAuction = "data_is_surplus_auction" + KillSwitchParamsBreakerEnabled = "data_is_surplus_auction" + Status = "status" +) diff --git a/x/liquidation/abci.go b/x/liquidation/abci.go index 9a972c8a9..7f9fd8a2a 100644 --- a/x/liquidation/abci.go +++ b/x/liquidation/abci.go @@ -1,6 +1,7 @@ package liquidation import ( + "fmt" "github.com/cosmos/cosmos-sdk/telemetry" sdk "github.com/cosmos/cosmos-sdk/types" abci "github.com/tendermint/tendermint/abci/types" @@ -15,9 +16,21 @@ func BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock, k keeper.Keeper) err := k.LiquidateVaults(ctx) if err != nil { ctx.Logger().Error("error in LiquidateVaults") + ctx.EventManager().EmitEvent( + sdk.NewEvent( + types.EventTypeLiquidateVaults, + sdk.NewAttribute(types.Error, fmt.Sprintf("%s", err)), + ), + ) } err = k.LiquidateBorrows(ctx) if err != nil { ctx.Logger().Error("error in LiquidateBorrows") + ctx.EventManager().EmitEvent( + sdk.NewEvent( + types.EventTypeLiquidateBorrows, + sdk.NewAttribute(types.Error, fmt.Sprintf("%s", err)), + ), + ) } } diff --git a/x/liquidation/types/events.go b/x/liquidation/types/events.go new file mode 100644 index 000000000..425d6cf28 --- /dev/null +++ b/x/liquidation/types/events.go @@ -0,0 +1,7 @@ +package types + +const ( + EventTypeLiquidateVaults = "liquidate_vaults" + EventTypeLiquidateBorrows = "liquidate_borrows" + Error = "error" +) diff --git a/x/vault/keeper/msg_server.go b/x/vault/keeper/msg_server.go index 6b4879eef..e022d2446 100644 --- a/x/vault/keeper/msg_server.go +++ b/x/vault/keeper/msg_server.go @@ -2,6 +2,7 @@ package keeper import ( "context" + "strconv" sdk "github.com/cosmos/cosmos-sdk/types" @@ -195,6 +196,21 @@ func (k msgServer) MsgCreate(c context.Context, msg *types.MsgCreateRequest) (*t ctx.GasMeter().ConsumeGas(types.CreateVaultGas, "CreateVaultGas") + ctx.EventManager().EmitEvents(sdk.Events{ + sdk.NewEvent( + types.EventTypeCreateVault, + sdk.NewAttribute(types.AttributeKeyAppID, strconv.FormatUint(newVault.Id, 10)), + sdk.NewAttribute(types.AttributeKeyAppID, strconv.FormatUint(msg.AppId, 10)), + sdk.NewAttribute(types.AttributeKeyAppID, strconv.FormatUint(msg.ExtendedPairVaultId, 10)), + sdk.NewAttribute(types.AttributeKeyCreator, msg.From), + sdk.NewAttribute(types.AttributeKeyAmountIn, newVault.AmountIn.String()), + sdk.NewAttribute(types.AttributeKeyAmountIn, newVault.AmountOut.String()), + sdk.NewAttribute(types.AttributeKeyCreatedAt, ctx.BlockTime().String()), + sdk.NewAttribute(types.AttributeKeyInterestAccumulated, newVault.InterestAccumulated.String()), + sdk.NewAttribute(types.AttributeKeyClosingFeeAccumulated, newVault.ClosingFeeAccumulated.String()), + ), + }) + return &types.MsgCreateResponse{}, nil } @@ -838,6 +854,21 @@ func (k msgServer) MsgClose(c context.Context, msg *types.MsgCloseRequest) (*typ ctx.GasMeter().ConsumeGas(types.CloseVaultGas, "CloseVaultGas") + ctx.EventManager().EmitEvents(sdk.Events{ + sdk.NewEvent( + types.EventTypeCloseVault, + sdk.NewAttribute(types.AttributeKeyAppID, strconv.FormatUint(userVault.Id, 10)), + sdk.NewAttribute(types.AttributeKeyAppID, strconv.FormatUint(msg.AppId, 10)), + sdk.NewAttribute(types.AttributeKeyAppID, strconv.FormatUint(msg.ExtendedPairVaultId, 10)), + sdk.NewAttribute(types.AttributeKeyCreator, msg.From), + sdk.NewAttribute(types.AttributeKeyAmountIn, userVault.AmountIn.String()), + sdk.NewAttribute(types.AttributeKeyAmountIn, userVault.AmountOut.String()), + sdk.NewAttribute(types.AttributeKeyCreatedAt, userVault.CreatedAt.String()), + sdk.NewAttribute(types.AttributeKeyInterestAccumulated, userVault.InterestAccumulated.String()), + sdk.NewAttribute(types.AttributeKeyClosingFeeAccumulated, userVault.ClosingFeeAccumulated.String()), + ), + }) + return &types.MsgCloseResponse{}, nil } diff --git a/x/vault/types/events.go b/x/vault/types/events.go new file mode 100644 index 000000000..9b31d0828 --- /dev/null +++ b/x/vault/types/events.go @@ -0,0 +1,16 @@ +package types + +// Event types for the Vault module. +const ( + EventTypeCreateVault = "create_vault" + EventTypeCloseVault = "close_vault" + + AttributeKeyVaultID = "vaultId" + AttributeKeyCreator = "creator" + AttributeKeyAppID = "appId" + AttributeKeyAmountIn = "amountIn" + AttributeKeyAmountOut = "amountOut" + AttributeKeyCreatedAt = "createdAt" + AttributeKeyInterestAccumulated = "interestAccumulated" + AttributeKeyClosingFeeAccumulated = "closingFeeAccumulated" +) From f72a0ee3b1faacb15645c75038271f35f000eb37 Mon Sep 17 00:00:00 2001 From: Chandragupta Singh Date: Mon, 14 Nov 2022 02:49:38 +0530 Subject: [PATCH 2/6] script changed --- scripts/comdex_local_setup/states.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/comdex_local_setup/states.py b/scripts/comdex_local_setup/states.py index 91de33eab..850bf34bf 100644 --- a/scripts/comdex_local_setup/states.py +++ b/scripts/comdex_local_setup/states.py @@ -674,7 +674,7 @@ "msg_add_e_s_m_trigger_params": { "app_id": 1, "target_value": {"amount": "200", "denom": "uharbor"}, - "cool_off_period": 180, + "cool_off_period": 7200, "asset_id": [4,3,13], "rates": [1000000,1000000,1000000], } From 7f7f692206495b16b6df2e7dd33ab0fc013f8188 Mon Sep 17 00:00:00 2001 From: Chandragupta Singh Date: Mon, 14 Nov 2022 12:10:10 +0530 Subject: [PATCH 3/6] events added in market --- x/market/keeper/oracle.go | 13 +++++++++ x/market/types/events.go | 10 +++++++ x/vault/keeper/msg_server.go | 54 +++++++++++++++++++++++++++++++----- x/vault/types/events.go | 9 ++++-- 4 files changed, 77 insertions(+), 9 deletions(-) create mode 100644 x/market/types/events.go diff --git a/x/market/keeper/oracle.go b/x/market/keeper/oracle.go index 7a2881db5..977ac0928 100644 --- a/x/market/keeper/oracle.go +++ b/x/market/keeper/oracle.go @@ -4,6 +4,7 @@ import ( assetTypes "github.com/comdex-official/comdex/x/asset/types" "github.com/comdex-official/comdex/x/market/types" sdk "github.com/cosmos/cosmos-sdk/types" + "strconv" ) func (k Keeper) SetTwa(ctx sdk.Context, twa types.TimeWeightedAverage) { @@ -126,10 +127,22 @@ func (k Keeper) UpdatePriceList(ctx sdk.Context, id, scriptID, rate, twaBatch ui func (k Keeper) CalculateTwa(ctx sdk.Context, twa types.TimeWeightedAverage, twaBatch uint64) uint64 { var sum uint64 + oldTwa := twa.Twa for i := 0; i < int(twaBatch); i++ { sum = sum + twa.PriceValue[i] } twa.Twa = sum / twaBatch + + if oldTwa != twa.Twa { + ctx.EventManager().EmitEvents(sdk.Events{ + sdk.NewEvent( + types.EventTypeTwaChange, + sdk.NewAttribute(types.AttributeKeyAssetID, strconv.FormatUint(twa.AssetID, 10)), + sdk.NewAttribute(types.AttributeKeyOldTwa, strconv.FormatUint(oldTwa, 10)), + sdk.NewAttribute(types.AttributeKeyNewTwa, strconv.FormatUint(twa.Twa, 10)), + ), + }) + } return twa.Twa } diff --git a/x/market/types/events.go b/x/market/types/events.go new file mode 100644 index 000000000..6e10e45c9 --- /dev/null +++ b/x/market/types/events.go @@ -0,0 +1,10 @@ +package types + +// Event types for the Vault module. +const ( + EventTypeTwaChange = "twa_change" + + AttributeKeyOldTwa = "old_twa" + AttributeKeyNewTwa = "new_twa" + AttributeKeyAssetID = "assetId" +) diff --git a/x/vault/keeper/msg_server.go b/x/vault/keeper/msg_server.go index e022d2446..c4192c16e 100644 --- a/x/vault/keeper/msg_server.go +++ b/x/vault/keeper/msg_server.go @@ -199,12 +199,12 @@ func (k msgServer) MsgCreate(c context.Context, msg *types.MsgCreateRequest) (*t ctx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( types.EventTypeCreateVault, - sdk.NewAttribute(types.AttributeKeyAppID, strconv.FormatUint(newVault.Id, 10)), + sdk.NewAttribute(types.AttributeKeyVaultID, strconv.FormatUint(newVault.Id, 10)), sdk.NewAttribute(types.AttributeKeyAppID, strconv.FormatUint(msg.AppId, 10)), - sdk.NewAttribute(types.AttributeKeyAppID, strconv.FormatUint(msg.ExtendedPairVaultId, 10)), + sdk.NewAttribute(types.AttributeKeyExtendedPairID, strconv.FormatUint(msg.ExtendedPairVaultId, 10)), sdk.NewAttribute(types.AttributeKeyCreator, msg.From), sdk.NewAttribute(types.AttributeKeyAmountIn, newVault.AmountIn.String()), - sdk.NewAttribute(types.AttributeKeyAmountIn, newVault.AmountOut.String()), + sdk.NewAttribute(types.AttributeKeyAmountOut, newVault.AmountOut.String()), sdk.NewAttribute(types.AttributeKeyCreatedAt, ctx.BlockTime().String()), sdk.NewAttribute(types.AttributeKeyInterestAccumulated, newVault.InterestAccumulated.String()), sdk.NewAttribute(types.AttributeKeyClosingFeeAccumulated, newVault.ClosingFeeAccumulated.String()), @@ -306,6 +306,16 @@ func (k msgServer) MsgDeposit(c context.Context, msg *types.MsgDepositRequest) ( k.UpdateCollateralLockedAmountLockerMapping(ctx, appExtendedPairVaultData.AppId, appExtendedPairVaultData.ExtendedPairId, msg.Amount, true) ctx.GasMeter().ConsumeGas(types.DepositVaultGas, "DepositVaultGas") + ctx.EventManager().EmitEvents(sdk.Events{ + sdk.NewEvent( + types.EventTypeDepositVault, + sdk.NewAttribute(types.AttributeKeyVaultID, strconv.FormatUint(msg.UserVaultId, 10)), + sdk.NewAttribute(types.AttributeKeyAppID, strconv.FormatUint(msg.AppId, 10)), + sdk.NewAttribute(types.AttributeKeyExtendedPairID, strconv.FormatUint(msg.ExtendedPairVaultId, 10)), + sdk.NewAttribute(types.AttributeKeyCreator, msg.From), + sdk.NewAttribute(types.AttributeKeyAmountIn, msg.Amount.String()), + ), + }) return &types.MsgDepositResponse{}, nil } @@ -414,6 +424,16 @@ func (k msgServer) MsgWithdraw(c context.Context, msg *types.MsgWithdrawRequest) k.UpdateCollateralLockedAmountLockerMapping(ctx, appExtendedPairVaultData.AppId, appExtendedPairVaultData.ExtendedPairId, msg.Amount, false) ctx.GasMeter().ConsumeGas(types.WithdrawVaultGas, "WithdrawVaultGas") + ctx.EventManager().EmitEvents(sdk.Events{ + sdk.NewEvent( + types.EventTypeWithdrawVault, + sdk.NewAttribute(types.AttributeKeyVaultID, strconv.FormatUint(msg.UserVaultId, 10)), + sdk.NewAttribute(types.AttributeKeyAppID, strconv.FormatUint(msg.AppId, 10)), + sdk.NewAttribute(types.AttributeKeyExtendedPairID, strconv.FormatUint(msg.ExtendedPairVaultId, 10)), + sdk.NewAttribute(types.AttributeKeyCreator, msg.From), + sdk.NewAttribute(types.AttributeKeyAmountIn, msg.Amount.String()), + ), + }) return &types.MsgWithdrawResponse{}, nil } @@ -560,6 +580,17 @@ func (k msgServer) MsgDraw(c context.Context, msg *types.MsgDrawRequest) (*types ctx.GasMeter().ConsumeGas(types.DrawVaultGas, "DrawVaultGas") + ctx.EventManager().EmitEvents(sdk.Events{ + sdk.NewEvent( + types.EventTypeDrawVault, + sdk.NewAttribute(types.AttributeKeyVaultID, strconv.FormatUint(msg.UserVaultId, 10)), + sdk.NewAttribute(types.AttributeKeyAppID, strconv.FormatUint(msg.AppId, 10)), + sdk.NewAttribute(types.AttributeKeyExtendedPairID, strconv.FormatUint(msg.ExtendedPairVaultId, 10)), + sdk.NewAttribute(types.AttributeKeyCreator, msg.From), + sdk.NewAttribute(types.AttributeKeyAmountOut, msg.Amount.String()), + ), + }) + return &types.MsgDrawResponse{}, nil } @@ -712,6 +743,17 @@ func (k msgServer) MsgRepay(c context.Context, msg *types.MsgRepayRequest) (*typ ctx.GasMeter().ConsumeGas(types.RepayVaultGas, "RepayVaultGas") + ctx.EventManager().EmitEvents(sdk.Events{ + sdk.NewEvent( + types.EventTypeRepayVault, + sdk.NewAttribute(types.AttributeKeyVaultID, strconv.FormatUint(msg.UserVaultId, 10)), + sdk.NewAttribute(types.AttributeKeyAppID, strconv.FormatUint(msg.AppId, 10)), + sdk.NewAttribute(types.AttributeKeyExtendedPairID, strconv.FormatUint(msg.ExtendedPairVaultId, 10)), + sdk.NewAttribute(types.AttributeKeyCreator, msg.From), + sdk.NewAttribute(types.AttributeKeyAmountOut, msg.Amount.String()), + ), + }) + return &types.MsgRepayResponse{}, nil } @@ -857,12 +899,10 @@ func (k msgServer) MsgClose(c context.Context, msg *types.MsgCloseRequest) (*typ ctx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( types.EventTypeCloseVault, - sdk.NewAttribute(types.AttributeKeyAppID, strconv.FormatUint(userVault.Id, 10)), + sdk.NewAttribute(types.AttributeKeyVaultID, strconv.FormatUint(userVault.Id, 10)), sdk.NewAttribute(types.AttributeKeyAppID, strconv.FormatUint(msg.AppId, 10)), - sdk.NewAttribute(types.AttributeKeyAppID, strconv.FormatUint(msg.ExtendedPairVaultId, 10)), + sdk.NewAttribute(types.AttributeKeyExtendedPairID, strconv.FormatUint(msg.ExtendedPairVaultId, 10)), sdk.NewAttribute(types.AttributeKeyCreator, msg.From), - sdk.NewAttribute(types.AttributeKeyAmountIn, userVault.AmountIn.String()), - sdk.NewAttribute(types.AttributeKeyAmountIn, userVault.AmountOut.String()), sdk.NewAttribute(types.AttributeKeyCreatedAt, userVault.CreatedAt.String()), sdk.NewAttribute(types.AttributeKeyInterestAccumulated, userVault.InterestAccumulated.String()), sdk.NewAttribute(types.AttributeKeyClosingFeeAccumulated, userVault.ClosingFeeAccumulated.String()), diff --git a/x/vault/types/events.go b/x/vault/types/events.go index 9b31d0828..49af1ccfc 100644 --- a/x/vault/types/events.go +++ b/x/vault/types/events.go @@ -2,12 +2,17 @@ package types // Event types for the Vault module. const ( - EventTypeCreateVault = "create_vault" - EventTypeCloseVault = "close_vault" + EventTypeCreateVault = "create_vault" + EventTypeDepositVault = "deposit_vault" + EventTypeWithdrawVault = "withdraw_vault" + EventTypeDrawVault = "draw_vault" + EventTypeRepayVault = "repay_vault" + EventTypeCloseVault = "close_vault" AttributeKeyVaultID = "vaultId" AttributeKeyCreator = "creator" AttributeKeyAppID = "appId" + AttributeKeyExtendedPairID = "extendedPairId" AttributeKeyAmountIn = "amountIn" AttributeKeyAmountOut = "amountOut" AttributeKeyCreatedAt = "createdAt" From e77aa6a4544648054ce14c78603aab415c1e96c5 Mon Sep 17 00:00:00 2001 From: Chandragupta Singh Date: Mon, 14 Nov 2022 12:10:30 +0530 Subject: [PATCH 4/6] events added in market --- x/market/types/events.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/market/types/events.go b/x/market/types/events.go index 6e10e45c9..62defd204 100644 --- a/x/market/types/events.go +++ b/x/market/types/events.go @@ -1,6 +1,6 @@ package types -// Event types for the Vault module. +// Event types for the market module. const ( EventTypeTwaChange = "twa_change" From 6963e521be8338fa8c7e08b5a2a5daff985c359c Mon Sep 17 00:00:00 2001 From: Chandragupta Singh Date: Mon, 14 Nov 2022 12:41:09 +0530 Subject: [PATCH 5/6] auction,liquidation events added --- x/auction/abci.go | 8 ++++---- x/auction/keeper/dutch.go | 13 +++++++++++++ x/auction/types/events.go | 14 ++++++++++---- x/liquidation/abci.go | 4 ++-- x/liquidation/types/events.go | 6 +++--- 5 files changed, 32 insertions(+), 13 deletions(-) diff --git a/x/auction/abci.go b/x/auction/abci.go index da350ec8e..8869282b6 100644 --- a/x/auction/abci.go +++ b/x/auction/abci.go @@ -28,7 +28,7 @@ func BeginBlocker(ctx sdk.Context, k keeper.Keeper, assetKeeper expected.AssetKe if err1 != nil { ctx.EventManager().EmitEvent( sdk.NewEvent( - types.EventTypeSurplusActivator, + types.EventTypeSurplusActivatorErr, sdk.NewAttribute(types.DataAppID, fmt.Sprintf("%d", data.AppId)), sdk.NewAttribute(types.DataAssetID, fmt.Sprintf("%d", data.AssetId)), sdk.NewAttribute(types.DataAssetOutOraclePrice, fmt.Sprintf("%t", data.AssetOutOraclePrice)), @@ -51,7 +51,7 @@ func BeginBlocker(ctx sdk.Context, k keeper.Keeper, assetKeeper expected.AssetKe if err2 != nil { ctx.EventManager().EmitEvent( sdk.NewEvent( - types.EventTypeDebtActivator, + types.EventTypeDebtActivatorErr, sdk.NewAttribute(types.DataAppID, fmt.Sprintf("%d", data.AppId)), sdk.NewAttribute(types.DataAssetID, fmt.Sprintf("%d", data.AssetId)), sdk.NewAttribute(types.DataAssetOutOraclePrice, fmt.Sprintf("%t", data.AssetOutOraclePrice)), @@ -80,7 +80,7 @@ func BeginBlocker(ctx sdk.Context, k keeper.Keeper, assetKeeper expected.AssetKe if err4 != nil { ctx.EventManager().EmitEvent( sdk.NewEvent( - types.EventTypeRestartDutch, + types.EventTypeRestartDutchErr, sdk.NewAttribute(types.DataAppID, fmt.Sprintf("%d", app.Id)), ), ) @@ -91,7 +91,7 @@ func BeginBlocker(ctx sdk.Context, k keeper.Keeper, assetKeeper expected.AssetKe if err6 != nil { ctx.EventManager().EmitEvent( sdk.NewEvent( - types.EventTypeRestartLendDutch, + types.EventTypeRestartLendDutchErr, sdk.NewAttribute(types.DataAppID, fmt.Sprintf("%d", app.Id)), ), ) diff --git a/x/auction/keeper/dutch.go b/x/auction/keeper/dutch.go index 9c89e7fb9..0f515a6a1 100644 --- a/x/auction/keeper/dutch.go +++ b/x/auction/keeper/dutch.go @@ -2,6 +2,7 @@ package keeper import ( "fmt" + "strconv" "time" liquidationtypes "github.com/comdex-official/comdex/x/liquidation/types" @@ -144,6 +145,18 @@ func (k Keeper) StartDutchAuction( return err } + ctx.EventManager().EmitEvent( + sdk.NewEvent( + auctiontypes.EventTypeDutchNewAuction, + sdk.NewAttribute(auctiontypes.DataAppID, strconv.FormatUint(auction.AppId, 10)), + sdk.NewAttribute(auctiontypes.AttributeKeyOwner, auction.VaultOwner.String()), + sdk.NewAttribute(auctiontypes.AttributeKeyCollateral, auction.OutflowTokenInitAmount.String()), + sdk.NewAttribute(auctiontypes.AttributeKeyDebt, auction.InflowTokenTargetAmount.String()), + sdk.NewAttribute(auctiontypes.AttributeKeyStartTime, auction.StartTime.String()), + sdk.NewAttribute(auctiontypes.AttributeKeyEndTime, auction.EndTime.String()), + ), + ) + return nil } diff --git a/x/auction/types/events.go b/x/auction/types/events.go index 4de7db8ed..d086ebb98 100644 --- a/x/auction/types/events.go +++ b/x/auction/types/events.go @@ -1,10 +1,16 @@ package types const ( - EventTypeSurplusActivator = "surplus_activator" - EventTypeDebtActivator = "debt_activator" - EventTypeRestartDutch = "restart_dutch" - EventTypeRestartLendDutch = "restart_lend_dutch" + EventTypeSurplusActivatorErr = "surplus_activator_err" + EventTypeDebtActivatorErr = "debt_activator_err" + EventTypeRestartDutchErr = "restart_dutch_err" + EventTypeRestartLendDutchErr = "restart_lend_dutch_err" + EventTypeDutchNewAuction = "dutch_new_auction" + AttributeKeyOwner = "vault_owner" + AttributeKeyCollateral = "collateral_token" + AttributeKeyDebt = "debt_token" + AttributeKeyStartTime = "start_time" + AttributeKeyEndTime = "end_time" DataAppID = "data_app_id" DataAssetID = "data_asset_id" DataAssetOutOraclePrice = "data_asset_out_oracle_price" diff --git a/x/liquidation/abci.go b/x/liquidation/abci.go index 7f9fd8a2a..6148ebc6f 100644 --- a/x/liquidation/abci.go +++ b/x/liquidation/abci.go @@ -18,7 +18,7 @@ func BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock, k keeper.Keeper) ctx.Logger().Error("error in LiquidateVaults") ctx.EventManager().EmitEvent( sdk.NewEvent( - types.EventTypeLiquidateVaults, + types.EventTypeLiquidateVaultsErr, sdk.NewAttribute(types.Error, fmt.Sprintf("%s", err)), ), ) @@ -28,7 +28,7 @@ func BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock, k keeper.Keeper) ctx.Logger().Error("error in LiquidateBorrows") ctx.EventManager().EmitEvent( sdk.NewEvent( - types.EventTypeLiquidateBorrows, + types.EventTypeLiquidateBorrowsErr, sdk.NewAttribute(types.Error, fmt.Sprintf("%s", err)), ), ) diff --git a/x/liquidation/types/events.go b/x/liquidation/types/events.go index 425d6cf28..647e8c169 100644 --- a/x/liquidation/types/events.go +++ b/x/liquidation/types/events.go @@ -1,7 +1,7 @@ package types const ( - EventTypeLiquidateVaults = "liquidate_vaults" - EventTypeLiquidateBorrows = "liquidate_borrows" - Error = "error" + EventTypeLiquidateVaultsErr = "liquidate_vaults_err" + EventTypeLiquidateBorrowsErr = "liquidate_borrows_err" + Error = "error" ) From 4b810d2272b89b7bc6fd15750b5415839e8429cb Mon Sep 17 00:00:00 2001 From: Dheeraj Dubey Date: Mon, 14 Nov 2022 13:12:52 +0530 Subject: [PATCH 6/6] refactor --- x/auction/abci.go | 1 + x/esm/keeper/esm.go | 2 +- x/liquidation/abci.go | 1 + x/market/keeper/oracle.go | 3 ++- 4 files changed, 5 insertions(+), 2 deletions(-) diff --git a/x/auction/abci.go b/x/auction/abci.go index 8869282b6..f902a58da 100644 --- a/x/auction/abci.go +++ b/x/auction/abci.go @@ -2,6 +2,7 @@ package auction import ( "fmt" + "github.com/comdex-official/comdex/x/auction/expected" "github.com/cosmos/cosmos-sdk/telemetry" sdk "github.com/cosmos/cosmos-sdk/types" diff --git a/x/esm/keeper/esm.go b/x/esm/keeper/esm.go index 2f394abd8..44859e746 100644 --- a/x/esm/keeper/esm.go +++ b/x/esm/keeper/esm.go @@ -277,7 +277,7 @@ func (k Keeper) SetUpDebtRedemptionForCollector(ctx sdk.Context, appID uint64) e value, _ := k.GetAssetToAmount(ctx, data.AppId, data.AssetId) if !value.IsCollateral && !data.NetFeesCollected.IsZero() { - // substract dollar value + // subtract dollar value // burn token // update collector data assetData, found := k.asset.GetAsset(ctx, value.AssetID) diff --git a/x/liquidation/abci.go b/x/liquidation/abci.go index 6148ebc6f..8fc34a5e4 100644 --- a/x/liquidation/abci.go +++ b/x/liquidation/abci.go @@ -2,6 +2,7 @@ package liquidation import ( "fmt" + "github.com/cosmos/cosmos-sdk/telemetry" sdk "github.com/cosmos/cosmos-sdk/types" abci "github.com/tendermint/tendermint/abci/types" diff --git a/x/market/keeper/oracle.go b/x/market/keeper/oracle.go index 977ac0928..ee21ca387 100644 --- a/x/market/keeper/oracle.go +++ b/x/market/keeper/oracle.go @@ -1,10 +1,11 @@ package keeper import ( + "strconv" + assetTypes "github.com/comdex-official/comdex/x/asset/types" "github.com/comdex-official/comdex/x/market/types" sdk "github.com/cosmos/cosmos-sdk/types" - "strconv" ) func (k Keeper) SetTwa(ctx sdk.Context, twa types.TimeWeightedAverage) {