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

docs: Liquidity godoc QA #217

Open
wants to merge 14 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 13 additions & 13 deletions x/liquidity/keeper/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -126,15 +126,15 @@ 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
}
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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion x/liquidity/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
14 changes: 7 additions & 7 deletions x/liquidity/keeper/liquidity_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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
Expand Down