-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
132d67d
commit b8d555e
Showing
26 changed files
with
1,763 additions
and
89 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
syntax = "proto3"; | ||
package cosmos.accumulator; | ||
|
||
import "google/protobuf/any.proto"; | ||
import "cosmos/base/query/v1beta1/pagination.proto"; | ||
import "google/api/annotations.proto"; | ||
import "gogoproto/gogo.proto"; | ||
import "cosmos/base/v1beta1/coin.proto"; | ||
|
||
option go_package = "github.com/cosmos/cosmos-sdk/x/accumulator/types"; | ||
|
||
message Admin { | ||
string address = 1; | ||
|
||
int64 vesting_period = 2; | ||
|
||
cosmos.base.v1beta1.Coin reward_per_period = 3 [(gogoproto.nullable) = false]; | ||
|
||
int64 vesting_periods_count = 4; | ||
|
||
int64 last_vesting_time = 5; | ||
|
||
int64 vesting_counter = 6; | ||
|
||
string denom = 7; | ||
} | ||
|
||
|
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 |
---|---|---|
@@ -1,15 +1,18 @@ | ||
syntax = "proto3"; | ||
package accumulator; | ||
package cosmos.accumulator; | ||
|
||
import "gogoproto/gogo.proto"; | ||
import "cosmos/accumulator/params.proto"; | ||
import "cosmos/accumulator/admin.proto"; | ||
|
||
// this line is used by starport scaffolding # genesis/proto/import | ||
|
||
option go_package = "github.com/cosmos/cosmos-sdk/x/accumulator/types"; | ||
|
||
// GenesisState defines the bruhaccumulator module's genesis state. | ||
// GenesisState defines the accumulator module's genesis state. | ||
message GenesisState { | ||
Params params = 1 [(gogoproto.nullable) = false]; | ||
repeated cosmos.accumulator.Admin admins = 2 [(gogoproto.nullable) = false]; | ||
|
||
// this line is used by starport scaffolding # genesis/proto/state | ||
} |
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
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,36 @@ | ||
package accumulator | ||
|
||
import ( | ||
"github.com/cosmos/cosmos-sdk/telemetry" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/x/accumulator/keeper" | ||
"github.com/cosmos/cosmos-sdk/x/accumulator/types" | ||
"time" | ||
) | ||
|
||
// update vesting state for each admin | ||
func EndBlocker(ctx sdk.Context, k keeper.Keeper) { | ||
defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyBeginBlocker) | ||
|
||
for _, admin := range k.GetAllAdmins(ctx) { | ||
if ctx.BlockTime().Unix()-admin.LastVestingTime < admin.VestingPeriod { | ||
return | ||
} | ||
|
||
if admin.VestingCounter >= admin.VestingPeriodsCount { | ||
return | ||
} | ||
|
||
address, _ := sdk.AccAddressFromBech32(admin.Address) | ||
err := k.DistributeToAccount(ctx, types.AdminPoolName, sdk.NewCoins(sdk.NewCoin(admin.Denom, admin.RewardPerPeriod.Amount)), address) | ||
if err != nil { | ||
return | ||
} | ||
|
||
admin.VestingCounter++ | ||
admin.LastVestingTime = ctx.BlockTime().Unix() | ||
|
||
k.SetAdmin(ctx, admin) | ||
} | ||
|
||
} |
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
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,59 @@ | ||
package keeper | ||
|
||
import ( | ||
"github.com/cosmos/cosmos-sdk/store/prefix" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/x/accumulator/types" | ||
) | ||
|
||
// SetAdmin set a specific deposit in the store from its index | ||
func (k BaseKeeper) SetAdmin(ctx sdk.Context, v types.Admin) { | ||
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.AdminKeyPrefix)) | ||
b := k.cdc.MustMarshal(&v) | ||
store.Set(types.AdminKey(v.Address), b) | ||
} | ||
|
||
// GetAdmin returns a Admin from its index | ||
func (k BaseKeeper) GetAdmin( | ||
ctx sdk.Context, | ||
address string, | ||
) (val types.Admin, found bool) { | ||
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.AdminKeyPrefix)) | ||
b := store.Get(types.AdminKey( | ||
address, | ||
)) | ||
|
||
if b == nil { | ||
return val, false | ||
} | ||
|
||
k.cdc.MustUnmarshal(b, &val) | ||
return val, true | ||
} | ||
|
||
// RemoveAdmin removes a Admin from the store | ||
func (k BaseKeeper) RemoveAdmin( | ||
ctx sdk.Context, | ||
address string, | ||
) { | ||
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.AdminKeyPrefix)) | ||
store.Delete(types.AdminKey( | ||
address, | ||
)) | ||
} | ||
|
||
// GetAllAdmin returns all Admin | ||
func (k BaseKeeper) GetAllAdmins(ctx sdk.Context) (list []types.Admin) { | ||
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.AdminKeyPrefix)) | ||
iterator := sdk.KVStorePrefixIterator(store, []byte{}) | ||
|
||
defer iterator.Close() | ||
|
||
for ; iterator.Valid(); iterator.Next() { | ||
var val types.Admin | ||
k.cdc.MustUnmarshal(iterator.Value(), &val) | ||
list = append(list, val) | ||
} | ||
|
||
return | ||
} |
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 |
---|---|---|
@@ -1,5 +1,42 @@ | ||
package keeper | ||
|
||
import ( | ||
"context" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/x/accumulator/types" | ||
) | ||
|
||
type msgServer struct { | ||
Keeper | ||
} | ||
|
||
func NewMsgServerImpl(keeper Keeper) types.MsgServer { | ||
return &msgServer{Keeper: keeper} | ||
} | ||
|
||
var _ types.MsgServer = msgServer{} | ||
|
||
func (m msgServer) AddAdmin(goctx context.Context, req *types.MsgAddAdmin) (*types.MsgAddAdminResponse, error) { | ||
ctx := sdk.UnwrapSDKContext(goctx) | ||
|
||
if m.GetParams(ctx).MasterAdmin != req.Creator { | ||
return nil, types.ErrForbidden | ||
} | ||
|
||
if _, ok := m.GetAdmin(ctx, req.Address); ok { | ||
return nil, types.ErrAdminExists | ||
} | ||
newAdmin := types.Admin{ | ||
Address: req.Address, | ||
VestingPeriod: req.VestingPeriod, | ||
RewardPerPeriod: req.RewardPerPeriod, | ||
VestingPeriodsCount: req.VestingPeriodsCount, | ||
VestingCounter: 0, | ||
LastVestingTime: 0, | ||
Denom: req.Denom, | ||
} | ||
|
||
m.SetAdmin(ctx, newAdmin) | ||
|
||
return new(types.MsgAddAdminResponse), nil | ||
} |
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
Oops, something went wrong.