Skip to content

Commit

Permalink
chore: manage eden boost burning from elys unstake and eden uncommitted
Browse files Browse the repository at this point in the history
  • Loading branch information
kenta-elys committed Sep 19, 2023
1 parent b337ad1 commit c06f61e
Show file tree
Hide file tree
Showing 15 changed files with 686 additions and 6 deletions.
17 changes: 17 additions & 0 deletions proto/elys/incentive/elys_staked.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
syntax = "proto3";
package elys.incentive;

option go_package = "github.com/elys-network/elys/x/incentive/types";
option (gogoproto.equal_all) = true;

import "gogoproto/gogo.proto";

// Elys staked
message ElysStaked {
string address = 1;
string amount = 2 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];
}

1 change: 0 additions & 1 deletion proto/elys/incentive/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ service Query {
option (google.api.http).get = "/elys-network/elys/incentive/community_pool";

}

}
// QueryParamsRequest is request type for the Query/Params RPC method.
message QueryParamsRequest {}
Expand Down
19 changes: 18 additions & 1 deletion x/amm/types/query.pb.gw.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions x/commitment/keeper/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,25 @@ func (mh MultiCommitmentHooks) CommitmentChanged(ctx sdk.Context, creator string
}
}

// Committed is called when staker committed his token
func (mh MultiCommitmentHooks) EdenUncommitted(ctx sdk.Context, creator string, amount sdk.Coin) {
for i := range mh {
mh[i].EdenUncommitted(ctx, creator, amount)
}
}

// Committed executes the indicated for committed hook
func (k Keeper) AfterCommitmentChange(ctx sdk.Context, creator string, amount sdk.Coin) {
if k.hooks == nil {
return
}
k.hooks.CommitmentChanged(ctx, creator, amount)
}

// Committed executes the indicated for committed hook
func (k Keeper) EdenUncommitted(ctx sdk.Context, creator string, amount sdk.Coin) {
if k.hooks == nil {
return
}
k.hooks.EdenUncommitted(ctx, creator, amount)
}
6 changes: 6 additions & 0 deletions x/commitment/keeper/msg_server_uncommit_tokens.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
aptypes "github.com/elys-network/elys/x/assetprofile/types"
"github.com/elys-network/elys/x/commitment/types"
ptypes "github.com/elys-network/elys/x/parameter/types"
)

func (k msgServer) UncommitTokens(goCtx context.Context, msg *types.MsgUncommitTokens) (*types.MsgUncommitTokensResponse, error) {
Expand Down Expand Up @@ -58,6 +59,11 @@ func (k msgServer) UncommitTokens(goCtx context.Context, msg *types.MsgUncommitT
// Emit Hook commitment changed
k.AfterCommitmentChange(ctx, msg.Creator, sdk.NewCoin(msg.Denom, msg.Amount))

// Emit Hook if Eden is uncommitted
if msg.Denom == ptypes.Eden {
k.EdenUncommitted(ctx, msg.Creator, sdk.NewCoin(msg.Denom, msg.Amount))
}

// Emit blockchain event
ctx.EventManager().EmitEvent(
sdk.NewEvent(
Expand Down
3 changes: 3 additions & 0 deletions x/commitment/types/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@ import sdk "github.com/cosmos/cosmos-sdk/types"
type CommitmentHooks interface {
// Token commitment changed
CommitmentChanged(ctx sdk.Context, creator string, amount sdk.Coin)

// Eden uncommitted
EdenUncommitted(ctx sdk.Context, creator string, amount sdk.Coin)
}
57 changes: 57 additions & 0 deletions x/incentive/keeper/abci.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Copyright 2022 Evmos Foundation
// This file is part of the Evmos Network packages.
//
// Evmos is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The Evmos packages are distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the Evmos packages. If not, see https://github.com/evmos/evmos/blob/main/LICENSE

package keeper

import (
"time"

"github.com/cosmos/cosmos-sdk/telemetry"
sdk "github.com/cosmos/cosmos-sdk/types"

ctypes "github.com/elys-network/elys/x/commitment/types"
"github.com/elys-network/elys/x/incentive/types"
)

// EndBlocker of incentive module
func (k Keeper) EndBlocker(ctx sdk.Context) {
defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyEndBlocker)
// Track the amount of Elys staked
k.cmk.IterateCommitments(
ctx, func(commitments ctypes.Commitments) bool {
// Commitment owner
creator := commitments.Creator
_, err := sdk.AccAddressFromBech32(creator)
if err != nil {
// This could be validator address
return false
}

// Calculate delegated amount per delegator
delegatedAmt := k.CalculateDelegatedAmount(ctx, creator)

elysStaked := types.ElysStaked{
Address: creator,
Amount: delegatedAmt,
}

// Set Elys staked amount
k.SetElysStaked(ctx, elysStaked)

return false
},
)
}
63 changes: 63 additions & 0 deletions x/incentive/keeper/elys_staked.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package keeper

import (
"github.com/cosmos/cosmos-sdk/store/prefix"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/elys-network/elys/x/incentive/types"
)

// SetSuperAdmin set a specific superAdmin in the store from its index
func (k Keeper) SetElysStaked(ctx sdk.Context, elysStaked types.ElysStaked) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.ElysStakedKeyPrefix))
b := k.cdc.MustMarshal(&elysStaked)
store.Set(types.ElysStakedKey(
elysStaked.Address,
), b)
}

