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

bugfix/KIP-84 -> release/v0.4.2 #691

Open
wants to merge 20 commits into
base: release/v0.4.2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
2 changes: 1 addition & 1 deletion 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.4.1"
SekaiVersion = "v0.4.2"
CosmosVersion = "v0.47.6"
)
26 changes: 18 additions & 8 deletions x/layer2/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,19 +81,20 @@ 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)
if dapp.TotalBond.Amount.GT(sdk.NewInt(int64(properties.MaxDappBond)).Mul(sdk.NewInt(1000_000))) {
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})
if err != nil {
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)
Expand All @@ -114,6 +115,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
Expand All @@ -125,8 +131,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)
Expand All @@ -135,6 +140,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
}

Expand Down
Loading