From cdc5d5b14fe041e7aa50d2268d7f95c0d786da7c Mon Sep 17 00:00:00 2001 From: Ruslan Akhtariev <46343690+pysel@users.noreply.github.com> Date: Sat, 12 Aug 2023 00:14:21 +0200 Subject: [PATCH] golangci: enable unused parameters linter (#6018) * enable unused parameters linter * enable unparam linter and fix basic unparam warnings * finish with unparam * reset deliverTx and mark as nolint * nolint no favor * changelog (cherry picked from commit 2e3f19d86dd4e3c961a3594f3577b96e2eb00707) # Conflicts: # x/concentrated-liquidity/client/cli/tx.go # x/protorev/keeper/rebalance.go # x/superfluid/keeper/migrate.go --- .golangci.yml | 1 + CHANGELOG.md | 1 + app/upgrades/v15/export_test.go | 4 +- app/upgrades/v15/upgrade_test.go | 3 +- app/upgrades/v15/upgrades.go | 8 +- simulation/executor/mock_tendermint.go | 5 +- simulation/executor/util.go | 1 + simulation/simtypes/txbuilder.go | 4 +- tests/e2e/configurer/upgrade.go | 5 +- tests/e2e/initialization/chain.go | 4 +- tests/e2e/initialization/init.go | 11 +- x/concentrated-liquidity/client/cli/tx.go | 5 + x/concentrated-liquidity/export_test.go | 10 +- x/concentrated-liquidity/incentives.go | 2 +- x/concentrated-liquidity/pool.go | 16 +- .../simulation/sim_msgs.go | 4 +- x/downtime-detector/client/cli/query.go | 1 + x/gamm/simulation/sim_msgs.go | 4 +- x/incentives/client/cli/tx.go | 4 +- x/poolmanager/create_pool.go | 4 +- x/poolmanager/export_test.go | 2 +- x/protorev/client/cli/query.go | 2 + x/protorev/keeper/rebalance.go | 143 ++++++++++++++++++ x/superfluid/keeper/export_test.go | 2 +- x/superfluid/keeper/migrate.go | 10 +- x/superfluid/keeper/stake.go | 10 +- x/tokenfactory/keeper/createdenom.go | 4 +- 27 files changed, 210 insertions(+), 60 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 3e367e1e7ae..4e92b01dbea 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -40,6 +40,7 @@ linters: - unconvert - unused - whitespace + - unparam issues: exclude-rules: diff --git a/CHANGELOG.md b/CHANGELOG.md index 255062d05f5..f4d5751978c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -48,6 +48,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * [#5983](https://github.com/osmosis-labs/osmosis/pull/5983) refactor(CL): 6 return values in CL CreatePosition with a struct * [#5983](https://github.com/osmosis-labs/osmosis/pull/5983) refactor(CL): 6 return values in CL CreatePosition with a struct * [#6004](https://github.com/osmosis-labs/osmosis/pull/6004) reduce number of returns for creating full range position +* [#6018](https://github.com/osmosis-labs/osmosis/pull/6018) golangci: add unused parameters linter ### Misc Improvements * [#5976](https://github.com/osmosis-labs/osmosis/pull/5976) chore[e2e]: faster epoch diff --git a/app/upgrades/v15/export_test.go b/app/upgrades/v15/export_test.go index bdcde6bb677..2e0dd36b7cd 100644 --- a/app/upgrades/v15/export_test.go +++ b/app/upgrades/v15/export_test.go @@ -26,8 +26,8 @@ func SetICQParams(ctx sdk.Context, icqKeeper *icqkeeper.Keeper) { setICQParams(ctx, icqKeeper) } -func MigrateBalancerPoolToSolidlyStable(ctx sdk.Context, gammKeeper *gammkeeper.Keeper, poolmanager *poolmanager.Keeper, bankKeeper bankkeeper.Keeper, poolId uint64) { - migrateBalancerPoolToSolidlyStable(ctx, gammKeeper, poolmanager, bankKeeper, poolId) +func MigrateBalancerPoolToSolidlyStable(ctx sdk.Context, gammKeeper *gammkeeper.Keeper, bankKeeper bankkeeper.Keeper, poolId uint64) { + migrateBalancerPoolToSolidlyStable(ctx, gammKeeper, bankKeeper, poolId) } func SetRateLimits(ctx sdk.Context, accountKeeper *authkeeper.AccountKeeper, rateLimitingICS4Wrapper *ibcratelimit.ICS4Wrapper, wasmKeeper *wasmkeeper.Keeper) { diff --git a/app/upgrades/v15/upgrade_test.go b/app/upgrades/v15/upgrade_test.go index 5e7699d753e..308f46311e1 100644 --- a/app/upgrades/v15/upgrade_test.go +++ b/app/upgrades/v15/upgrade_test.go @@ -90,7 +90,6 @@ func (suite *UpgradeTestSuite) TestMigrateBalancerToStablePools() { ctx := suite.Ctx gammKeeper := suite.App.GAMMKeeper - poolmanagerKeeper := suite.App.PoolManagerKeeper // bankKeeper := suite.App.BankKeeper testAccount := suite.TestAccs[0] @@ -138,7 +137,7 @@ func (suite *UpgradeTestSuite) TestMigrateBalancerToStablePools() { balancerBalances := suite.App.BankKeeper.GetAllBalances(ctx, balancerPool.GetAddress()) // test migrating the balancer pool to a stable pool - v15.MigrateBalancerPoolToSolidlyStable(ctx, gammKeeper, poolmanagerKeeper, suite.App.BankKeeper, poolID) + v15.MigrateBalancerPoolToSolidlyStable(ctx, gammKeeper, suite.App.BankKeeper, poolID) // check that the pool is now a stable pool stablepool, err := gammKeeper.GetCFMMPool(ctx, poolID) diff --git a/app/upgrades/v15/upgrades.go b/app/upgrades/v15/upgrades.go index c5ba966adbb..243f0d8ff53 100644 --- a/app/upgrades/v15/upgrades.go +++ b/app/upgrades/v15/upgrades.go @@ -63,7 +63,7 @@ func CreateUpgradeHandler( // Stride stXXX/XXX pools are being migrated from the standard balancer curve to the // solidly stable curve. - migrateBalancerPoolsToSolidlyStable(ctx, keepers.GAMMKeeper, keepers.PoolManagerKeeper, keepers.BankKeeper) + migrateBalancerPoolsToSolidlyStable(ctx, keepers.GAMMKeeper, keepers.BankKeeper) setRateLimits(ctx, keepers.AccountKeeper, keepers.RateLimitingICS4Wrapper, keepers.WasmKeeper) @@ -79,15 +79,15 @@ func setICQParams(ctx sdk.Context, icqKeeper *icqkeeper.Keeper) { icqKeeper.SetParams(ctx, icqparams) } -func migrateBalancerPoolsToSolidlyStable(ctx sdk.Context, gammKeeper *gammkeeper.Keeper, poolmanagerKeeper *poolmanager.Keeper, bankKeeper bankkeeper.Keeper) { +func migrateBalancerPoolsToSolidlyStable(ctx sdk.Context, gammKeeper *gammkeeper.Keeper, bankKeeper bankkeeper.Keeper) { // migrate stOSMO_OSMOPoolId, stJUNO_JUNOPoolId, stSTARS_STARSPoolId pools := []uint64{stOSMO_OSMOPoolId, stJUNO_JUNOPoolId, stSTARS_STARSPoolId} for _, poolId := range pools { - migrateBalancerPoolToSolidlyStable(ctx, gammKeeper, poolmanagerKeeper, bankKeeper, poolId) + migrateBalancerPoolToSolidlyStable(ctx, gammKeeper, bankKeeper, poolId) } } -func migrateBalancerPoolToSolidlyStable(ctx sdk.Context, gammKeeper *gammkeeper.Keeper, poolmanagerKeeper *poolmanager.Keeper, bankKeeper bankkeeper.Keeper, poolId uint64) { +func migrateBalancerPoolToSolidlyStable(ctx sdk.Context, gammKeeper *gammkeeper.Keeper, bankKeeper bankkeeper.Keeper, poolId uint64) { // fetch the pool with the given poolId balancerPool, err := gammKeeper.GetCFMMPool(ctx, poolId) if err != nil { diff --git a/simulation/executor/mock_tendermint.go b/simulation/executor/mock_tendermint.go index 5d50dc436b1..9ad81fcf756 100644 --- a/simulation/executor/mock_tendermint.go +++ b/simulation/executor/mock_tendermint.go @@ -181,7 +181,7 @@ func RandomRequestBeginBlock(r *rand.Rand, params Params, } voteInfos := randomVoteInfos(r, params, validators) - evidence := randomDoubleSignEvidence(r, params, validators, pastTimes, pastVoteInfos, event, header, voteInfos) + evidence := randomDoubleSignEvidence(r, params, pastTimes, pastVoteInfos, event, header, voteInfos) return abci.RequestBeginBlock{ Header: header, @@ -230,8 +230,7 @@ func randomVoteInfos(r *rand.Rand, simParams Params, validators mockValidators, return voteInfos } -func randomDoubleSignEvidence(r *rand.Rand, params Params, - validators mockValidators, pastTimes []time.Time, +func randomDoubleSignEvidence(r *rand.Rand, params Params, pastTimes []time.Time, pastVoteInfos [][]abci.VoteInfo, event func(route, op, evResult string), header tmproto.Header, voteInfos []abci.VoteInfo, ) []abci.Evidence { diff --git a/simulation/executor/util.go b/simulation/executor/util.go index 3e254392b84..02e55ec6a3c 100644 --- a/simulation/executor/util.go +++ b/simulation/executor/util.go @@ -8,6 +8,7 @@ import ( "github.com/osmosis-labs/osmosis/v16/simulation/simtypes" ) +//nolint:unparam func getTestingMode(tb testing.TB) (testingMode bool, t *testing.T, b *testing.B) { tb.Helper() testingMode = false diff --git a/simulation/simtypes/txbuilder.go b/simulation/simtypes/txbuilder.go index 4dbc3132331..3aff64fb978 100644 --- a/simulation/simtypes/txbuilder.go +++ b/simulation/simtypes/txbuilder.go @@ -62,14 +62,14 @@ func (sim *SimCtx) deliverTx(tx sdk.Tx, msg sdk.Msg, msgName string) (simulation txConfig := params.MakeEncodingConfig().TxConfig // TODO: unhardcode gasInfo, results, err := sim.BaseApp().Deliver(txConfig.TxEncoder(), tx) if err != nil { - return simulation.NoOpMsg(msgName, msgName, fmt.Sprintf("unable to deliver tx. \nreason: %v\n results: %v\n msg: %s\n tx: %s", err, results, msg, tx)), nil, nil, err + return simulation.NoOpMsg(msgName, msgName, fmt.Sprintf("unable to deliver tx. \nreason: %v\n results: %v\n msg: %s\n tx: %s", err, results, msg, tx)), []simulation.FutureOperation{}, nil, err } opMsg := simulation.NewOperationMsg(msg, true, "", gasInfo.GasWanted, gasInfo.GasUsed, nil) opMsg.Route = msgName opMsg.Name = msgName - return opMsg, nil, results.Data, nil + return opMsg, []simulation.FutureOperation{}, results.Data, nil } // GenTx generates a signed mock transaction. diff --git a/tests/e2e/configurer/upgrade.go b/tests/e2e/configurer/upgrade.go index 9bee1a689b9..3683d09794e 100644 --- a/tests/e2e/configurer/upgrade.go +++ b/tests/e2e/configurer/upgrade.go @@ -307,7 +307,7 @@ func (uc *UpgradeConfigurer) RunSetup() error { func (uc *UpgradeConfigurer) RunUpgrade() error { var err error if uc.forkHeight > 0 { - err = uc.runForkUpgrade() + uc.runForkUpgrade() } else { err = uc.runProposalUpgrade() } @@ -389,13 +389,12 @@ func (uc *UpgradeConfigurer) runProposalUpgrade() error { return nil } -func (uc *UpgradeConfigurer) runForkUpgrade() error { +func (uc *UpgradeConfigurer) runForkUpgrade() { for _, chainConfig := range uc.chainConfigs { uc.t.Logf("waiting to reach fork height on chain %s", chainConfig.Id) chainConfig.WaitUntilHeight(uc.forkHeight) uc.t.Logf("fork height reached on chain %s", chainConfig.Id) } - return nil } func (uc *UpgradeConfigurer) upgradeContainers(chainConfig *chain.Config, propHeight int64) error { diff --git a/tests/e2e/initialization/chain.go b/tests/e2e/initialization/chain.go index 690503b78a5..d782f1401ae 100644 --- a/tests/e2e/initialization/chain.go +++ b/tests/e2e/initialization/chain.go @@ -12,14 +12,14 @@ type internalChain struct { nodes []*internalNode } -func new(id, dataDir string) (*internalChain, error) { +func new(id, dataDir string) *internalChain { chainMeta := ChainMeta{ Id: id, DataDir: dataDir, } return &internalChain{ chainMeta: chainMeta, - }, nil + } } func (c *internalChain) export() *Chain { diff --git a/tests/e2e/initialization/init.go b/tests/e2e/initialization/init.go index db9282f3ab2..dea2573b78d 100644 --- a/tests/e2e/initialization/init.go +++ b/tests/e2e/initialization/init.go @@ -10,10 +10,7 @@ import ( ) func InitChain(id, dataDir string, nodeConfigs []*NodeConfig, votingPeriod, expeditedVotingPeriod time.Duration, forkHeight int) (*Chain, error) { - chain, err := new(id, dataDir) - if err != nil { - return nil, err - } + chain := new(id, dataDir) for _, nodeConfig := range nodeConfigs { newNode, err := newNode(chain, nodeConfig) @@ -49,11 +46,7 @@ func InitSingleNode(chainId, dataDir string, existingGenesisDir string, nodeConf return nil, errors.New("creating individual validator nodes after starting up chain is not currently supported") } - chain, err := new(chainId, dataDir) - if err != nil { - return nil, err - } - + chain := new(chainId, dataDir) newNode, err := newNode(chain, nodeConfig) if err != nil { return nil, err diff --git a/x/concentrated-liquidity/client/cli/tx.go b/x/concentrated-liquidity/client/cli/tx.go index 663b5fd6c54..fbe3aef9ae3 100644 --- a/x/concentrated-liquidity/client/cli/tx.go +++ b/x/concentrated-liquidity/client/cli/tx.go @@ -300,8 +300,13 @@ func parsePoolRecords(cmd *cobra.Command) ([]types.PoolRecord, error) { poolRecords := strings.Split(poolRecordsStr, ",") +<<<<<<< HEAD if len(poolRecords)%5 != 0 { return nil, fmt.Errorf("poolRecords must be a list of denom0, denom1, tickSpacing, exponentAtPriceOne, and spreadFactor") +======= + if len(poolRecords)%4 != 0 { + return nil, fmt.Errorf("poolRecords must be a list of denom0, denom1, tickSpacing, and spreadFactor") +>>>>>>> 2e3f19d8 (golangci: enable unused parameters linter (#6018)) } finalPoolRecords := []types.PoolRecord{} diff --git a/x/concentrated-liquidity/export_test.go b/x/concentrated-liquidity/export_test.go index caf99818625..26025b0aa10 100644 --- a/x/concentrated-liquidity/export_test.go +++ b/x/concentrated-liquidity/export_test.go @@ -131,15 +131,15 @@ func AsConcentrated(poolI poolmanagertypes.PoolI) (types.ConcentratedPoolExtensi } func (k Keeper) ValidateSpreadFactor(ctx sdk.Context, params types.Params, spreadFactor sdk.Dec) bool { - return k.validateSpreadFactor(ctx, params, spreadFactor) + return k.validateSpreadFactor(params, spreadFactor) } func (k Keeper) ValidateTickSpacing(ctx sdk.Context, params types.Params, tickSpacing uint64) bool { - return k.validateTickSpacing(ctx, params, tickSpacing) + return k.validateTickSpacing(params, tickSpacing) } func (k Keeper) ValidateTickSpacingUpdate(ctx sdk.Context, pool types.ConcentratedPoolExtension, params types.Params, newTickSpacing uint64) bool { - return k.validateTickSpacingUpdate(ctx, pool, params, newTickSpacing) + return k.validateTickSpacingUpdate(pool, params, newTickSpacing) } func (k Keeper) FungifyChargedPosition(ctx sdk.Context, owner sdk.AccAddress, positionIds []uint64) (uint64, error) { @@ -319,7 +319,7 @@ func (k Keeper) GetListenersUnsafe() types.ConcentratedLiquidityListeners { } func ValidateAuthorizedQuoteDenoms(ctx sdk.Context, denom1 string, authorizedQuoteDenoms []string) bool { - return validateAuthorizedQuoteDenoms(ctx, denom1, authorizedQuoteDenoms) + return validateAuthorizedQuoteDenoms(denom1, authorizedQuoteDenoms) } func (k Keeper) ValidatePositionUpdateById(ctx sdk.Context, positionId uint64, updateInitiator sdk.AccAddress, lowerTickGiven int64, upperTickGiven int64, liquidityDeltaGiven sdk.Dec, joinTimeGiven time.Time, poolIdGiven uint64) error { @@ -331,7 +331,7 @@ func (k Keeper) GetLargestAuthorizedUptimeDuration(ctx sdk.Context) time.Duratio } func (k Keeper) GetLargestSupportedUptimeDuration(ctx sdk.Context) time.Duration { - return k.getLargestSupportedUptimeDuration(ctx) + return k.getLargestSupportedUptimeDuration() } func (k Keeper) SetupSwapStrategy(ctx sdk.Context, p types.ConcentratedPoolExtension, diff --git a/x/concentrated-liquidity/incentives.go b/x/concentrated-liquidity/incentives.go index 17903834f8a..c19dfc34bdc 100644 --- a/x/concentrated-liquidity/incentives.go +++ b/x/concentrated-liquidity/incentives.go @@ -1129,6 +1129,6 @@ func (k Keeper) getLargestAuthorizedUptimeDuration(ctx sdk.Context) time.Duratio // nolint: unused // getLargestSupportedUptimeDuration retrieves the largest supported uptime duration from the preset constant slice. -func (k Keeper) getLargestSupportedUptimeDuration(ctx sdk.Context) time.Duration { +func (k Keeper) getLargestSupportedUptimeDuration() time.Duration { return getLargestDuration(types.SupportedUptimes) } diff --git a/x/concentrated-liquidity/pool.go b/x/concentrated-liquidity/pool.go index 5707fb7b914..1e17868e45d 100644 --- a/x/concentrated-liquidity/pool.go +++ b/x/concentrated-liquidity/pool.go @@ -42,15 +42,15 @@ func (k Keeper) InitializePool(ctx sdk.Context, poolI poolmanagertypes.PoolI, cr poolId := concentratedPool.GetId() quoteAsset := concentratedPool.GetToken1() - if !k.validateTickSpacing(ctx, params, tickSpacing) { + if !k.validateTickSpacing(params, tickSpacing) { return types.UnauthorizedTickSpacingError{ProvidedTickSpacing: tickSpacing, AuthorizedTickSpacings: params.AuthorizedTickSpacing} } - if !k.validateSpreadFactor(ctx, params, spreadFactor) { + if !k.validateSpreadFactor(params, spreadFactor) { return types.UnauthorizedSpreadFactorError{ProvidedSpreadFactor: spreadFactor, AuthorizedSpreadFactors: params.AuthorizedSpreadFactors} } - if !validateAuthorizedQuoteDenoms(ctx, quoteAsset, params.AuthorizedQuoteDenoms) { + if !validateAuthorizedQuoteDenoms(quoteAsset, params.AuthorizedQuoteDenoms) { return types.UnauthorizedQuoteDenomError{ProvidedQuoteDenom: quoteAsset, AuthorizedQuoteDenoms: params.AuthorizedQuoteDenoms} } @@ -270,7 +270,7 @@ func (k Keeper) DecreaseConcentratedPoolTickSpacing(ctx sdk.Context, poolIdToTic } params := k.GetParams(ctx) - if !k.validateTickSpacingUpdate(ctx, pool, params, poolIdToTickSpacingRecord.NewTickSpacing) { + if !k.validateTickSpacingUpdate(pool, params, poolIdToTickSpacingRecord.NewTickSpacing) { return fmt.Errorf("tick spacing %d is not valid", poolIdToTickSpacingRecord.NewTickSpacing) } @@ -285,7 +285,7 @@ func (k Keeper) DecreaseConcentratedPoolTickSpacing(ctx sdk.Context, poolIdToTic // validateTickSpacing returns true if the given tick spacing is one of the authorized tick spacings set in the // params. False otherwise. -func (k Keeper) validateTickSpacing(ctx sdk.Context, params types.Params, tickSpacing uint64) bool { +func (k Keeper) validateTickSpacing(params types.Params, tickSpacing uint64) bool { for _, authorizedTick := range params.AuthorizedTickSpacing { if tickSpacing == authorizedTick { return true @@ -296,7 +296,7 @@ func (k Keeper) validateTickSpacing(ctx sdk.Context, params types.Params, tickSp // validateTickSpacingUpdate returns true if the given tick spacing is one of the authorized tick spacings set in the // params and is less than the current tick spacing. False otherwise. -func (k Keeper) validateTickSpacingUpdate(ctx sdk.Context, pool types.ConcentratedPoolExtension, params types.Params, newTickSpacing uint64) bool { +func (k Keeper) validateTickSpacingUpdate(pool types.ConcentratedPoolExtension, params types.Params, newTickSpacing uint64) bool { currentTickSpacing := pool.GetTickSpacing() for _, authorizedTick := range params.AuthorizedTickSpacing { // New tick spacing must be one of the authorized tick spacings and must be less than the current tick spacing @@ -309,7 +309,7 @@ func (k Keeper) validateTickSpacingUpdate(ctx sdk.Context, pool types.Concentrat // validateSpreadFactor returns true if the given spread factor is one of the authorized spread factors set in the // params. False otherwise. -func (k Keeper) validateSpreadFactor(ctx sdk.Context, params types.Params, spreadFactor sdk.Dec) bool { +func (k Keeper) validateSpreadFactor(params types.Params, spreadFactor sdk.Dec) bool { for _, authorizedSpreadFactor := range params.AuthorizedSpreadFactors { if spreadFactor.Equal(authorizedSpreadFactor) { return true @@ -328,7 +328,7 @@ func (k Keeper) validateSpreadFactor(ctx sdk.Context, params types.Params, sprea // // Returns: // - bool: A boolean indicating if the denom1 is authorized or not. -func validateAuthorizedQuoteDenoms(ctx sdk.Context, denom1 string, authorizedQuoteDenoms []string) bool { +func validateAuthorizedQuoteDenoms(denom1 string, authorizedQuoteDenoms []string) bool { for _, authorizedQuoteDenom := range authorizedQuoteDenoms { if denom1 == authorizedQuoteDenom { return true diff --git a/x/concentrated-liquidity/simulation/sim_msgs.go b/x/concentrated-liquidity/simulation/sim_msgs.go index 4d81ea2c6ca..a6d1634a2a3 100644 --- a/x/concentrated-liquidity/simulation/sim_msgs.go +++ b/x/concentrated-liquidity/simulation/sim_msgs.go @@ -233,7 +233,7 @@ func RandMsgCollectIncentives(k clkeeper.Keeper, sim *osmosimtypes.SimCtx, ctx s } // createPoolRestriction creates specific restriction for the creation of a pool. -func createPoolRestriction(k clkeeper.Keeper, sim *osmosimtypes.SimCtx, ctx sdk.Context) osmosimtypes.SimAccountConstraint { +func createPoolRestriction(sim *osmosimtypes.SimCtx, ctx sdk.Context) osmosimtypes.SimAccountConstraint { return func(acc legacysimulationtype.Account) bool { accCoins := sim.BankKeeper().SpendableCoins(ctx, acc.Address) hasTwoCoins := len(accCoins) >= 3 @@ -329,7 +329,7 @@ func RandomPreparePoolFunc(sim *osmosimtypes.SimCtx, ctx sdk.Context, k clkeeper authorizedSpreadFactor := cltypes.AuthorizedSpreadFactors // find an address with two or more distinct denoms in their wallet - sender, senderExists := sim.RandomSimAccountWithConstraint(createPoolRestriction(k, sim, ctx)) + sender, senderExists := sim.RandomSimAccountWithConstraint(createPoolRestriction(sim, ctx)) if !senderExists { return nil, sdk.Coin{}, sdk.Coin{}, 0, sdk.Dec{}, fmt.Errorf("no sender with two different denoms & pool creation fee exists") } diff --git a/x/downtime-detector/client/cli/query.go b/x/downtime-detector/client/cli/query.go index 3725e19aabb..c55ab5675ce 100644 --- a/x/downtime-detector/client/cli/query.go +++ b/x/downtime-detector/client/cli/query.go @@ -30,6 +30,7 @@ downtime-duration is a duration, but is restricted to a smaller set. Heres a few }, &queryproto.RecoveredSinceDowntimeOfLengthRequest{} } +//nolint:unparam func parseDowntimeDuration(arg string, _ *pflag.FlagSet) (any, osmocli.FieldReadLocation, error) { dur, err := time.ParseDuration(arg) if err != nil { diff --git a/x/gamm/simulation/sim_msgs.go b/x/gamm/simulation/sim_msgs.go index 2e4dfc86015..9582356f787 100644 --- a/x/gamm/simulation/sim_msgs.go +++ b/x/gamm/simulation/sim_msgs.go @@ -87,7 +87,7 @@ func RandomExitPoolMsg(k keeper.Keeper, sim *simtypes.SimCtx, ctx sdk.Context) ( func RandomCreateUniV2Msg(k keeper.Keeper, sim *simtypes.SimCtx, ctx sdk.Context) (*balancertypes.MsgCreateBalancerPool, error) { var poolAssets []balancertypes.PoolAsset // find an address with two or more distinct denoms in their wallet - sender, senderExists := sim.RandomSimAccountWithConstraint(createPoolRestriction(k, sim, ctx)) + sender, senderExists := sim.RandomSimAccountWithConstraint(createPoolRestriction(sim, ctx)) if !senderExists { return nil, errors.New("no sender with two different denoms & pool creation fee exists") } @@ -405,7 +405,7 @@ func deriveRealMinShareOutAmt(ctx sdk.Context, tokenIn sdk.Coins, pool types.CFM return minShareOutAmt, nil } -func createPoolRestriction(k keeper.Keeper, sim *simtypes.SimCtx, ctx sdk.Context) simtypes.SimAccountConstraint { +func createPoolRestriction(sim *simtypes.SimCtx, ctx sdk.Context) simtypes.SimAccountConstraint { return func(acc legacysimulationtype.Account) bool { accCoins := sim.BankKeeper().SpendableCoins(ctx, acc.Address) hasTwoCoins := len(accCoins) >= 2 diff --git a/x/incentives/client/cli/tx.go b/x/incentives/client/cli/tx.go index 365df5981a3..1f1f7389cf0 100644 --- a/x/incentives/client/cli/tx.go +++ b/x/incentives/client/cli/tx.go @@ -88,8 +88,8 @@ func NewCreateGaugeCmd() *cobra.Command { } var distributeTo lockuptypes.QueryCondition - // if poolId is 0 it is a guranteed lock gauge - // if poolId is > 0 it is a guranteed no-lock gauge + // if poolId is 0 it is a guaranteed lock gauge + // if poolId is > 0 it is a guaranteed no-lock gauge if poolId == 0 { distributeTo = lockuptypes.QueryCondition{ LockQueryType: lockuptypes.ByDuration, diff --git a/x/poolmanager/create_pool.go b/x/poolmanager/create_pool.go index 8f7534a4473..6e6a5c7e6d7 100644 --- a/x/poolmanager/create_pool.go +++ b/x/poolmanager/create_pool.go @@ -12,7 +12,7 @@ import ( ) // validateCreatedPool checks that the pool was created with the correct pool ID and address. -func (k Keeper) validateCreatedPool(ctx sdk.Context, poolId uint64, pool types.PoolI) error { +func (k Keeper) validateCreatedPool(poolId uint64, pool types.PoolI) error { if pool.GetId() != poolId { return types.IncorrectPoolIdError{ExpectedPoolId: poolId, ActualPoolId: pool.GetId()} } @@ -115,7 +115,7 @@ func (k Keeper) createPoolZeroLiquidityNoCreationFee(ctx sdk.Context, msg types. k.SetPoolRoute(ctx, poolId, msg.GetPoolType()) // Validates the pool address and pool ID stored match what was expected. - if err := k.validateCreatedPool(ctx, poolId, pool); err != nil { + if err := k.validateCreatedPool(poolId, pool); err != nil { return nil, err } diff --git a/x/poolmanager/export_test.go b/x/poolmanager/export_test.go index 2a59d27772d..b12ed609cf3 100644 --- a/x/poolmanager/export_test.go +++ b/x/poolmanager/export_test.go @@ -39,7 +39,7 @@ func (k Keeper) GetAllPoolRoutes(ctx sdk.Context) []types.ModuleRoute { } func (k Keeper) ValidateCreatedPool(ctx sdk.Context, poolId uint64, pool types.PoolI) error { - return k.validateCreatedPool(ctx, poolId, pool) + return k.validateCreatedPool(poolId, pool) } func (k Keeper) IsOsmoRoutedMultihop(ctx sdk.Context, route types.MultihopRoute, inDenom, outDenom string) (isRouted bool) { diff --git a/x/protorev/client/cli/query.go b/x/protorev/client/cli/query.go index bf5b718b012..e7ec399f135 100644 --- a/x/protorev/client/cli/query.go +++ b/x/protorev/client/cli/query.go @@ -158,6 +158,8 @@ func NewQueryPoolCmd() (*osmocli.QueryDescriptor, *types.QueryGetProtoRevPoolReq } // convert a string array "[1,2,3]" to []uint64 +// +//nolint:unparam func parseRoute(arg string, _ *pflag.FlagSet) (any, osmocli.FieldReadLocation, error) { var route []uint64 err := json.Unmarshal([]byte(arg), &route) diff --git a/x/protorev/keeper/rebalance.go b/x/protorev/keeper/rebalance.go index 33a25007766..80db823ab01 100644 --- a/x/protorev/keeper/rebalance.go +++ b/x/protorev/keeper/rebalance.go @@ -167,6 +167,149 @@ func (k Keeper) FindMaxProfitForRoute(ctx sdk.Context, route RouteMetaData, rema return tokenIn, profit, nil } +<<<<<<< HEAD +======= +// UpdateSearchRangeIfNeeded updates the search range for the binary search. First, we check if there are any +// concentrated liquidity pools in the route. If there are, then we may need to reduce the upper bound of the +// binary search since it is gas intensive to move across several ticks. Next, we determine if the current bound +// includes the optimal amount in. If it does not, then we can extend the search range to capture more profits. +func (k Keeper) UpdateSearchRangeIfNeeded( + ctx sdk.Context, + route RouteMetaData, + inputDenom string, + curLeft, curRight sdk.Int, +) (sdk.Int, sdk.Int, error) { + // If there are concentrated liquidity pools in the route, then we may need to reduce the upper bound of the binary search. + updatedMax, err := k.CalculateUpperBoundForSearch(ctx, route, inputDenom) + if err != nil { + return sdk.ZeroInt(), sdk.ZeroInt(), err + } + + // In the case where the updated upper bound is less than the current upper bound, we know we will not extend + // the search range so we can short-circuit return. + if updatedMax.LT(curRight) { + return curLeft, updatedMax, nil + } + + return k.ExtendSearchRangeIfNeeded(ctx, route, inputDenom, curLeft, curRight, updatedMax) +} + +// CalculateUpperBoundForSearch returns the max amount in that can be used for the binary search +// respecting the max ticks moved across all concentrated liquidity pools in the route. +func (k Keeper) CalculateUpperBoundForSearch( + ctx sdk.Context, + route RouteMetaData, + inputDenom string, +) (sdk.Int, error) { + var intermidiateCoin sdk.Coin + + poolInfo := k.GetInfoByPoolType(ctx) + + // Iterate through all CL pools and determine the maximal amount of input that can be used + // respecting the max ticks moved. + for index := route.Route.Length() - 1; index >= 0; index-- { + hop := route.Route[index] + pool, err := k.poolmanagerKeeper.GetPool(ctx, hop.PoolId) + if err != nil { + return sdk.ZeroInt(), err + } + + tokenInDenom := inputDenom + if index > 0 { + tokenInDenom = route.Route[index-1].TokenOutDenom + } + + switch { + case pool.GetType() == poolmanagertypes.Concentrated: + // If the pool is a concentrated liquidity pool, then check the maximum amount in that can be used + // and determine what this amount is as an input at the previous pool (working all the way up to the + // beginning of the route). + maxTokenIn, maxTokenOut, err := k.concentratedLiquidityKeeper.ComputeMaxInAmtGivenMaxTicksCrossed( + ctx, + pool.GetId(), + tokenInDenom, + poolInfo.Concentrated.MaxTicksCrossed, + ) + if err != nil { + return sdk.ZeroInt(), err + } + + // if there have been no other CL pools in the route, then we can set the intermediate coin to the max input amount. + // Additionally, if the amount of the previous token is greater than the possible amount from this pool, then we + // can set the intermediate coin to the max input amount (from the current pool). Otherwise we have to do a + // safe swap given the previous max amount. + if intermidiateCoin.IsNil() || maxTokenOut.Amount.LT(intermidiateCoin.Amount) { + intermidiateCoin = maxTokenIn + continue + } + + // In the scenario where there are multiple CL pools in a route, we select the one that inputs + // the smaller amount to ensure we do not overstep the max ticks moved. + intermidiateCoin, err = k.executeSafeSwap(ctx, pool.GetId(), intermidiateCoin, tokenInDenom) + if err != nil { + return sdk.ZeroInt(), err + } + case !intermidiateCoin.IsNil(): + // If we have already seen a CL pool in the route, then simply propagate the intermediate coin up + // the route. + intermidiateCoin, err = k.executeSafeSwap(ctx, pool.GetId(), intermidiateCoin, tokenInDenom) + if err != nil { + return sdk.ZeroInt(), err + } + } + } + + // In the case where there are no CL pools, we want to return the extended max input amount + if intermidiateCoin.IsNil() { + return types.ExtendedMaxInputAmount, nil + } + + // Ensure that the normalized upper bound is not greater than the extended max input amount + upperBound := intermidiateCoin.Amount.Quo(route.StepSize) + if upperBound.GT(types.ExtendedMaxInputAmount) { + return types.ExtendedMaxInputAmount, nil + } + + return upperBound, nil +} + +// executeSafeSwap executes a safe swap by first ensuring the swap amount is less than the +// amount of total liquidity in the pool. +func (k Keeper) executeSafeSwap( + ctx sdk.Context, + poolID uint64, + outputCoin sdk.Coin, + tokenInDenom string, +) (sdk.Coin, error) { + liquidity, err := k.poolmanagerKeeper.GetTotalPoolLiquidity(ctx, poolID) + if err != nil { + return sdk.NewCoin(tokenInDenom, sdk.ZeroInt()), err + } + + // At most we can swap half of the liquidity in the pool + liquidTokenAmt := liquidity.AmountOf(outputCoin.Denom).Quo(sdk.NewInt(4)) + if liquidTokenAmt.LT(outputCoin.Amount) { + outputCoin.Amount = liquidTokenAmt + } + + amt, err := k.poolmanagerKeeper.MultihopEstimateInGivenExactAmountOut( + ctx, + poolmanagertypes.SwapAmountOutRoutes{ + { + PoolId: poolID, + TokenInDenom: tokenInDenom, + }, + }, + outputCoin, + ) + if err != nil { + return sdk.NewCoin(tokenInDenom, sdk.ZeroInt()), err + } + + return sdk.NewCoin(tokenInDenom, amt), nil +} + +>>>>>>> 2e3f19d8 (golangci: enable unused parameters linter (#6018)) // Determine if the binary search range needs to be extended func (k Keeper) ExtendSearchRangeIfNeeded(ctx sdk.Context, route RouteMetaData, inputDenom string, curLeft, curRight sdk.Int) (sdk.Int, sdk.Int) { // Get the profit for the maximum amount in diff --git a/x/superfluid/keeper/export_test.go b/x/superfluid/keeper/export_test.go index dc36c4d6516..57b4c4f0d48 100644 --- a/x/superfluid/keeper/export_test.go +++ b/x/superfluid/keeper/export_test.go @@ -40,7 +40,7 @@ func (k Keeper) ValidateSharesToMigrateUnlockAndExitBalancerPool(ctx sdk.Context } func (k Keeper) RouteMigration(ctx sdk.Context, sender sdk.AccAddress, lockId int64, sharesToMigrate sdk.Coin) (synthLockBeforeMigration lockuptypes.SyntheticLock, migrationType MigrationType, err error) { - return k.routeMigration(ctx, sender, lockId, sharesToMigrate) + return k.routeMigration(ctx, lockId) } func (k Keeper) ValidateMigration(ctx sdk.Context, sender sdk.AccAddress, lockId uint64, sharesToMigrate sdk.Coin) (types.MigrationPoolIDs, *lockuptypes.PeriodLock, time.Duration, error) { diff --git a/x/superfluid/keeper/migrate.go b/x/superfluid/keeper/migrate.go index c2d137c46c8..e8ac560503a 100644 --- a/x/superfluid/keeper/migrate.go +++ b/x/superfluid/keeper/migrate.go @@ -43,7 +43,7 @@ const ( // // Errors if the lock is not found, if the lock is not a balancer pool lock, or if the lock is not owned by the sender. func (k Keeper) RouteLockedBalancerToConcentratedMigration(ctx sdk.Context, sender sdk.AccAddress, providedLockId int64, sharesToMigrate sdk.Coin, tokenOutMins sdk.Coins) (positionData cltypes.CreateFullRangePositionData, migratedPoolIDs types.MigrationPoolIDs, concentratedLockId uint64, err error) { - synthLockBeforeMigration, migrationType, err := k.routeMigration(ctx, sender, providedLockId, sharesToMigrate) + synthLockBeforeMigration, migrationType, err := k.routeMigration(ctx, providedLockId) if err != nil { return cltypes.CreateFullRangePositionData{}, types.MigrationPoolIDs{}, 0, err } @@ -95,6 +95,7 @@ func (k Keeper) migrateSuperfluidBondedBalancerToConcentrated(ctx sdk.Context, // Superfluid undelegate the portion of shares the user is migrating from the superfluid delegated position. // If all shares are being migrated, this deletes the connection between the gamm lock and the intermediate account, deletes the synthetic lock, and burns the synthetic osmo. +<<<<<<< HEAD intermediateAccount := types.SuperfluidIntermediaryAccount{} var gammLockToMigrate *lockuptypes.PeriodLock if isPartialMigration { @@ -112,6 +113,11 @@ func (k Keeper) migrateSuperfluidBondedBalancerToConcentrated(ctx sdk.Context, if err != nil { return cltypes.CreateFullRangePositionData{}, 0, types.MigrationPoolIDs{}, err } +======= + intermediateAccount, err := k.SuperfluidUndelegateToConcentratedPosition(ctx, sender.String(), originalLockId) + if err != nil { + return cltypes.CreateFullRangePositionData{}, 0, types.MigrationPoolIDs{}, err +>>>>>>> 2e3f19d8 (golangci: enable unused parameters linter (#6018)) } // Force unlock, validate the provided sharesToMigrate, and exit the balancer pool. @@ -229,7 +235,7 @@ func (k Keeper) migrateNonSuperfluidLockBalancerToConcentrated(ctx sdk.Context, // routeMigration determines the status of the provided lock which is used to determine the method for migration. // It also returns the underlying synthetic locks of the provided lock, if any exist. -func (k Keeper) routeMigration(ctx sdk.Context, sender sdk.AccAddress, providedLockId int64, sharesToMigrate sdk.Coin) (synthLockBeforeMigration lockuptypes.SyntheticLock, migrationType MigrationType, err error) { +func (k Keeper) routeMigration(ctx sdk.Context, providedLockId int64) (synthLockBeforeMigration lockuptypes.SyntheticLock, migrationType MigrationType, err error) { // As a hack around to get frontend working, we decided to allow negative values for the provided lock ID to indicate that the user wants to migrate shares that are not locked. if providedLockId <= 0 { return lockuptypes.SyntheticLock{}, Unlocked, nil diff --git a/x/superfluid/keeper/stake.go b/x/superfluid/keeper/stake.go index bd40b110a77..7cb1ba44ae4 100644 --- a/x/superfluid/keeper/stake.go +++ b/x/superfluid/keeper/stake.go @@ -128,7 +128,7 @@ func (k Keeper) IncreaseSuperfluidDelegation(ctx sdk.Context, lockID uint64, amo // basic validation for locks to be eligible for superfluid delegation. This includes checking // - that the sender is the owner of the lock // - that the lock is consisted of single coin -func (k Keeper) validateLockForSF(ctx sdk.Context, lock *lockuptypes.PeriodLock, sender string) error { +func (k Keeper) validateLockForSF(lock *lockuptypes.PeriodLock, sender string) error { if lock.Owner != sender { return lockuptypes.ErrNotLockOwner } @@ -146,7 +146,7 @@ func (k Keeper) validateLockForSF(ctx sdk.Context, lock *lockuptypes.PeriodLock, // - lock duration is greater or equal to the unbonding time // - lock should not be already superfluid staked func (k Keeper) validateLockForSFDelegate(ctx sdk.Context, lock *lockuptypes.PeriodLock, sender string) error { - err := k.validateLockForSF(ctx, lock, sender) + err := k.validateLockForSF(lock, sender) if err != nil { return err } @@ -255,7 +255,7 @@ func (k Keeper) undelegateCommon(ctx sdk.Context, sender string, lockID uint64) if err != nil { return types.SuperfluidIntermediaryAccount{}, err } - err = k.validateLockForSF(ctx, lock, sender) + err = k.validateLockForSF(lock, sender) if err != nil { return types.SuperfluidIntermediaryAccount{}, err } @@ -316,7 +316,7 @@ func (k Keeper) partialUndelegateCommon(ctx sdk.Context, sender string, lockID u if err != nil { return types.SuperfluidIntermediaryAccount{}, &lockuptypes.PeriodLock{}, err } - err = k.validateLockForSF(ctx, lock, sender) + err = k.validateLockForSF(lock, sender) if err != nil { return types.SuperfluidIntermediaryAccount{}, &lockuptypes.PeriodLock{}, err } @@ -465,7 +465,7 @@ func (k Keeper) unbondLock(ctx sdk.Context, underlyingLockId uint64, sender stri if err != nil { return 0, err } - err = k.validateLockForSF(ctx, lock, sender) + err = k.validateLockForSF(lock, sender) if err != nil { return 0, err } diff --git a/x/tokenfactory/keeper/createdenom.go b/x/tokenfactory/keeper/createdenom.go index bb456750421..824886fa2c5 100644 --- a/x/tokenfactory/keeper/createdenom.go +++ b/x/tokenfactory/keeper/createdenom.go @@ -16,7 +16,7 @@ func (k Keeper) CreateDenom(ctx sdk.Context, creatorAddr string, subdenom string return "", err } - err = k.chargeForCreateDenom(ctx, creatorAddr, subdenom) + err = k.chargeForCreateDenom(ctx, creatorAddr) if err != nil { return "", err } @@ -73,7 +73,7 @@ func (k Keeper) validateCreateDenom(ctx sdk.Context, creatorAddr string, subdeno return denom, nil } -func (k Keeper) chargeForCreateDenom(ctx sdk.Context, creatorAddr string, subdenom string) (err error) { +func (k Keeper) chargeForCreateDenom(ctx sdk.Context, creatorAddr string) (err error) { params := k.GetParams(ctx) // if DenomCreationFee is non-zero, transfer the tokens from the creator