From 0714d6120e3e045cfff09dda8203a1d1c930b5e4 Mon Sep 17 00:00:00 2001 From: Denali Marsh Date: Wed, 18 Aug 2021 14:51:09 +0200 Subject: [PATCH] Certik audit revisions (#999) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * revisions: BAS-01 | Inconsistent Comment * revisions: GEE-01 | Unsorted imports * revisions: KEE-01 | Ambiguous Function Naming * revisions: OPE-01 | Redundant “if” Clause --- x/swap/genesis.go | 4 ++-- x/swap/keeper/deposit.go | 4 ++-- x/swap/keeper/keeper.go | 4 ++-- x/swap/keeper/withdraw.go | 2 +- x/swap/simulation/operations.go | 5 +---- x/swap/types/base_pool.go | 2 +- 6 files changed, 9 insertions(+), 12 deletions(-) diff --git a/x/swap/genesis.go b/x/swap/genesis.go index 2676d94f..40d942a1 100644 --- a/x/swap/genesis.go +++ b/x/swap/genesis.go @@ -3,9 +3,9 @@ package swap import ( "fmt" - "github.com/kava-labs/kava/x/swap/types" - sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/kava-labs/kava/x/swap/types" ) // InitGenesis initializes story state from genesis file diff --git a/x/swap/keeper/deposit.go b/x/swap/keeper/deposit.go index b7fe8db6..17310d1e 100644 --- a/x/swap/keeper/deposit.go +++ b/x/swap/keeper/deposit.go @@ -79,9 +79,9 @@ func (k Keeper) Deposit(ctx sdk.Context, depositor sdk.AccAddress, coinA sdk.Coi k.updatePool(ctx, poolID, pool) if shareRecord, hasExistingShares := k.GetDepositorShares(ctx, depositor, poolID); hasExistingShares { k.BeforePoolDepositModified(ctx, poolID, depositor, shareRecord.SharesOwned) - k.updateShares(ctx, depositor, poolID, shareRecord.SharesOwned.Add(shares)) + k.updateDepositorShares(ctx, depositor, poolID, shareRecord.SharesOwned.Add(shares)) } else { - k.updateShares(ctx, depositor, poolID, shares) + k.updateDepositorShares(ctx, depositor, poolID, shares) k.AfterPoolDepositCreated(ctx, poolID, depositor, shares) } diff --git a/x/swap/keeper/keeper.go b/x/swap/keeper/keeper.go index 8141ffc7..e7256cb1 100644 --- a/x/swap/keeper/keeper.go +++ b/x/swap/keeper/keeper.go @@ -240,8 +240,8 @@ func (k Keeper) updatePool(ctx sdk.Context, poolID string, pool *types.Denominat } } -// updateShares updates a depositor shares records for a pool, deleting the record if the new shares are zero -func (k Keeper) updateShares(ctx sdk.Context, owner sdk.AccAddress, poolID string, shares sdk.Int) { +// updateDepositorShares updates a depositor share records for a pool, deleting the record if the new shares are zero +func (k Keeper) updateDepositorShares(ctx sdk.Context, owner sdk.AccAddress, poolID string, shares sdk.Int) { if shares.IsZero() { k.DeleteDepositorShares(ctx, owner, poolID) } else { diff --git a/x/swap/keeper/withdraw.go b/x/swap/keeper/withdraw.go index 1246e51f..41c916d3 100644 --- a/x/swap/keeper/withdraw.go +++ b/x/swap/keeper/withdraw.go @@ -53,7 +53,7 @@ func (k Keeper) Withdraw(ctx sdk.Context, owner sdk.AccAddress, shares sdk.Int, k.updatePool(ctx, poolID, pool) k.BeforePoolDepositModified(ctx, poolID, owner, shareRecord.SharesOwned) - k.updateShares(ctx, owner, poolID, shareRecord.SharesOwned.Sub(shares)) + k.updateDepositorShares(ctx, owner, poolID, shareRecord.SharesOwned.Sub(shares)) err = k.supplyKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleAccountName, owner, withdrawnAmount) if err != nil { diff --git a/x/swap/simulation/operations.go b/x/swap/simulation/operations.go index dd09f664..4478911d 100644 --- a/x/swap/simulation/operations.go +++ b/x/swap/simulation/operations.go @@ -200,10 +200,7 @@ func SimulateMsgWithdraw(ak types.AccountKeeper, k keeper.Keeper) simulation.Ope // Find an account-pool pair for which withdraw is possible withdrawer, poolRecord, found := findValidAccountPoolRecordPair(accs, poolRecords, func(acc simulation.Account, poolRecord types.PoolRecord) bool { _, found := k.GetDepositorShares(ctx, acc.Address, poolRecord.PoolID) - if !found { - return false // keep searching - } - return true + return found }) if !found { return simulation.NewOperationMsgBasic(types.ModuleName, "no-operation (no valid pool record and withdrawer)", "", false, nil), nil, nil diff --git a/x/swap/types/base_pool.go b/x/swap/types/base_pool.go index a34ccf26..643c1e3e 100644 --- a/x/swap/types/base_pool.go +++ b/x/swap/types/base_pool.go @@ -119,7 +119,7 @@ func (p *BasePool) AddLiquidity(desiredA sdk.Int, desiredB sdk.Int) (sdk.Int, sd // then we use (desiredA, optimalB) as the deposit. // // If the optimalB is greater than the desiredB, we calculate the optimalA - // from the desiredB and use (optimalA, optimalB) as the deposit. + // from the desiredB and use (optimalA, desiredB) as the deposit. // // These optimal values are calculated as: //