diff --git a/x/liquidity/keeper/batch.go b/x/liquidity/keeper/batch.go index b597ac8fe..3ffc52110 100644 --- a/x/liquidity/keeper/batch.go +++ b/x/liquidity/keeper/batch.go @@ -7,13 +7,13 @@ import ( "github.com/tendermint/liquidity/x/liquidity/types" ) -// Reinitialize batch messages that were not executed in the previous batch and delete batch messages that were executed or ready to delete. +// Reinitialize batch messages that were not executed in the previous batch and delete batch messages that were executed or are ready to delete. func (k Keeper) DeleteAndInitPoolBatch(ctx sdk.Context) { k.IterateAllPoolBatches(ctx, func(poolBatch types.PoolBatch) bool { - // Delete and init next batch when not empty batch on before block + // Delete and init the next batch when batch was not empty on the previous block if poolBatch.Executed { - // On the other hand, BatchDeposit, BatchWithdraw, is all handled by the endblock if there is no error. - // If there are BatchMsgs left, reset the Executed, Succeeded flag so that it can be executed in the next batch. + // On the other hand, handle BatchDeposit, BatchWithdraw by the endblock if there is no error. + // If there are BatchMsgs left, reset the Executed, Succeeded flag so that the messages can be executed in the next batch. depositMsgs := k.GetAllRemainingPoolBatchDepositMsgStates(ctx, poolBatch) if len(depositMsgs) > 0 { for _, msg := range depositMsgs { @@ -35,7 +35,7 @@ func (k Keeper) DeleteAndInitPoolBatch(ctx sdk.Context) { height := ctx.BlockHeight() // reinitialize remaining batch msgs - // In the case of BatchSwapMsgs, it is often fractional matched or has not yet expired since it has not passed ExpiryHeight. + // In the case of BatchSwapMsgs, it is often fractionally matched or has not yet expired since it has not passed ExpiryHeight. swapMsgs := k.GetAllRemainingPoolBatchSwapMsgStates(ctx, poolBatch) if len(swapMsgs) > 0 { for _, msg := range swapMsgs { @@ -63,7 +63,7 @@ func (k Keeper) DeleteAndInitPoolBatch(ctx sdk.Context) { }) } -// Increase the index of the already executed batch for processing as the next batch and reinitialize the values. +// Increase the index of the batch that was already executed to be processed as the next batch and reinitialize the values. func (k Keeper) InitNextBatch(ctx sdk.Context, poolBatch types.PoolBatch) error { if !poolBatch.Executed { return types.ErrBatchNotExecuted @@ -78,8 +78,8 @@ func (k Keeper) InitNextBatch(ctx sdk.Context, poolBatch types.PoolBatch) error return nil } -// In case of deposit, withdraw, and swap msgs, unlike other normal tx msgs, -// collect them in the liquidity pool batch and perform an execution once at the endblock to calculate and use the universal price. +// In contrast to normal tx msgs, collect the deposit, withdraw, and swap msgs +// in the liquidity pool batch and then perform an execution once at the endblock to calculate and use the universal price. func (k Keeper) ExecutePoolBatch(ctx sdk.Context) { k.IterateAllPoolBatches(ctx, func(poolBatch types.PoolBatch) bool { params := k.GetParams(ctx) @@ -126,7 +126,7 @@ func (k Keeper) ExecutePoolBatch(ctx sdk.Context) { }) } -// In order to deal with the batch at once, the coins of msgs deposited in escrow. +// The coins of msgs are deposited in escrow to deal with the batch one time. func (k Keeper) HoldEscrow(ctx sdk.Context, depositor sdk.AccAddress, depositCoins sdk.Coins) error { if err := k.bankKeeper.SendCoinsFromAccountToModule(ctx, depositor, types.ModuleName, depositCoins); err != nil { return err @@ -134,7 +134,7 @@ func (k Keeper) HoldEscrow(ctx sdk.Context, depositor sdk.AccAddress, depositCoi return nil } -// If batch messages has expired or has not been processed, will be refunded the escrow that had been deposited through this function. +// If batch message has expired or has not been processed, refund the escrow that was deposited through this function. func (k Keeper) ReleaseEscrow(ctx sdk.Context, withdrawer sdk.AccAddress, withdrawCoins sdk.Coins) error { if err := k.bankKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, withdrawer, withdrawCoins); err != nil { return err @@ -158,7 +158,7 @@ func (k Keeper) ReleaseEscrowForMultiSend(withdrawer sdk.AccAddress, withdrawCoi return input, output, nil } -// In order to deal with the batch at once, Put the message in the batch and the coins of the msgs deposited in escrow. +// To deal with the batch one time, put the message in the batch and deposit the coins of the msgs in escrow. func (k Keeper) DepositLiquidityPoolToBatch(ctx sdk.Context, msg *types.MsgDepositWithinBatch) (types.DepositMsgState, error) { if err := k.ValidateMsgDepositLiquidityPool(ctx, *msg); err != nil { return types.DepositMsgState{}, err @@ -190,7 +190,7 @@ func (k Keeper) DepositLiquidityPoolToBatch(ctx sdk.Context, msg *types.MsgDepos return msgState, nil } -// In order to deal with the batch at once, Put the message in the batch and the coins of the msgs deposited in escrow. +// To deal with the batch one time, put the message in the batch and deposit the coins of the msgs in escrow. func (k Keeper) WithdrawLiquidityPoolToBatch(ctx sdk.Context, msg *types.MsgWithdrawWithinBatch) (types.WithdrawMsgState, error) { if err := k.ValidateMsgWithdrawLiquidityPool(ctx, *msg); err != nil { return types.WithdrawMsgState{}, err @@ -222,7 +222,7 @@ func (k Keeper) WithdrawLiquidityPoolToBatch(ctx sdk.Context, msg *types.MsgWith return batchPoolMsg, nil } -// In order to deal with the batch at once, Put the message in the batch and the coins of the msgs deposited in escrow. +// To deal with the batch one time, put the message in the batch and deposit the coins of the msgs in escrow. func (k Keeper) SwapLiquidityPoolToBatch(ctx sdk.Context, msg *types.MsgSwapWithinBatch, OrderExpirySpanHeight int64) (*types.SwapMsgState, error) { if err := k.ValidateMsgSwapWithinBatch(ctx, *msg); err != nil { return nil, err diff --git a/x/liquidity/keeper/grpc_query.go b/x/liquidity/keeper/grpc_query.go index d7ac8606e..5b5ded27b 100644 --- a/x/liquidity/keeper/grpc_query.go +++ b/x/liquidity/keeper/grpc_query.go @@ -58,7 +58,7 @@ func (k Querier) LiquidityPoolBatch(c context.Context, req *types.QueryLiquidity }, nil } -// Pools queries all liquidity pools currently existed with each liquidity pool with batch and metadata. +// Pools queries all existing liquidity pools for each liquidity pool batch and metadata. func (k Querier) LiquidityPools(c context.Context, req *types.QueryLiquidityPoolsRequest) (*types.QueryLiquidityPoolsResponse, error) { empty := &types.QueryLiquidityPoolsRequest{} if req == nil || req == empty { diff --git a/x/liquidity/keeper/liquidity_pool.go b/x/liquidity/keeper/liquidity_pool.go index a237aca86..43ec79a38 100644 --- a/x/liquidity/keeper/liquidity_pool.go +++ b/x/liquidity/keeper/liquidity_pool.go @@ -18,7 +18,7 @@ func (k Keeper) ValidateMsgCreatePool(ctx sdk.Context, msg *types.MsgCreatePool) params := k.GetParams(ctx) var poolType types.PoolType - // check poolType exist, get poolType from param + // check if poolType exists, get poolType from param if len(params.PoolTypes) >= int(msg.PoolTypeId) { poolType = params.PoolTypes[msg.PoolTypeId-1] if poolType.Id != msg.PoolTypeId { @@ -172,7 +172,7 @@ func (k Keeper) DepositLiquidityPool(ctx sdk.Context, msg types.DepositMsgState, reserveCoins := k.GetReserveCoins(ctx, pool) - // reinitialize pool in case of reserve coins has run out + // reinitialize pool in case the reserve coins have run out if reserveCoins.IsZero() { for _, depositCoin := range msg.Msg.DepositCoins { if depositCoin.Amount.LT(params.MinInitDepositAmount) { @@ -249,7 +249,7 @@ func (k Keeper) DepositLiquidityPool(ctx sdk.Context, msg types.DepositMsgState, refundedCoinA := sdk.NewInt(0) refundedCoinB := sdk.NewInt(0) - // handle when depositing coin A amount is less than, greater than or equal to depositable amount + // handle when depositing coin A amount is less than, greater than, or equal to depositable amount if depositCoinA.Amount.LT(depositableCoinAmountA) { depositCoinAmountB = depositCoinA.Amount.ToDec().QuoTruncate(lastReserveRatio).TruncateInt() acceptedCoins = sdk.NewCoins(depositCoinA, sdk.NewCoin(depositCoinB.Denom, depositCoinAmountB)) @@ -543,7 +543,7 @@ func (k Keeper) RefundDepositLiquidityPool(ctx sdk.Context, batchMsg types.Depos if err := k.ReleaseEscrow(ctx, batchMsg.Msg.GetDepositor(), batchMsg.Msg.DepositCoins); err != nil { return err } - // not delete now, set ToBeDeleted true for delete on next block beginblock + // do not delete now, and set ToBeDeleted true for delete on next block beginblock batchMsg.ToBeDeleted = true k.SetPoolBatchDepositMsgState(ctx, batchMsg.Msg.PoolId, batchMsg) ctx.EventManager().EmitEvent( @@ -583,7 +583,7 @@ func (k Keeper) RefundWithdrawLiquidityPool(ctx sdk.Context, batchMsg types.With sdk.NewAttribute(types.AttributeValueSuccess, types.Failure), )) - // not delete now, set ToBeDeleted true for delete on next block beginblock + // do not delete now, and set ToBeDeleted true for delete on next block beginblock batchMsg.ToBeDeleted = true k.SetPoolBatchWithdrawMsgState(ctx, batchMsg.Msg.PoolId, batchMsg) return nil @@ -767,7 +767,7 @@ func (k Keeper) ValidateMsgSwapWithinBatch(ctx sdk.Context, msg types.MsgSwapWit params := k.GetParams(ctx) - // can not exceed max order ratio of reserve coins that can be ordered at a order + // cannot exceed max order ratio of reserve coins for one order reserveCoinAmt := k.GetReserveCoins(ctx, pool).AmountOf(msg.OfferCoin.Denom) if !reserveCoinAmt.IsPositive() { @@ -884,7 +884,7 @@ func (k Keeper) ValidatePoolRecord(ctx sdk.Context, record types.PoolRecord) err return nil } -// IsPoolCoinDenom checks is the denom poolcoin or not, need to additional checking the reserve account is existed +// IsPoolCoinDenom checks if the denom is already a poolcoin, need to additionally check if the reserve account exists func (k Keeper) IsPoolCoinDenom(ctx sdk.Context, denom string) bool { if err := sdk.ValidateDenom(denom); err != nil { return false