2022-09-29 17:01:06 +00:00
|
|
|
package keeper
|
|
|
|
|
|
|
|
import (
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
|
2024-05-01 03:17:24 +00:00
|
|
|
"github.com/0glabs/0g-chain/x/earn/types"
|
|
|
|
kavadisttypes "github.com/0glabs/0g-chain/x/kavadist/types"
|
2022-09-29 17:01:06 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// HandleCommunityPoolDepositProposal is a handler for executing a passed community pool deposit proposal
|
|
|
|
func HandleCommunityPoolDepositProposal(ctx sdk.Context, k Keeper, p *types.CommunityPoolDepositProposal) error {
|
2023-01-26 17:01:28 +00:00
|
|
|
fundAcc := k.accountKeeper.GetModuleAccount(ctx, kavadisttypes.FundModuleAccount)
|
|
|
|
if err := k.distKeeper.DistributeFromFeePool(ctx, sdk.NewCoins(p.Amount), fundAcc.GetAddress()); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
err := k.DepositFromModuleAccount(ctx, kavadisttypes.FundModuleAccount, p.Amount, types.STRATEGY_TYPE_SAVINGS)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
2022-09-29 17:01:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// HandleCommunityPoolWithdrawProposal is a handler for executing a passed community pool withdraw proposal.
|
|
|
|
func HandleCommunityPoolWithdrawProposal(ctx sdk.Context, k Keeper, p *types.CommunityPoolWithdrawProposal) error {
|
2023-01-26 17:01:28 +00:00
|
|
|
// Withdraw to fund module account
|
|
|
|
withdrawAmount, err := k.WithdrawFromModuleAccount(ctx, kavadisttypes.FundModuleAccount, p.Amount, types.STRATEGY_TYPE_SAVINGS)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Move funds to the community pool manually
|
|
|
|
err = k.bankKeeper.SendCoinsFromModuleToModule(
|
|
|
|
ctx,
|
|
|
|
kavadisttypes.FundModuleAccount,
|
|
|
|
k.distKeeper.GetDistributionAccount(ctx).GetName(),
|
|
|
|
sdk.NewCoins(withdrawAmount),
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
feePool := k.distKeeper.GetFeePool(ctx)
|
|
|
|
newCommunityPool := feePool.CommunityPool.Add(sdk.NewDecCoinFromCoin(withdrawAmount))
|
|
|
|
feePool.CommunityPool = newCommunityPool
|
|
|
|
k.distKeeper.SetFeePool(ctx, feePool)
|
|
|
|
return nil
|
2022-09-29 17:01:06 +00:00
|
|
|
}
|