// GetSuperAdmin returns a superAdmin from its index
func (k Keeper) GetElysStaked(
ctx sdk.Context,
address string,

) (val types.ElysStaked, found bool) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.ElysStakedKeyPrefix))

b := store.Get(types.ElysStakedKey(
address,
))
if b == nil {
return val, false
}

k.cdc.MustUnmarshal(b, &val)
return val, true
}

// RemoveSuperAdmin removes a superAdmin from the store
func (k Keeper) RemoveElysStaked(
ctx sdk.Context,
address string,

) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.ElysStakedKeyPrefix))
store.Delete(types.ElysStakedKey(
address,
))
}

// GetAllSuperAdmin returns all superAdmin
func (k Keeper) GetAllElysStaked(ctx sdk.Context) (list []types.ElysStaked) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.ElysStakedKeyPrefix))
iterator := sdk.KVStorePrefixIterator(store, []byte{})

defer iterator.Close()

for ; iterator.Valid(); iterator.Next() {
var val types.ElysStaked
k.cdc.MustUnmarshal(iterator.Value(), &val)
list = append(list, val)
}

return
}
10 changes: 10 additions & 0 deletions x/incentive/keeper/hooks_commitment.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ import (
func (k Keeper) CommitmentChanged(ctx sdk.Context, creator string, amount sdk.Coin) {
}

// Process eden uncommitted hook
func (k Keeper) EdenUncommitted(ctx sdk.Context, creator string, amount sdk.Coin) {
k.BurnEdenBFromEdenUncommitted(ctx, creator, amount.Amount)
}

// ___________________________________________________________________________________________________

// Hooks wrapper struct for incentive keeper
Expand All @@ -27,3 +32,8 @@ func (k Keeper) CommitmentHooks() CommitmentHooks {
func (h CommitmentHooks) CommitmentChanged(ctx sdk.Context, creator string, amount sdk.Coin) {
h.k.CommitmentChanged(ctx, creator, amount)
}

// EdenUncommitted implements EdenUncommitted
func (h CommitmentHooks) EdenUncommitted(ctx sdk.Context, creator string, amount sdk.Coin) {
h.k.EdenUncommitted(ctx, creator, amount)
}
6 changes: 3 additions & 3 deletions x/incentive/keeper/hooks_staking.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ func (k Keeper) BeforeDelegationCreated(ctx sdk.Context, delAddr sdk.AccAddress,

// Updating commitments on delegation changes
func (k Keeper) AfterDelegationModified(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress) error {
return nil
return k.BurnEdenBFromElysUnstaking(ctx, delAddr)
}

func (k Keeper) BeforeDelegationRemoved(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress) error {
return nil
return k.BurnEdenBFromElysUnstaking(ctx, delAddr)
}

func (k Keeper) BeforeDelegationSharesModified(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress) error {
return nil
return k.BurnEdenBFromElysUnstaking(ctx, delAddr)
}

// ________________________________________________________________________________________
Expand Down
Loading

0 comments on commit c06f61e

Please sign in to comment.