diff --git a/x/amm/keeper/pool_share.go b/x/amm/keeper/pool_share.go index eb7688cff..6e1e21e65 100644 --- a/x/amm/keeper/pool_share.go +++ b/x/amm/keeper/pool_share.go @@ -62,9 +62,9 @@ func (k Keeper) MintPoolShareToAccount(ctx sdk.Context, pool types.Pool, addr sd } // Commit LP token minted - lockUntil := uint64(ctx.BlockTime().Unix()) + lockUntil := uint64(0) if pool.PoolParams.UseOracle { - lockUntil += uint64(time.Hour.Seconds()) + lockUntil = uint64(ctx.BlockTime().Unix()) + uint64(time.Hour.Seconds()) } err = k.commitmentKeeper.CommitLiquidTokens(ctx, addr, poolShareDenom, amount, lockUntil) diff --git a/x/commitment/types/commitments.go b/x/commitment/types/commitments.go index 5c9062906..c7b5c18ec 100644 --- a/x/commitment/types/commitments.go +++ b/x/commitment/types/commitments.go @@ -40,23 +40,28 @@ func (c *Commitments) AddCommittedTokens(denom string, amount math.Int, unlockTi for i, token := range c.CommittedTokens { if token.Denom == denom { c.CommittedTokens[i].Amount = token.Amount.Add(amount) - c.CommittedTokens[i].Lockups = append(token.Lockups, Lockup{ - Amount: amount, - UnlockTimestamp: unlockTime, - }) + if unlockTime != 0 { + c.CommittedTokens[i].Lockups = append(token.Lockups, Lockup{ + Amount: amount, + UnlockTimestamp: unlockTime, + }) + } return } } - c.CommittedTokens = append(c.CommittedTokens, &CommittedTokens{ - Denom: denom, - Amount: amount, - Lockups: []Lockup{ - { - Amount: amount, - UnlockTimestamp: unlockTime, - }, - }, - }) + + committedToken := &CommittedTokens{ + Denom: denom, + Amount: amount, + Lockups: []Lockup{}, + } + if unlockTime != 0 { + committedToken.Lockups = append(committedToken.Lockups, Lockup{ + Amount: amount, + UnlockTimestamp: unlockTime, + }) + } + c.CommittedTokens = append(c.CommittedTokens, committedToken) } func (c *Commitments) DeductFromCommitted(denom string, amount math.Int, currTime uint64) error { @@ -67,29 +72,18 @@ func (c *Commitments) DeductFromCommitted(denom string, amount math.Int, currTim return ErrInsufficientCommittedTokens } - withdrawnTokens := sdk.ZeroInt() newLockups := []Lockup{} - + lockedAmount := sdk.ZeroInt() for _, lockup := range token.Lockups { - if withdrawnTokens.LT(amount) { - if lockup.UnlockTimestamp <= currTime { - withdrawAmount := lockup.Amount - if withdrawAmount.GT(amount.Sub(withdrawnTokens)) { - withdrawAmount = amount.Sub(withdrawnTokens) - newLockups = append(newLockups, Lockup{ - Amount: lockup.Amount.Sub(withdrawAmount), - UnlockTimestamp: lockup.UnlockTimestamp, - }) - } - withdrawnTokens = withdrawnTokens.Add(withdrawAmount) - } else { - return ErrInsufficientWithdrawableTokens - } - } else { + if lockup.UnlockTimestamp > currTime { newLockups = append(newLockups, lockup) + lockedAmount = lockedAmount.Add(lockup.Amount) } } c.CommittedTokens[i].Lockups = newLockups + if lockedAmount.GT(c.CommittedTokens[i].Amount) { + return ErrInsufficientWithdrawableTokens + } return nil } } diff --git a/x/stablestake/keeper/msg_server_bond.go b/x/stablestake/keeper/msg_server_bond.go index ceb1cfc00..81b6f1da4 100644 --- a/x/stablestake/keeper/msg_server_bond.go +++ b/x/stablestake/keeper/msg_server_bond.go @@ -69,7 +69,7 @@ func (k msgServer) Bond(goCtx context.Context, msg *types.MsgBond) (*types.MsgBo } // Commit LP token - err = k.commitmentKeeper.CommitLiquidTokens(ctx, sender, shareDenom, shareAmount, uint64(ctx.BlockTime().Unix())) + err = k.commitmentKeeper.CommitLiquidTokens(ctx, sender, shareDenom, shareAmount, 0) if err != nil { return nil, err }