From 1b8fb77c7af283e5cca069305969524ae3cdff11 Mon Sep 17 00:00:00 2001 From: Kobs Date: Mon, 18 Nov 2024 15:39:12 +0100 Subject: [PATCH 1/5] KIP-84 fix: reclaim --- x/layer2/keeper/msg_server.go | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/x/layer2/keeper/msg_server.go b/x/layer2/keeper/msg_server.go index 16db385c..58ba4e07 100644 --- a/x/layer2/keeper/msg_server.go +++ b/x/layer2/keeper/msg_server.go @@ -81,6 +81,14 @@ func (k msgServer) BondDappProposal(goCtx context.Context, msg *types.MsgBondDap return nil, types.ErrInvalidDappBondDenom } + dapp.TotalBond = dapp.TotalBond.Add(msg.Bond) + + properties := k.keeper.gk.GetNetworkProperties(ctx) + target := sdk.NewInt(int64(properties.MaxDappBond)) + if dapp.TotalBond.Amount.GT(target) { + return nil, types.ErrMaxDappBondReached + } + // send initial bond to module account addr := sdk.MustAccAddressFromBech32(msg.Sender) err := k.keeper.bk.SendCoinsFromAccountToModule(ctx, addr, types.ModuleName, sdk.Coins{msg.Bond}) @@ -88,12 +96,6 @@ func (k msgServer) BondDappProposal(goCtx context.Context, msg *types.MsgBondDap return nil, err } - properties := k.keeper.gk.GetNetworkProperties(ctx) - if dapp.TotalBond.Amount.GTE(sdk.NewInt(int64(properties.MaxDappBond)).Mul(sdk.NewInt(1000_000))) { - return nil, types.ErrMaxDappBondReached - } - - dapp.TotalBond = dapp.TotalBond.Add(msg.Bond) k.keeper.SetDapp(ctx, dapp) userDappBond := k.keeper.GetUserDappBond(ctx, msg.DappName, msg.Sender) @@ -114,6 +116,11 @@ func (k msgServer) BondDappProposal(goCtx context.Context, msg *types.MsgBondDap func (k msgServer) ReclaimDappBondProposal(goCtx context.Context, msg *types.MsgReclaimDappBondProposal) (*types.MsgReclaimDappBondProposalResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) + dapp := k.keeper.GetDapp(ctx, msg.DappName) + if dapp.Name == "" { + return nil, types.ErrDappDoesNotExist + } + userDappBond := k.keeper.GetUserDappBond(ctx, msg.DappName, msg.Sender) if userDappBond.DappName == "" { return nil, types.ErrUserDappBondDoesNotExist @@ -125,8 +132,7 @@ func (k msgServer) ReclaimDappBondProposal(goCtx context.Context, msg *types.Msg return nil, types.ErrNotEnoughUserDappBond } - userDappBond.Bond.Amount = userDappBond.Bond.Amount.Sub(msg.Bond.Amount) - k.keeper.SetUserDappBond(ctx, userDappBond) + dapp.TotalBond = dapp.TotalBond.Sub(msg.Bond) // send tokens back to user addr := sdk.MustAccAddressFromBech32(msg.Sender) @@ -135,6 +141,11 @@ func (k msgServer) ReclaimDappBondProposal(goCtx context.Context, msg *types.Msg return nil, err } + k.keeper.SetDapp(ctx, dapp) + + userDappBond.Bond.Amount = userDappBond.Bond.Amount.Sub(msg.Bond.Amount) + k.keeper.SetUserDappBond(ctx, userDappBond) + return &types.MsgReclaimDappBondProposalResponse{}, nil } From 982e8b2b254941712120a282dad604f70171ee2d Mon Sep 17 00:00:00 2001 From: Kobs Date: Mon, 18 Nov 2024 15:40:48 +0100 Subject: [PATCH 2/5] KIP-84 fix: reclaim --- types/constants.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/constants.go b/types/constants.go index e8708733..f4a52078 100644 --- a/types/constants.go +++ b/types/constants.go @@ -3,6 +3,6 @@ package types const ( // we set page iteration limit for safety PageIterationLimit = 512 - SekaiVersion = "v0.4.1" + SekaiVersion = "v0.4.2" CosmosVersion = "v0.47.6" ) From 708167470b84c7f155419153f7347a7a6782ae4f Mon Sep 17 00:00:00 2001 From: Kobs Date: Mon, 18 Nov 2024 15:50:02 +0100 Subject: [PATCH 3/5] KIP-84 fix: reclaim --- x/layer2/keeper/msg_server_test.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/x/layer2/keeper/msg_server_test.go b/x/layer2/keeper/msg_server_test.go index 6b7542fe..e2c3f868 100644 --- a/x/layer2/keeper/msg_server_test.go +++ b/x/layer2/keeper/msg_server_test.go @@ -155,7 +155,7 @@ func (suite *KeeperTestSuite) TestBondDappProposal() { TotalBond: sdk.Coin{}, CreationTime: 0, }, - Bond: sdk.NewInt64Coin("ukex", 10000000000), + Bond: sdk.NewInt64Coin("ukex", 1000000), } _, err = msgServer.CreateDappProposal(sdk.WrapSDKContext(suite.ctx), createMsg) @@ -165,7 +165,7 @@ func (suite *KeeperTestSuite) TestBondDappProposal() { bondMsg := &types.MsgBondDappProposal{ Sender: addr1.String(), DappName: createMsg.Dapp.Name, - Bond: sdk.NewInt64Coin("ukex", 10000000000), + Bond: sdk.NewInt64Coin("ukex", 1000000), } _, err = msgServer.BondDappProposal(sdk.WrapSDKContext(suite.ctx), bondMsg) @@ -187,7 +187,7 @@ func (suite *KeeperTestSuite) TestReclaimDappBondProposal() { val.Status = stakingtypes.Active suite.app.CustomStakingKeeper.AddValidator(suite.ctx, val) - coins := sdk.Coins{sdk.NewInt64Coin("ukex", 20000000000)} + coins := sdk.Coins{sdk.NewInt64Coin("ukex", 2000000)} 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) @@ -242,7 +242,7 @@ func (suite *KeeperTestSuite) TestReclaimDappBondProposal() { TotalBond: sdk.Coin{}, CreationTime: 0, }, - Bond: sdk.NewInt64Coin("ukex", 10000000000), + Bond: sdk.NewInt64Coin("ukex", 1000000), } _, err = msgServer.CreateDappProposal(sdk.WrapSDKContext(suite.ctx), createMsg) @@ -252,7 +252,7 @@ func (suite *KeeperTestSuite) TestReclaimDappBondProposal() { reclaimMsg := &types.MsgReclaimDappBondProposal{ Sender: addr1.String(), DappName: createMsg.Dapp.Name, - Bond: sdk.NewInt64Coin("ukex", 10000000), + Bond: sdk.NewInt64Coin("ukex", 1000000), } _, err = msgServer.ReclaimDappBondProposal(sdk.WrapSDKContext(suite.ctx), reclaimMsg) From a77d9c8aa409f6ac587c08e3e2ce9e472d669ff9 Mon Sep 17 00:00:00 2001 From: Kobs Date: Mon, 18 Nov 2024 16:09:51 +0100 Subject: [PATCH 4/5] KIP-84 fix: reclaim --- x/layer2/keeper/msg_server.go | 3 +-- x/layer2/keeper/msg_server_test.go | 10 +++++----- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/x/layer2/keeper/msg_server.go b/x/layer2/keeper/msg_server.go index 58ba4e07..2ad97fa8 100644 --- a/x/layer2/keeper/msg_server.go +++ b/x/layer2/keeper/msg_server.go @@ -84,8 +84,7 @@ func (k msgServer) BondDappProposal(goCtx context.Context, msg *types.MsgBondDap dapp.TotalBond = dapp.TotalBond.Add(msg.Bond) properties := k.keeper.gk.GetNetworkProperties(ctx) - target := sdk.NewInt(int64(properties.MaxDappBond)) - if dapp.TotalBond.Amount.GT(target) { + if dapp.TotalBond.Amount.GT(sdk.NewInt(int64(properties.MaxDappBond)).Mul(sdk.NewInt(1000_000))) { return nil, types.ErrMaxDappBondReached } diff --git a/x/layer2/keeper/msg_server_test.go b/x/layer2/keeper/msg_server_test.go index e2c3f868..6f9d56f2 100644 --- a/x/layer2/keeper/msg_server_test.go +++ b/x/layer2/keeper/msg_server_test.go @@ -155,7 +155,7 @@ func (suite *KeeperTestSuite) TestBondDappProposal() { TotalBond: sdk.Coin{}, CreationTime: 0, }, - Bond: sdk.NewInt64Coin("ukex", 1000000), + Bond: sdk.NewInt64Coin("ukex", 10000000000), } _, err = msgServer.CreateDappProposal(sdk.WrapSDKContext(suite.ctx), createMsg) @@ -165,7 +165,7 @@ func (suite *KeeperTestSuite) TestBondDappProposal() { bondMsg := &types.MsgBondDappProposal{ Sender: addr1.String(), DappName: createMsg.Dapp.Name, - Bond: sdk.NewInt64Coin("ukex", 1000000), + Bond: sdk.NewInt64Coin("ukex", 10000000000), } _, err = msgServer.BondDappProposal(sdk.WrapSDKContext(suite.ctx), bondMsg) @@ -187,7 +187,7 @@ func (suite *KeeperTestSuite) TestReclaimDappBondProposal() { val.Status = stakingtypes.Active suite.app.CustomStakingKeeper.AddValidator(suite.ctx, val) - coins := sdk.Coins{sdk.NewInt64Coin("ukex", 2000000)} + coins := sdk.Coins{sdk.NewInt64Coin("ukex", 20000000000)} 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) @@ -242,7 +242,7 @@ func (suite *KeeperTestSuite) TestReclaimDappBondProposal() { TotalBond: sdk.Coin{}, CreationTime: 0, }, - Bond: sdk.NewInt64Coin("ukex", 1000000), + Bond: sdk.NewInt64Coin("ukex", 10000000000), } _, err = msgServer.CreateDappProposal(sdk.WrapSDKContext(suite.ctx), createMsg) @@ -252,7 +252,7 @@ func (suite *KeeperTestSuite) TestReclaimDappBondProposal() { reclaimMsg := &types.MsgReclaimDappBondProposal{ Sender: addr1.String(), DappName: createMsg.Dapp.Name, - Bond: sdk.NewInt64Coin("ukex", 1000000), + Bond: sdk.NewInt64Coin("ukex", 10000000000), } _, err = msgServer.ReclaimDappBondProposal(sdk.WrapSDKContext(suite.ctx), reclaimMsg) From ca6cc7c03c6dc4b45eda515cdc6495f486c7b66a Mon Sep 17 00:00:00 2001 From: Kobs Date: Mon, 18 Nov 2024 16:16:09 +0100 Subject: [PATCH 5/5] KIP-84 fix: reclaim --- x/layer2/keeper/msg_server_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/layer2/keeper/msg_server_test.go b/x/layer2/keeper/msg_server_test.go index 6f9d56f2..6b7542fe 100644 --- a/x/layer2/keeper/msg_server_test.go +++ b/x/layer2/keeper/msg_server_test.go @@ -252,7 +252,7 @@ func (suite *KeeperTestSuite) TestReclaimDappBondProposal() { reclaimMsg := &types.MsgReclaimDappBondProposal{ Sender: addr1.String(), DappName: createMsg.Dapp.Name, - Bond: sdk.NewInt64Coin("ukex", 10000000000), + Bond: sdk.NewInt64Coin("ukex", 10000000), } _, err = msgServer.ReclaimDappBondProposal(sdk.WrapSDKContext(suite.ctx), reclaimMsg)