From adbd70f71cb8b42bc468fa68c1295b8a58f45d02 Mon Sep 17 00:00:00 2001 From: drklee3 Date: Wed, 25 Oct 2023 09:17:11 -0700 Subject: [PATCH] Update `x/community` lend withdraw proposal to keep funds in `x/community` (#1755) * Update x/community lend withdraw proposal to keep funds in x/community * Update changelog --- CHANGELOG.md | 2 ++ x/community/keeper/proposal_handler.go | 16 +--------------- x/community/keeper/proposal_handler_test.go | 11 +++++++---- 3 files changed, 10 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4cf82f7c..292ef1d4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -56,6 +56,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ - (community) [#1706] Add disable inflation upgrade to begin blocker that updates x/mint and x/kavadist params - (community) [#1729] Consolidate community funds from `x/distribution` and `x/kavadist` to `x/community` - (community) [#1752] Set `x/distribution` CommunityTax to zero on inflation disable upgrade +- (community) [#1755] Keep funds in `x/community` in `CommunityPoolLendWithdrawProposal` handler ## [v0.24.0] @@ -296,6 +297,7 @@ the [changelog](https://github.com/cosmos/cosmos-sdk/blob/v0.38.4/CHANGELOG.md). - [#257](https://github.com/Kava-Labs/kava/pulls/257) Include scripts to run large-scale simulations remotely using aws-batch +[#1755]: https://github.com/Kava-Labs/kava/pull/1755 [#1752]: https://github.com/Kava-Labs/kava/pull/1752 [#1751]: https://github.com/Kava-Labs/kava/pull/1751 [#1745]: https://github.com/Kava-Labs/kava/pull/1745 diff --git a/x/community/keeper/proposal_handler.go b/x/community/keeper/proposal_handler.go index abd217dd..f6366b5a 100644 --- a/x/community/keeper/proposal_handler.go +++ b/x/community/keeper/proposal_handler.go @@ -19,22 +19,8 @@ func HandleCommunityPoolLendDepositProposal(ctx sdk.Context, k Keeper, p *types. // HandleCommunityPoolLendWithdrawProposal is a handler for executing a passed community pool lend withdraw proposal. func HandleCommunityPoolLendWithdrawProposal(ctx sdk.Context, k Keeper, p *types.CommunityPoolLendWithdrawProposal) error { - // hard allows attempting to withdraw more funds than there is a deposit for. - // this means the amount that gets withdrawn will not necessarily match the amount set in the proposal. - // to calculate how much is withdrawn, compare this module's balance before & after withdraw. - balanceBefore := k.bankKeeper.GetAllBalances(ctx, k.moduleAddress) - // withdraw funds from x/hard to this module account - err := k.hardKeeper.Withdraw(ctx, k.moduleAddress, p.Amount) - if err != nil { - return err - } - - balanceAfter := k.bankKeeper.GetAllBalances(ctx, k.moduleAddress) - totalWithdrawn := balanceAfter.Sub(balanceBefore...) - - // send all withdrawn coins back to community pool - return k.distrKeeper.FundCommunityPool(ctx, totalWithdrawn, k.moduleAddress) + return k.hardKeeper.Withdraw(ctx, k.moduleAddress, p.Amount) } // HandleCommunityCDPRepayDebtProposal is a handler for executing a passed community pool cdp repay debt proposal. diff --git a/x/community/keeper/proposal_handler_test.go b/x/community/keeper/proposal_handler_test.go index ebf01e49..b65bb382 100644 --- a/x/community/keeper/proposal_handler_test.go +++ b/x/community/keeper/proposal_handler_test.go @@ -120,10 +120,13 @@ func (suite *proposalTestSuite) FundCommunityPool(coins sdk.Coins) { } func (suite *proposalTestSuite) GetCommunityPoolBalance() sdk.Coins { - balance, change := suite.App.GetDistrKeeper().GetFeePoolCommunityCoins(suite.Ctx).TruncateDecimal() - // expect no decimal dust - suite.True(sdk.NewDecCoins().IsEqual(change), "expected no decimal dust in community pool") - return balance + ak := suite.App.GetAccountKeeper() + bk := suite.App.GetBankKeeper() + + addr := ak.GetModuleAddress(types.ModuleAccountName) + + // Return x/community module account balance, no longer using x/distribution community pool + return bk.GetAllBalances(suite.Ctx, addr) } func (suite *proposalTestSuite) CheckCommunityPoolBalance(expected sdk.Coins) {