From fb84aeb05f08590f5b878905b4b80c8121071153 Mon Sep 17 00:00:00 2001 From: Vishnu Kumavat Date: Mon, 29 Aug 2022 16:16:32 +0530 Subject: [PATCH 1/3] Swap conversion fix for disabled pool, causing division by zero panic --- x/liquidity/keeper/swap.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/x/liquidity/keeper/swap.go b/x/liquidity/keeper/swap.go index 3b4768eb4..439c02c8e 100644 --- a/x/liquidity/keeper/swap.go +++ b/x/liquidity/keeper/swap.go @@ -605,6 +605,10 @@ func (k Keeper) ConvertAccumulatedSwapFeesWithSwapDistrToken(ctx sdk.Context, ap undirectedGraph := types.BuildUndirectedGraph(edges) for _, pool := range availablePools { + if pool.Disabled { + continue + } + pair, found := k.GetPair(ctx, pool.AppId, pool.PairId) if !found { continue @@ -629,6 +633,9 @@ func (k Keeper) ConvertAccumulatedSwapFeesWithSwapDistrToken(ctx sdk.Context, ap } rx, ry := k.getPoolBalances(ctx, swappablePool, swappablePair) + if !rx.Amount.IsPositive() || !ry.Amount.IsPositive() { + continue + } baseCoinPoolPrice := rx.Amount.ToDec().Quo(ry.Amount.ToDec()) orderDirection := types.OrderDirectionBuy From 76f058a17c5eb993e7fd29c4a2484f1aa9e1a8e1 Mon Sep 17 00:00:00 2001 From: Chandragupta Singh Date: Mon, 29 Aug 2022 23:50:40 +0530 Subject: [PATCH 2/3] bug fix, paginations added --- proto/comdex/auction/v1beta1/query.proto | 2 +- x/asset/keeper/pairs_vault.go | 24 ++--- x/auction/client/cli/cli.go | 11 +++ x/auction/client/cli/query.go | 7 +- x/auction/keeper/query_server.go | 116 +++++++++++++++++++---- x/auction/types/query.pb.go | 100 +++++++++---------- x/auction/types/query.pb.gw.go | 4 +- x/locker/keeper/msg_server.go | 6 +- x/rewards/keeper/iter.go | 8 +- x/rewards/keeper/msg_server.go | 8 ++ x/rewards/keeper/rewards.go | 2 +- x/rewards/types/errors.go | 1 + x/vault/keeper/msg_server.go | 4 +- 13 files changed, 201 insertions(+), 92 deletions(-) diff --git a/proto/comdex/auction/v1beta1/query.proto b/proto/comdex/auction/v1beta1/query.proto index 62f3f044e..122cc9b5b 100644 --- a/proto/comdex/auction/v1beta1/query.proto +++ b/proto/comdex/auction/v1beta1/query.proto @@ -268,7 +268,7 @@ message QueryDutchLendBiddingsResponse { message QueryFilterDutchAuctionsRequest { uint64 app_id = 1; - string denom = 2; + repeated string denom = 2; bool history = 3; cosmos.base.query.v1beta1.PageRequest pagination = 4 [(gogoproto.moretags) = "yaml:\"pagination\""]; diff --git a/x/asset/keeper/pairs_vault.go b/x/asset/keeper/pairs_vault.go index 771f23c01..a997925e8 100644 --- a/x/asset/keeper/pairs_vault.go +++ b/x/asset/keeper/pairs_vault.go @@ -5,6 +5,7 @@ import ( rewardstypes "github.com/comdex-official/comdex/x/rewards/types" sdk "github.com/cosmos/cosmos-sdk/types" protobuftypes "github.com/gogo/protobuf/types" + "regexp" "github.com/comdex-official/comdex/x/asset/types" ) @@ -90,7 +91,7 @@ func (k Keeper) GetPairsVaults(ctx sdk.Context) (apps []types.ExtendedPairVault, return apps, true } -func (k Keeper) WasmExtendedPairByAppQuery(ctx sdk.Context, appID uint64) (extId []uint64, found bool) { +func (k Keeper) WasmExtendedPairByAppQuery(ctx sdk.Context, appID uint64) (extID []uint64, found bool) { var ( store = k.Store(ctx) iter = sdk.KVStorePrefixIterator(store, types.PairsVaultKeyPrefix) @@ -106,15 +107,15 @@ func (k Keeper) WasmExtendedPairByAppQuery(ctx sdk.Context, appID uint64) (extId for ; iter.Valid(); iter.Next() { var extPair types.ExtendedPairVault k.cdc.MustUnmarshal(iter.Value(), &extPair) - if extPair.AppId == appID { - extId = append(extId, extPair.Id) + if extPair.AppId == appID && !extPair.IsStableMintVault { + extID = append(extID, extPair.Id) } } - if extId == nil { + if extID == nil { return nil, false } - return extId, true + return extID, true } func (k Keeper) WasmAddExtendedPairsVaultRecords(ctx sdk.Context, pairVaultBinding *bindings.MsgAddExtendedPairsVault) error { @@ -130,6 +131,12 @@ func (k Keeper) WasmAddExtendedPairsVaultRecords(ctx sdk.Context, pairVaultBindi return types.ErrorPairDoesNotExist } + var IsLetter = regexp.MustCompile(`^[A-Z-]+$`).MatchString + + if !IsLetter(pairVaultBinding.PairName) { + return types.ErrorNameDidNotMeetCriterion + } + var id = k.GetPairsVaultID(ctx) extendedPairVault, _ := k.GetPairsVaults(ctx) @@ -229,13 +236,12 @@ func (k Keeper) WasmUpdatePairsVault(ctx sdk.Context, updatePairVault *bindings. } _, found1 := k.rewards.GetAppIDByApp(ctx, updatePairVault.AppID) if found1 { - if ExtPairVaultData.StabilityFee != updatePairVault.StabilityFee { + if ExtPairVaultData.StabilityFee != updatePairVault.StabilityFee && !ExtPairVaultData.IsStableMintVault { if updatePairVault.StabilityFee.IsZero() { // run script to distrubyte reward k.VaultIterateRewards(ctx, ExtPairVaultData.StabilityFee, ExtPairVaultData.BlockHeight, ExtPairVaultData.BlockTime.Unix(), updatePairVault.AppID, ExtPairVaultData.Id, false) ExtPairVaultData.BlockTime = ctx.BlockTime() ExtPairVaultData.BlockHeight = 0 - } else if ExtPairVaultData.StabilityFee.IsZero() { // do nothing ExtPairVaultData.BlockHeight = ctx.BlockHeight() @@ -245,7 +251,6 @@ func (k Keeper) WasmUpdatePairsVault(ctx sdk.Context, updatePairVault *bindings. k.VaultIterateRewards(ctx, ExtPairVaultData.StabilityFee, ExtPairVaultData.BlockHeight, ExtPairVaultData.BlockTime.Unix(), updatePairVault.AppID, ExtPairVaultData.Id, true) ExtPairVaultData.BlockHeight = ctx.BlockHeight() ExtPairVaultData.BlockTime = ctx.BlockTime() - } } } @@ -287,7 +292,6 @@ func (k Keeper) WasmCheckWhitelistedAssetQuery(ctx sdk.Context, denom string) (f } func (k Keeper) VaultIterateRewards(ctx sdk.Context, collectorLsr sdk.Dec, collectorBh, collectorBt int64, appID, pairVaultID uint64, changeTypes bool) { - extPairVault, found := k.vault.GetAppExtendedPairVaultMappingData(ctx, appID, pairVaultID) if found { for _, valID := range extPairVault.VaultIds { @@ -349,8 +353,6 @@ func (k Keeper) VaultIterateRewards(ctx sdk.Context, collectorLsr sdk.Dec, colle } k.vault.SetVault(ctx, vaultData) } - } } - } diff --git a/x/auction/client/cli/cli.go b/x/auction/client/cli/cli.go index b8ea00dbd..ab0dfcad7 100644 --- a/x/auction/client/cli/cli.go +++ b/x/auction/client/cli/cli.go @@ -2,6 +2,7 @@ package cli import ( "github.com/cosmos/cosmos-sdk/client" + "strings" "github.com/spf13/cobra" ) @@ -54,3 +55,13 @@ func GetTxCmd() *cobra.Command { return cmd } + +func ParseStringFromString(s string, seperator string) ([]string, error) { + var parsedStrings []string + for _, s := range strings.Split(s, seperator) { + s = strings.TrimSpace(s) + + parsedStrings = append(parsedStrings, s) + } + return parsedStrings, nil +} \ No newline at end of file diff --git a/x/auction/client/cli/query.go b/x/auction/client/cli/query.go index f0dad2526..537c75735 100644 --- a/x/auction/client/cli/query.go +++ b/x/auction/client/cli/query.go @@ -671,7 +671,10 @@ func queryFilterDutchAuctions() *cobra.Command { if err != nil { return err } - denom := args[1] + denoms, err := ParseStringFromString(args[1], ",") + if err != nil { + return err + } history, err := strconv.ParseBool(args[2]) if err != nil { return err @@ -685,7 +688,7 @@ func queryFilterDutchAuctions() *cobra.Command { context.Background(), &types.QueryFilterDutchAuctionsRequest{ AppId: appID, - Denom: denom, + Denom: denoms, History: history, Pagination: pagination, }, diff --git a/x/auction/keeper/query_server.go b/x/auction/keeper/query_server.go index 015af85e8..0cb8c6ced 100644 --- a/x/auction/keeper/query_server.go +++ b/x/auction/keeper/query_server.go @@ -105,18 +105,42 @@ func (q QueryServer) QuerySurplusBiddings(c context.Context, req *types.QuerySur } var ( - ctx = sdk.UnwrapSDKContext(c) - item []types.SurplusBiddings + ctx = sdk.UnwrapSDKContext(c) + items []types.SurplusBiddings + key []byte ) if req.History { - item = q.GetHistorySurplusUserBiddings(ctx, req.Bidder, req.AppId) + key = types.HistoryUserAuctionTypeKey(req.Bidder, req.AppId, types.SurplusString) + // item = q.GetHistorySurplusUserBiddings(ctx, req.Bidder, req.AppId) } else { - item = q.GetSurplusUserBiddings(ctx, req.Bidder, req.AppId) + key = types.UserAuctionTypeKey(req.Bidder, req.AppId, types.SurplusString) + // item = q.GetSurplusUserBiddings(ctx, req.Bidder, req.AppId) + } + pagination, err := query.FilteredPaginate( + prefix.NewStore(q.Store(ctx), key), + req.Pagination, + func(_, value []byte, accumulate bool) (bool, error) { + var item types.SurplusBiddings + if err := q.cdc.Unmarshal(value, &item); err != nil { + return false, err + } + + if accumulate { + items = append(items, item) + } + + return true, nil + }, + ) + + if err != nil { + return nil, status.Error(codes.Internal, err.Error()) } return &types.QuerySurplusBiddingsResponse{ - Bidder: req.Bidder, - Biddings: item, + Bidder: req.Bidder, + Biddings: items, + Pagination: pagination, }, nil } func (q QueryServer) QueryDebtAuction(c context.Context, req *types.QueryDebtAuctionRequest) (res *types.QueryDebtAuctionResponse, err error) { @@ -190,18 +214,42 @@ func (q QueryServer) QueryDebtBiddings(c context.Context, req *types.QueryDebtBi } var ( - ctx = sdk.UnwrapSDKContext(c) - item []types.DebtBiddings + ctx = sdk.UnwrapSDKContext(c) + items []types.DebtBiddings + key []byte ) if req.History { - item = q.GetHistoryDebtUserBiddings(ctx, req.Bidder, req.AppId) + key = types.HistoryUserAuctionTypeKey(req.Bidder, req.AppId, types.DebtString) + // item = q.GetHistoryDebtUserBiddings(ctx, req.Bidder, req.AppId) } else { - item = q.GetDebtUserBiddings(ctx, req.Bidder, req.AppId) + key = types.UserAuctionTypeKey(req.Bidder, req.AppId, types.DebtString) + // item = q.GetDebtUserBiddings(ctx, req.Bidder, req.AppId) + } + pagination, err := query.FilteredPaginate( + prefix.NewStore(q.Store(ctx), key), + req.Pagination, + func(_, value []byte, accumulate bool) (bool, error) { + var item types.DebtBiddings + if err := q.cdc.Unmarshal(value, &item); err != nil { + return false, err + } + + if accumulate { + items = append(items, item) + } + + return true, nil + }, + ) + + if err != nil { + return nil, status.Error(codes.Internal, err.Error()) } return &types.QueryDebtBiddingsResponse{ - Bidder: req.Bidder, - Biddings: item, + Bidder: req.Bidder, + Biddings: items, + Pagination: pagination, }, nil } @@ -273,18 +321,43 @@ func (q QueryServer) QueryDutchBiddings(c context.Context, req *types.QueryDutch } var ( - ctx = sdk.UnwrapSDKContext(c) - item []types.DutchBiddings + ctx = sdk.UnwrapSDKContext(c) + key []byte + items []types.DutchBiddings ) if req.History { - item = q.GetHistoryDutchUserBiddings(ctx, req.Bidder, req.AppId) + key = types.HistoryUserAuctionTypeKey(req.Bidder, req.AppId, types.DutchString) + // item = q.GetHistoryDutchUserBiddings(ctx, req.Bidder, req.AppId) } else { - item = q.GetDutchUserBiddings(ctx, req.Bidder, req.AppId) + key = types.UserAuctionTypeKey(req.Bidder, req.AppId, types.DutchString) + // item = q.GetDutchUserBiddings(ctx, req.Bidder, req.AppId) + } + + pagination, err := query.FilteredPaginate( + prefix.NewStore(q.Store(ctx), key), + req.Pagination, + func(_, value []byte, accumulate bool) (bool, error) { + var item types.DutchBiddings + if err := q.cdc.Unmarshal(value, &item); err != nil { + return false, err + } + + if accumulate { + items = append(items, item) + } + + return true, nil + }, + ) + + if err != nil { + return nil, status.Error(codes.Internal, err.Error()) } return &types.QueryDutchBiddingsResponse{ - Bidder: req.Bidder, - Biddings: item, + Bidder: req.Bidder, + Biddings: items, + Pagination: pagination, }, nil } @@ -475,8 +548,11 @@ func (q QueryServer) QueryFilterDutchAuctions(c context.Context, req *types.Quer return false, err } var check = false - if item.OutflowTokenCurrentAmount.Denom == req.Denom || item.InflowTokenCurrentAmount.Denom == req.Denom { - check = true + for _, data := range req.Denom { + if item.OutflowTokenCurrentAmount.Denom == data || item.InflowTokenCurrentAmount.Denom == data { + check = true + break + } } if accumulate && check { diff --git a/x/auction/types/query.pb.go b/x/auction/types/query.pb.go index fe69d71d0..d4ec1e845 100644 --- a/x/auction/types/query.pb.go +++ b/x/auction/types/query.pb.go @@ -1269,7 +1269,7 @@ var xxx_messageInfo_QueryDutchLendBiddingsResponse proto.InternalMessageInfo type QueryFilterDutchAuctionsRequest struct { AppId uint64 `protobuf:"varint,1,opt,name=app_id,json=appId,proto3" json:"app_id,omitempty"` - Denom string `protobuf:"bytes,2,opt,name=denom,proto3" json:"denom,omitempty"` + Denom []string `protobuf:"bytes,2,rep,name=denom,proto3" json:"denom,omitempty"` History bool `protobuf:"varint,3,opt,name=history,proto3" json:"history,omitempty"` Pagination *query.PageRequest `protobuf:"bytes,4,opt,name=pagination,proto3" json:"pagination,omitempty" yaml:"pagination"` } @@ -1447,44 +1447,44 @@ var fileDescriptor_5ff4a64a3f291f95 = []byte{ 0xb5, 0xa5, 0xf4, 0xd8, 0x0d, 0xd2, 0x56, 0x0e, 0xba, 0x65, 0xde, 0x16, 0x7d, 0x8d, 0x38, 0x33, 0xf7, 0xf2, 0x1d, 0x92, 0xc0, 0x43, 0xbc, 0xf2, 0xb7, 0x47, 0xb7, 0x42, 0x7a, 0xac, 0xe0, 0x5b, 0x24, 0x81, 0xc7, 0xe4, 0xff, 0xb5, 0x4d, 0xba, 0xc5, 0xbe, 0x4e, 0x27, 0xb5, 0x86, 0xa5, 0xb6, - 0xb3, 0x1c, 0x40, 0x86, 0xf0, 0x80, 0xa2, 0xb6, 0xf4, 0x26, 0xd5, 0x74, 0x6d, 0xc5, 0x79, 0xf8, - 0xef, 0x34, 0xbd, 0x8f, 0xf0, 0x18, 0x9f, 0xc9, 0x8a, 0x5f, 0x7d, 0xe3, 0x3f, 0x6e, 0xc6, 0x03, - 0x94, 0x1f, 0x99, 0x47, 0xf0, 0x4d, 0xf5, 0x6f, 0xe4, 0xc8, 0x38, 0x8f, 0x0a, 0xff, 0xc7, 0x89, - 0xc2, 0xbe, 0x4c, 0x39, 0x0e, 0x5a, 0xb1, 0xf6, 0xce, 0x2f, 0x7f, 0x7d, 0x98, 0x9b, 0x22, 0x17, - 0x25, 0xce, 0x8f, 0x29, 0xa6, 0x93, 0xc7, 0x5e, 0x5f, 0x75, 0xda, 0xe7, 0x9a, 0x74, 0x35, 0xfc, - 0xbd, 0xf2, 0xbc, 0xa4, 0x0f, 0xd0, 0x2d, 0xd7, 0xc8, 0x4d, 0x84, 0x87, 0xa2, 0xee, 0xe3, 0x49, - 0x16, 0xc8, 0xac, 0x87, 0x0b, 0xfb, 0xb3, 0x25, 0x01, 0xd1, 0x32, 0x25, 0x7a, 0x98, 0x1c, 0x4a, - 0x47, 0xd4, 0xf4, 0x30, 0x75, 0x79, 0xfc, 0x1c, 0xe0, 0xc1, 0x56, 0x7f, 0x3a, 0x1e, 0x01, 0x87, - 0x4d, 0xc7, 0x23, 0x68, 0x66, 0xe2, 0x73, 0x94, 0xc7, 0x09, 0x72, 0x2c, 0x81, 0x07, 0xb3, 0x1d, - 0xe9, 0xaa, 0x63, 0x6d, 0xd7, 0xa2, 0x08, 0xdd, 0x45, 0x78, 0x43, 0xf0, 0x7a, 0x91, 0x48, 0xb1, - 0xb8, 0xc2, 0x57, 0xd4, 0x85, 0xbd, 0xe9, 0x13, 0x80, 0xc4, 0x6b, 0x94, 0xc4, 0x05, 0x72, 0x8e, - 0x47, 0x42, 0x51, 0xab, 0xd6, 0xa2, 0x5a, 0xee, 0x5b, 0x84, 0x37, 0x86, 0x2e, 0x4e, 0x49, 0x6a, - 0xa4, 0xae, 0x48, 0xa5, 0x0c, 0x19, 0x40, 0xee, 0x19, 0x4a, 0xee, 0x29, 0x72, 0x20, 0x05, 0xb9, - 0xc8, 0x36, 0xbb, 0xe1, 0xc5, 0xee, 0xf6, 0x58, 0x32, 0xf6, 0x60, 0x83, 0x95, 0x32, 0x64, 0x00, - 0xf6, 0x53, 0x14, 0x7b, 0x99, 0x1c, 0x89, 0xc3, 0x9e, 0xaa, 0xb5, 0xee, 0xb9, 0x24, 0x3c, 0xe6, - 0x9b, 0x44, 0x22, 0x7c, 0x87, 0x98, 0x44, 0x22, 0xe2, 0x6e, 0x4f, 0x94, 0x29, 0x89, 0x8b, 0xe4, - 0x3c, 0x97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31, 0xcc, 0xf9, 0x84, 0x7e, 0xe9, 0x92, 0x56, 0xd3, 0xe4, 0x06, + 0xc3, 0xd0, 0x45, 0x61, 0xcd, 0x18, 0xaa, 0x59, 0x1d, 0xa4, 0xbe, 0xb4, 0xef, 0xdf, 0x00, 0x00, + 0x00, 0xff, 0xff, 0xa8, 0x47, 0x84, 0xd1, 0x9d, 0x26, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -3649,11 +3649,13 @@ func (m *QueryFilterDutchAuctionsRequest) MarshalToSizedBuffer(dAtA []byte) (int dAtA[i] = 0x18 } if len(m.Denom) > 0 { - i -= len(m.Denom) - copy(dAtA[i:], m.Denom) - i = encodeVarintQuery(dAtA, i, uint64(len(m.Denom))) - i-- - dAtA[i] = 0x12 + for iNdEx := len(m.Denom) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.Denom[iNdEx]) + copy(dAtA[i:], m.Denom[iNdEx]) + i = encodeVarintQuery(dAtA, i, uint64(len(m.Denom[iNdEx]))) + i-- + dAtA[i] = 0x12 + } } if m.AppId != 0 { i = encodeVarintQuery(dAtA, i, uint64(m.AppId)) @@ -4322,9 +4324,11 @@ func (m *QueryFilterDutchAuctionsRequest) Size() (n int) { if m.AppId != 0 { n += 1 + sovQuery(uint64(m.AppId)) } - l = len(m.Denom) - if l > 0 { - n += 1 + l + sovQuery(uint64(l)) + if len(m.Denom) > 0 { + for _, s := range m.Denom { + l = len(s) + n += 1 + l + sovQuery(uint64(l)) + } } if m.History { n += 2 @@ -8324,7 +8328,7 @@ func (m *QueryFilterDutchAuctionsRequest) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Denom = string(dAtA[iNdEx:postIndex]) + m.Denom = append(m.Denom, string(dAtA[iNdEx:postIndex])) iNdEx = postIndex case 3: if wireType != 0 { diff --git a/x/auction/types/query.pb.gw.go b/x/auction/types/query.pb.gw.go index c93cabede..63091c1a1 100644 --- a/x/auction/types/query.pb.gw.go +++ b/x/auction/types/query.pb.gw.go @@ -1528,7 +1528,7 @@ func request_Query_QueryFilterDutchAuctions_0(ctx context.Context, marshaler run return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "denom") } - protoReq.Denom, err = runtime.String(val) + protoReq.Denom, err = runtime.StringSlice(val, ",") if err != nil { return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "denom", err) @@ -1584,7 +1584,7 @@ func local_request_Query_QueryFilterDutchAuctions_0(ctx context.Context, marshal return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "denom") } - protoReq.Denom, err = runtime.String(val) + protoReq.Denom, err = runtime.StringSlice(val, ",") if err != nil { return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "denom", err) diff --git a/x/locker/keeper/msg_server.go b/x/locker/keeper/msg_server.go index c1b792c42..b26bdae06 100644 --- a/x/locker/keeper/msg_server.go +++ b/x/locker/keeper/msg_server.go @@ -333,8 +333,10 @@ func (k msgServer) MsgCloseLocker(c context.Context, msg *types.MsgCloseLockerRe lockerData, _ = k.GetLocker(ctx, msg.LockerId) - if err := k.SendCoinFromModuleToAccount(ctx, types.ModuleName, depositor, sdk.NewCoin(asset.Denom, lockerData.NetBalance)); err != nil { - return nil, err + if lockerData.NetBalance.GT(sdk.ZeroInt()) { + if err := k.SendCoinFromModuleToAccount(ctx, types.ModuleName, depositor, sdk.NewCoin(asset.Denom, lockerData.NetBalance)); err != nil { + return nil, err + } } userLockerAssetMappingData, _ := k.GetUserLockerAssetMapping(ctx, msg.Depositor, msg.AppId, msg.AssetId) diff --git a/x/rewards/keeper/iter.go b/x/rewards/keeper/iter.go index 3697e1355..51345aee4 100644 --- a/x/rewards/keeper/iter.go +++ b/x/rewards/keeper/iter.go @@ -110,9 +110,11 @@ func (k Keeper) DistributeExtRewardVault(ctx sdk.Context) error { finalDailyRewards := sdk.NewInt(dailyRewards.TruncateInt64()) user, _ := sdk.AccAddressFromBech32(userVault.Owner) - err := k.SendCoinFromModuleToAccount(ctx, types.ModuleName, user, sdk.NewCoin(totalRewards.Denom, finalDailyRewards)) - if err != nil { - continue + if finalDailyRewards.GT(sdk.ZeroInt()) { + err := k.SendCoinFromModuleToAccount(ctx, types.ModuleName, user, sdk.NewCoin(totalRewards.Denom, finalDailyRewards)) + if err != nil { + continue + } } epoch.Count = epoch.Count + types.UInt64One epoch.StartingTime = timeNow + types.SecondsPerDay diff --git a/x/rewards/keeper/msg_server.go b/x/rewards/keeper/msg_server.go index 858cc2d30..49d208176 100644 --- a/x/rewards/keeper/msg_server.go +++ b/x/rewards/keeper/msg_server.go @@ -4,6 +4,7 @@ import ( "context" esmtypes "github.com/comdex-official/comdex/x/esm/types" + assettypes "github.com/comdex-official/comdex/x/asset/types" "github.com/comdex-official/comdex/x/rewards/types" sdk "github.com/cosmos/cosmos-sdk/types" ) @@ -78,6 +79,13 @@ func (m msgServer) ExternalRewardsVault(goCtx context.Context, msg *types.Activa if err != nil { return nil, err } + pairVault, found := m.GetPairsVault(ctx, msg.Extended_Pair_Id) + if !found { + return nil, assettypes.ErrorExtendedPairDoesNotExistForTheApp + } + if pairVault.IsStableMintVault { + return nil, types.ErrStablemintVaultFound + } if err := m.Keeper.ActExternalRewardsVaults(ctx, msg.AppMappingId, msg.Extended_Pair_Id, msg.DurationDays, msg.MinLockupTimeSeconds, msg.TotalRewards, Depositor); err != nil { return nil, err } diff --git a/x/rewards/keeper/rewards.go b/x/rewards/keeper/rewards.go index 2cc7347ad..a8663c45a 100644 --- a/x/rewards/keeper/rewards.go +++ b/x/rewards/keeper/rewards.go @@ -656,7 +656,7 @@ func (k Keeper) CalculateVaultInterest(ctx sdk.Context, appID, extendedPairID, v interest := sdk.ZeroDec() var err error extPairVaultBTime := ExtPairVaultData.BlockTime.Unix() - if ExtPairVaultData.StabilityFee.IsZero() { + if ExtPairVaultData.StabilityFee.IsZero() || ExtPairVaultData.IsStableMintVault{ return nil } else { if blockHeight == 0 { diff --git a/x/rewards/types/errors.go b/x/rewards/types/errors.go index f92b06809..6d921e0a3 100644 --- a/x/rewards/types/errors.go +++ b/x/rewards/types/errors.go @@ -33,4 +33,5 @@ var ( SendCoinsFromModuleToAccountInRewardsIsZero = sdkerrors.Register(ModuleName, 1112, "Coin value in module to account transfer in rewards is zero") SendCoinsFromAccountToModuleInRewardsIsZero = sdkerrors.Register(ModuleName, 1113, "Coin value in account to module transfer in rewards is zero") ErrInternalRewardsNotFound = sdkerrors.Register(ModuleName, 1114, "Internal rewards not found") + ErrStablemintVaultFound = sdkerrors.Register(ModuleName, 1115, "Can't give reward to stablemint vault") ) diff --git a/x/vault/keeper/msg_server.go b/x/vault/keeper/msg_server.go index 6192ad867..e1d072404 100644 --- a/x/vault/keeper/msg_server.go +++ b/x/vault/keeper/msg_server.go @@ -910,8 +910,8 @@ func (k msgServer) MsgCreateStableMint(c context.Context, msg *types.MsgCreateSt tokenMintedStatistics, _ := k.CheckAppExtendedPairVaultMapping(ctx, appMapping.Id, extendedPairVault.Id) - appData, _ := k.GetAppMappingData(ctx, appMapping.Id) - if len(appData) >= 1 { + extPairData, _ := k.GetAppExtendedPairVaultMappingData(ctx, appMapping.Id, msg.ExtendedPairVaultId) + if len(extPairData.VaultIds) >= 1 { return nil, types.ErrorStableMintVaultAlreadyCreated } From d3a4406cf77ef5deb98a8d45a69c9227d6b61bb1 Mon Sep 17 00:00:00 2001 From: Vishnu Kumavat Date: Tue, 30 Aug 2022 17:51:58 +0530 Subject: [PATCH 3/3] test case fixed in liquidity module --- x/liquidity/keeper/genesis_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/liquidity/keeper/genesis_test.go b/x/liquidity/keeper/genesis_test.go index c2aced209..ea69263be 100644 --- a/x/liquidity/keeper/genesis_test.go +++ b/x/liquidity/keeper/genesis_test.go @@ -117,7 +117,7 @@ func (s *KeeperTestSuite) TestIndexesAfterImport() { appID1 := s.CreateNewApp("appone") asset1 := s.CreateNewAsset("ASSETONE", "denom1", 1000000) asset2 := s.CreateNewAsset("ASSETTWO", "denom2", 2000000) - asset3 := s.CreateNewAsset("ASSETTWO", "denom3", 3000000) + asset3 := s.CreateNewAsset("ASSETTHREE", "denom3", 3000000) pair1 := s.CreateNewLiquidityPair(appID1, s.addr(0), asset1.Denom, asset2.Denom) pair2 := s.CreateNewLiquidityPair(appID1, s.addr(1), asset2.Denom, asset3.Denom)