-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(dividends): msg server and epoch hooks
- Loading branch information
Showing
26 changed files
with
534 additions
and
2,546 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package keeper | ||
|
||
import ( | ||
"fmt" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" | ||
"github.com/dymensionxyz/dymension-rdk/x/dividends/types" | ||
) | ||
|
||
func (k Keeper) Allocate(ctx sdk.Context) error { | ||
var ( | ||
totalStakingPower = k.stakingKeeper.GetLastTotalPower(ctx) | ||
totalStakingPowerDec = sdk.NewDecFromInt(totalStakingPower) | ||
) | ||
|
||
err := k.IterateGauges(ctx, func(_ uint64, gauge types.Gauge) (stop bool, err error) { | ||
var ( | ||
address = sdk.MustAccAddressFromBech32(gauge.Address) | ||
gaugeRewards = sdk.NewDecCoinsFromCoins(k.bankKeeper.GetAllBalances(ctx, address)...) | ||
) | ||
|
||
switch gauge.VestingCondition.Condition.(type) { | ||
case *types.VestingCondition_Block: | ||
Check failure on line 24 in x/dividends/keeper/allocation.go
|
||
case *types.VestingCondition_Epoch: | ||
} | ||
|
||
switch gauge.QueryCondition.Condition.(type) { | ||
case *types.QueryCondition_Stakers: | ||
k.AllocateStakers(ctx, totalStakingPowerDec, gaugeRewards) | ||
case *types.QueryCondition_Funds: | ||
Check failure on line 31 in x/dividends/keeper/allocation.go
|
||
} | ||
|
||
return false, nil | ||
}) | ||
if err != nil { | ||
return fmt.Errorf("iterate gauges: %w", err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (k Keeper) AllocateStakers(ctx sdk.Context, stakingPower sdk.Dec, gaugeRewards sdk.DecCoins) { | ||
k.stakingKeeper.IterateBondedValidatorsByPower(ctx, func(index int64, validator stakingtypes.ValidatorI) (stop bool) { | ||
var ( | ||
valPower = validator.GetConsensusPower(sdk.DefaultPowerReduction) | ||
powerFraction = sdk.NewDec(valPower).QuoTruncate(stakingPower) | ||
reward = gaugeRewards.MulDecTruncate(powerFraction) | ||
) | ||
|
||
k.distrKeeper.AllocateTokensToValidator(ctx, validator, reward) | ||
return false | ||
}) | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.