-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat/block 391 #196
Closed
Closed
Feat/block 391 #196
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c06f61e
chore: manage eden boost burning from elys unstake and eden uncommitted
kenta-elys b5ee6db
chore: add abci test
kenta-elys 4cc8177
refactor: margin functions (#194)
cosmic-vagabond 6d828d7
fix: issue with staking hook handling and burning amount calculation
kenta-elys 1e85979
Merge branch 'main' into feat/BLOCK-391
cosmic-vagabond File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,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 | ||
]; | ||
} | ||
|
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
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,63 @@ | ||
// 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) | ||
params := k.GetParams(ctx) | ||
// Update Elys staked amount every n blocks | ||
if params.ElysStakeTrackingRate == 0 || ctx.BlockHeight()%params.ElysStakeTrackingRate != 0 { | ||
return | ||
} | ||
|
||
// 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 | ||
}, | ||
) | ||
} |
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,50 @@ | ||
package keeper_test | ||
|
||
import ( | ||
"testing" | ||
|
||
tmproto "github.com/cometbft/cometbft/proto/tendermint/types" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
simapp "github.com/elys-network/elys/app" | ||
ctypes "github.com/elys-network/elys/x/commitment/types" | ||
ptypes "github.com/elys-network/elys/x/parameter/types" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestABCI_EndBlocker(t *testing.T) { | ||
app, genAccount, _ := simapp.InitElysTestAppWithGenAccount() | ||
ctx := app.BaseApp.NewContext(initChain, tmproto.Header{}) | ||
|
||
ik := app.IncentiveKeeper | ||
|
||
var committed []sdk.Coins | ||
var uncommitted []sdk.Coins | ||
|
||
// Prepare uncommitted tokens | ||
uedenToken := sdk.NewCoins(sdk.NewCoin(ptypes.Eden, sdk.NewInt(2000))) | ||
uedenBToken := sdk.NewCoins(sdk.NewCoin(ptypes.EdenB, sdk.NewInt(2000))) | ||
uncommitted = append(uncommitted, uedenToken) | ||
uncommitted = append(uncommitted, uedenBToken) | ||
|
||
// Eden | ||
err := app.BankKeeper.MintCoins(ctx, ctypes.ModuleName, uedenToken) | ||
require.NoError(t, err) | ||
err = app.BankKeeper.SendCoinsFromModuleToAccount(ctx, ctypes.ModuleName, genAccount, uedenToken) | ||
require.NoError(t, err) | ||
|
||
// EdenB | ||
err = app.BankKeeper.MintCoins(ctx, ctypes.ModuleName, uedenBToken) | ||
require.NoError(t, err) | ||
err = app.BankKeeper.SendCoinsFromModuleToAccount(ctx, ctypes.ModuleName, genAccount, uedenBToken) | ||
require.NoError(t, err) | ||
|
||
// Add testing commitment | ||
simapp.AddTestCommitment(app, ctx, genAccount, committed, uncommitted) | ||
// Update Elys staked amount | ||
ik.EndBlocker(ctx) | ||
|
||
// Get elys staked | ||
elysStaked, found := ik.GetElysStaked(ctx, genAccount.String()) | ||
require.Equal(t, found, true) | ||
require.Equal(t, elysStaked.Amount, sdk.DefaultPowerReduction) | ||
} |
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,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 | ||
} |
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kenta-elys can you review the comments in this file they don’t make sense