mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-12-25 07:45:18 +00:00
Certik audit revisions (#999)
* revisions: BAS-01 | Inconsistent Comment * revisions: GEE-01 | Unsorted imports * revisions: KEE-01 | Ambiguous Function Naming * revisions: OPE-01 | Redundant “if” Clause
This commit is contained in:
parent
61b7f8f56e
commit
0714d6120e
@ -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
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
|
@ -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:
|
||||
//
|
||||
|
Loading…
Reference in New Issue
Block a user