Skip to content
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

feature/autocompound_interval_addition -> release/v0.3.36 #583

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
Features:

- Upgrade Cosmos SDK to v0.47.5
- Upgrade go version to 1.19
- Upgrade from tendermint to cometbft
- Update protobuf generator
- Update few invalid protobuf package names
- Add posthandler for execution fees
- Resolve claim undelegation issue
4 changes: 3 additions & 1 deletion proto/kira/gov/network_properties.proto
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ enum NetworkProperty {
DAPP_POOL_SLIPPAGE_DEFAULT = 56 [(gogoproto.enumvalue_customname) = "DappPoolSlippageDefault"];
MINTING_FT_FEE = 57 [ (gogoproto.enumvalue_customname) = "MintingFtFee" ];
MINTING_NFT_FEE = 58 [ (gogoproto.enumvalue_customname) = "MintingNftFee" ];
VETO_THRESHOLD = 59 [ (gogoproto.enumvalue_customname) = "VetoThreshold" ];
VETO_THRESHOLD = 59 [ (gogoproto.enumvalue_customname) = "VetoThreshold" ];
AUTOCOMPOUND_INTERVAL_NUM_BLOCKS = 60 [ (gogoproto.enumvalue_customname) = "AutocompoundIntervalNumBlocks" ];
}

