0g-chain/x/liquid/keeper/claim.go
Derrick Lee 6ef9bab67d
Add liquid staking reward redistribution via incentive (#1308)
* wip Add claim

* Add distr keeper and claiming

* Add claim test

* Update claim test with failures

* wip Add staking rewards

* -S

Fix savings to earn incentive methods

* Use a single accural time for all earn incentives

* Add additional required liquid methods

* Update genesis to only include 1 accrual time for earn

* Revert "Update genesis to only include 1 accrual time for earn"

This reverts commit cc7e35347298681c0c8a4a0b9bf9b9b296c25531.

* Revert "Use a single accural time for all earn incentives"

This reverts commit aeb49c4622d4e3d99dc6421c8830932b1b546be9.

* Update tests with incentive distribution

* Add earn to incentive rewards query

* add earn cli tx

* Update claim example to use ukava large

* Use underlying ukava to determine proportional reward amount

* Rename liquid methods to reflect derivative value

* Add tests for derivative values

* Return error to panic in BeginBlocker

Co-authored-by: karzak <kjydavis3@gmail.com>
2022-09-28 13:20:01 -07:00

52 lines
1.3 KiB
Go

package keeper
import (
"fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/kava-labs/kava/x/liquid/types"
)
func (k Keeper) CollectStakingRewards(
ctx sdk.Context,
validator sdk.ValAddress,
destinationModAccount string,
) (sdk.Coins, error) {
macc := k.accountKeeper.GetModuleAccount(ctx, types.ModuleAccountName)
// Ensure withdraw address is as expected
withdrawAddr := k.distributionKeeper.GetDelegatorWithdrawAddr(ctx, macc.GetAddress())
if !withdrawAddr.Equals(macc.GetAddress()) {
panic(fmt.Sprintf(
"unexpected withdraw address for liquid staking module account, expected %s, got %s",
macc.GetAddress(), withdrawAddr,
))
}
rewards, err := k.distributionKeeper.WithdrawDelegationRewards(ctx, macc.GetAddress(), validator)
if err != nil {
return nil, err
}
err = k.bankKeeper.SendCoinsFromModuleToModule(ctx, types.ModuleAccountName, destinationModAccount, rewards)
if err != nil {
return nil, err
}
return rewards, nil
}
func (k Keeper) CollectStakingRewardsByDenom(
ctx sdk.Context,
derivativeDenom string,
destinationModAccount string,
) (sdk.Coins, error) {
valAddr, err := types.ParseLiquidStakingTokenDenom(derivativeDenom)
if err != nil {
return nil, err
}
return k.CollectStakingRewards(ctx, valAddr, destinationModAccount)
}