message NetworkPropertyValue {
Expand Down Expand Up @@ -172,4 +173,5 @@ message NetworkProperties {
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
uint64 autocompound_interval_num_blocks = 61; // default 17280 - once per day
}
3 changes: 2 additions & 1 deletion proto/kira/multistaking/multistaking.proto
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,5 @@ message CompoundInfo {
string delegator = 1;
bool all_denom = 2;
repeated string compound_denoms = 3;
}
uint64 last_exec_block = 4;
}
4 changes: 2 additions & 2 deletions types/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ package types
const (
// we set page iteration limit for safety
PageIterationLimit = 512
SekaiVersion = "v0.3.34"
CosmosVersion = "v0.47.5"
SekaiVersion = "v0.3.36"
CosmosVersion = "v0.47.5"
)
1 change: 1 addition & 0 deletions x/genutil/client/cli/upgrade_genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ $ %s new-genesis-from-exported exported-genesis.json new-genesis.json
MintingFtFee: 100_000_000_000_000,
MintingNftFee: 100_000_000_000_000,
VetoThreshold: sdk.NewDecWithPrec(3340, 2), //33.40%
AutocompoundIntervalNumBlocks: 17280,
},
ExecutionFees: govGenesisV01228.ExecutionFees,
PoorNetworkMessages: govGenesisV01228.PoorNetworkMessages,
Expand Down
1 change: 1 addition & 0 deletions x/gov/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@ func TestExportInitGenesis(t *testing.T) {
MintingFtFee: 100_000_000_000_000,
MintingNftFee: 100_000_000_000_000,
VetoThreshold: sdk.NewDecWithPrec(3340, 2), // 33.40%
AutocompoundIntervalNumBlocks: 17280,
},
ExecutionFees: []types.ExecutionFee{
{
Expand Down
6 changes: 5 additions & 1 deletion x/gov/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package keeper
import (
"errors"
"fmt"

"github.com/KiraCore/sekai/x/gov/types"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/store/prefix"
Expand Down Expand Up @@ -248,7 +249,8 @@ func (k Keeper) GetNetworkProperty(ctx sdk.Context, property types.NetworkProper
return types.NetworkPropertyValue{Value: properties.MintingNftFee}, nil
case types.VetoThreshold:
return types.NetworkPropertyValue{StrValue: properties.VetoThreshold.String()}, nil

case types.AutocompoundIntervalNumBlocks:
return types.NetworkPropertyValue{Value: properties.AutocompoundIntervalNumBlocks}, nil
default:
return types.NetworkPropertyValue{}, errors.New("trying to fetch network property that does not exist")
}
Expand Down Expand Up @@ -402,6 +404,8 @@ func (k Keeper) SetNetworkProperty(ctx sdk.Context, property types.NetworkProper
}
properties.VetoThreshold = decValue

case types.AutocompoundIntervalNumBlocks:
properties.AutocompoundIntervalNumBlocks = value.Value
default:
return errors.New("trying to set network property that does not exist")
}
Expand Down
1 change: 1 addition & 0 deletions x/gov/types/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ func DefaultGenesis() *GenesisState {
MintingFtFee: 100_000_000_000_000,
MintingNftFee: 100_000_000_000_000,
VetoThreshold: sdk.NewDecWithPrec(3340, 2), // 33.40%
AutocompoundIntervalNumBlocks: 17280,
},
ExecutionFees: []ExecutionFee{
{
Expand Down
392 changes: 218 additions & 174 deletions x/gov/types/network_properties.pb.go

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions x/gov/types/query.pb.go

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

5 changes: 4 additions & 1 deletion x/gov/types/query.pb.gw.go

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

6 changes: 6 additions & 0 deletions x/multistaking/keeper/delegation.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ func (k Keeper) SetUndelegation(ctx sdk.Context, undelegation types.Undelegation
store.Set(key, k.cdc.MustMarshal(&undelegation))
}

func (k Keeper) RemoveUndelegation(ctx sdk.Context, id uint64) {
store := ctx.KVStore(k.storeKey)
key := append(types.KeyPrefixUndelegation, sdk.Uint64ToBigEndian(id)...)
store.Delete(key)
}

func (k Keeper) SetPoolDelegator(ctx sdk.Context, poolId uint64, delegator sdk.AccAddress) {
store := ctx.KVStore(k.storeKey)
key := append(append(types.KeyPrefixPoolDelegator, sdk.Uint64ToBigEndian(poolId)...), delegator...)
Expand Down
2 changes: 2 additions & 0 deletions x/multistaking/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ func (k msgServer) ClaimUndelegation(goCtx context.Context, msg *types.MsgClaimU
return nil, err
}

k.keeper.RemoveUndelegation(ctx, undelegation.Id)

return &types.MsgClaimUndelegationResponse{}, nil
}

Expand Down
90 changes: 90 additions & 0 deletions x/multistaking/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package keeper_test

import (
"time"

multistakingkeeper "github.com/KiraCore/sekai/x/multistaking/keeper"
multistakingtypes "github.com/KiraCore/sekai/x/multistaking/types"
stakingtypes "github.com/KiraCore/sekai/x/staking/types"
"github.com/cometbft/cometbft/crypto/ed25519"
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
sdk "github.com/cosmos/cosmos-sdk/types"
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
)

func (suite *KeeperTestSuite) TestClaimUndelegation() {
addr1 := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address().Bytes())

valAddr := sdk.ValAddress(addr1)
pubkeys := simtestutil.CreateTestPubKeys(1)
pubKey := pubkeys[0]
val, err := stakingtypes.NewValidator(valAddr, pubKey)
suite.Require().NoError(err)

properties := suite.app.CustomGovKeeper.GetNetworkProperties(suite.ctx)
properties.MinCollectiveBond = 1
suite.app.CustomGovKeeper.SetNetworkProperties(suite.ctx, properties)

val.Status = stakingtypes.Active
suite.app.CustomStakingKeeper.AddValidator(suite.ctx, val)

stakingPool := multistakingtypes.StakingPool{
Id: 1,
Validator: valAddr.String(),
Enabled: true,
}

suite.app.MultiStakingKeeper.SetStakingPool(suite.ctx, stakingPool)

coins := sdk.Coins{sdk.NewInt64Coin("ukex", 1000000)}
err = suite.app.BankKeeper.MintCoins(suite.ctx, minttypes.ModuleName, coins)
suite.Require().NoError(err)
err = suite.app.BankKeeper.SendCoinsFromModuleToAccount(suite.ctx, minttypes.ModuleName, addr1, coins)
suite.Require().NoError(err)
msgServer := multistakingkeeper.NewMsgServerImpl(suite.app.MultiStakingKeeper, suite.app.BankKeeper, suite.app.CustomGovKeeper, suite.app.CustomStakingKeeper)
_, err = msgServer.Delegate(sdk.WrapSDKContext(suite.ctx), &multistakingtypes.MsgDelegate{
DelegatorAddress: addr1.String(),
ValidatorAddress: valAddr.String(),
Amounts: coins,
})
suite.Require().NoError(err)

_, err = msgServer.Undelegate(sdk.WrapSDKContext(suite.ctx), &multistakingtypes.MsgUndelegate{
DelegatorAddress: addr1.String(),
ValidatorAddress: valAddr.String(),
Amounts: coins,
})
suite.Require().NoError(err)

undelegations := suite.app.MultiStakingKeeper.GetAllUndelegations(suite.ctx)
suite.Require().Len(undelegations, 1)
suite.Require().Equal(undelegations[0], multistakingtypes.Undelegation{
Id: 1,
Address: addr1.String(),
ValAddress: valAddr.String(),
Expiry: uint64(suite.ctx.BlockTime().Unix()) + properties.UnstakingPeriod,
Amount: coins,
})

// claim before expiry
_, err = msgServer.ClaimUndelegation(sdk.WrapSDKContext(suite.ctx), &multistakingtypes.MsgClaimUndelegation{
Sender: addr1.String(),
UndelegationId: 1,
})
suite.Require().Error(err)

// claim correctly
suite.ctx = suite.ctx.WithBlockTime(suite.ctx.BlockTime().Add(time.Second * time.Duration(properties.UnstakingPeriod)))
_, err = msgServer.ClaimUndelegation(sdk.WrapSDKContext(suite.ctx), &multistakingtypes.MsgClaimUndelegation{
Sender: addr1.String(),
UndelegationId: 1,
})
suite.Require().NoError(err)

// Try claim again
_, err = msgServer.ClaimUndelegation(sdk.WrapSDKContext(suite.ctx), &multistakingtypes.MsgClaimUndelegation{
Sender: addr1.String(),
UndelegationId: 1,
})
suite.Require().Error(err)
}
Loading
Loading