Skip to content

Commit

Permalink
refactor(deps): switch to cosmossdk.io/math from fork math (#6238)
Browse files Browse the repository at this point in the history
* refactor(deps): switch to cosmossdk.io/math from fork math

* switch remaining things

* updates

(cherry picked from commit ca75f4c)

# Conflicts:
#	app/apptesting/concentrated_liquidity.go
#	app/apptesting/pool_manager.go
#	app/apptesting/test_suite.go
#	app/upgrades/v16/upgrades.go
#	app/upgrades/v17/constants.go
#	app/upgrades/v18/upgrades_test.go
#	app/upgrades/v19/upgrades.go
#	app/upgrades/v19/upgrades_test.go
#	app/upgrades/v3/forks.go
#	app/upgrades/v9/prop214.go
#	cmd/osmosisd/cmd/genesis.go
#	cmd/osmosisd/cmd/root.go
#	go.mod
#	go.sum
#	osmomath/sqrt.go
#	osmomath/sqrt_big_test.go
#	osmomath/sqrt_test.go
#	osmoutils/osmocli/dynamic_test.go
#	simulation/simtypes/randutil.go
#	tests/cl-genesis-positions/go.mod
#	tests/cl-genesis-positions/go.sum
#	tests/e2e/configurer/chain/chain.go
#	tests/e2e/configurer/chain/commands.go
#	tests/e2e/configurer/chain/queries.go
#	tests/e2e/configurer/upgrade.go
#	tests/e2e/containers/containers.go
#	tests/e2e/e2e_test.go
#	tests/e2e/helpers_e2e_test.go
#	tests/e2e/initialization/config.go
#	tests/e2e/initialization/node.go
#	tests/ibc-hooks/ibc_middleware_test.go
#	tests/ibc-hooks/path_validation_test.go
#	tests/ibc-hooks/xcs_cw20_test.go
#	tests/simulator/sim_test.go
#	tests/simulator/state.go
#	wasmbinding/query_plugin_test.go
#	wasmbinding/test/custom_msg_test.go
#	wasmbinding/test/helpers_test.go
#	wasmbinding/test/messages_test.go
#	x/concentrated-liquidity/bench_test.go
#	x/concentrated-liquidity/client/query_proto_wrap.go
#	x/concentrated-liquidity/event.go
#	x/concentrated-liquidity/incentives.go
#	x/concentrated-liquidity/incentives_test.go
#	x/concentrated-liquidity/math/precompute.go
#	x/concentrated-liquidity/model/msgs.go
#	x/concentrated-liquidity/model/msgs_test.go
#	x/concentrated-liquidity/msg_server.go
#	x/concentrated-liquidity/msg_server_test.go
#	x/concentrated-liquidity/simulation/sim_msgs.go
#	x/concentrated-liquidity/total_liquidity.go
#	x/concentrated-liquidity/types/expected_keepers.go
#	x/concentrated-liquidity/types/gov_test.go
#	x/concentrated-liquidity/types/msgs_test.go
#	x/concentrated-liquidity/types/params_test.go
#	x/cosmwasmpool/cosmwasm/msg/transmuter/transmuter_test.go
#	x/cosmwasmpool/model/pool_test.go
#	x/cosmwasmpool/model/store_model.go
#	x/cosmwasmpool/pool_module_test.go
#	x/gamm/client/cli/query_test.go
#	x/gamm/client/cli/tx_test.go
#	x/gamm/keeper/export_test.go
#	x/gamm/keeper/gas_test.go
#	x/gamm/keeper/genesis_test.go
#	x/gamm/keeper/grpc_query.go
#	x/gamm/keeper/grpc_query_test.go
#	x/gamm/keeper/keeper_test.go
#	x/gamm/keeper/msg_server_test.go
#	x/gamm/keeper/pool.go
#	x/gamm/keeper/pool_test.go
#	x/gamm/keeper/share.go
#	x/gamm/keeper/swap.go
#	x/gamm/keeper/swap_test.go
#	x/gamm/keeper/total_liquidity.go
#	x/gamm/pool-models/balancer/amm_test.go
#	x/gamm/pool-models/balancer/marshal_test.go
#	x/gamm/pool-models/balancer/msgs_test.go
#	x/gamm/pool-models/balancer/pool.go
#	x/gamm/pool-models/balancer/pool_asset.go
#	x/gamm/pool-models/balancer/pool_params.go
#	x/gamm/pool-models/internal/cfmm_common/lp_test.go
#	x/gamm/pool-models/stableswap/msgs_test.go
#	x/gamm/pool-models/stableswap/pool_params.go
#	x/gamm/pool-models/stableswap/util_test.go
#	x/gamm/simulation/sim_msgs.go
#	x/gamm/types/expected_keepers.go
#	x/gamm/types/gov.go
#	x/gamm/types/msgs_test.go
#	x/gamm/types/pool.go
#	x/ibc-rate-limit/ibc_middleware_test.go
#	x/incentives/client/cli/query_test.go
#	x/incentives/keeper/distribute.go
#	x/incentives/keeper/distribute_test.go
#	x/incentives/keeper/export_test.go
#	x/incentives/keeper/gauge.go
#	x/incentives/keeper/gauge_test.go
#	x/incentives/keeper/grpc_query_test.go
#	x/incentives/keeper/keeper_test.go
#	x/incentives/keeper/msg_server_test.go
#	x/incentives/keeper/store_test.go
#	x/incentives/simulation/operations.go
#	x/incentives/types/expected_keepers.go
#	x/incentives/types/gauge.go
#	x/incentives/types/msgs_test.go
#	x/lockup/keeper/bench_test.go
#	x/lockup/keeper/genesis_test.go
#	x/lockup/keeper/grpc_query_test.go
#	x/lockup/keeper/invariants.go
#	x/lockup/keeper/lock.go
#	x/lockup/keeper/lock_test.go
#	x/lockup/keeper/msg_server_test.go
#	x/lockup/keeper/store.go
#	x/lockup/types/msgs_test.go
#	x/mint/keeper/export_test.go
#	x/mint/keeper/genesis.go
#	x/mint/simulation/decoder_test.go
#	x/mint/simulation/genesis.go
#	x/mint/simulation/genesis_test.go
#	x/mint/types/minter_test.go
#	x/mint/types/params_test.go
#	x/pool-incentives/keeper/distr_test.go
#	x/pool-incentives/keeper/genesis.go
#	x/pool-incentives/keeper/genesis_test.go
#	x/pool-incentives/keeper/grpc_query.go
#	x/pool-incentives/keeper/grpc_query_test.go
#	x/pool-incentives/keeper/hooks.go
#	x/pool-incentives/keeper/keeper_test.go
#	x/pool-incentives/types/genesis_test.go
#	x/pool-incentives/types/gov_test.go
#	x/pool-incentives/types/incentives_test.go
#	x/pool-incentives/types/record_test.go
#	x/poolmanager/client/cli/tx.go
#	x/poolmanager/client/cli/tx_test.go
#	x/poolmanager/client/testutil/test_helpers.go
#	x/poolmanager/create_pool_test.go
#	x/poolmanager/events/emit_test.go
#	x/poolmanager/export_test.go
#	x/poolmanager/keeper_test.go
#	x/poolmanager/msg_server_test.go
#	x/poolmanager/router.go
#	x/poolmanager/router_test.go
#	x/poolmanager/taker_fee.go
#	x/poolmanager/types/expected_keepers.go
#	x/poolmanager/types/gov_test.go
#	x/poolmanager/types/msgs_test.go
#	x/poolmanager/types/params.go
#	x/protorev/client/cli/utils.go
#	x/protorev/keeper/developer_fees.go
#	x/protorev/keeper/developer_fees_test.go
#	x/protorev/keeper/emit.go
#	x/protorev/keeper/emit_test.go
#	x/protorev/keeper/epoch_hook_test.go
#	x/protorev/keeper/grpc_query_test.go
#	x/protorev/keeper/hooks.go
#	x/protorev/keeper/hooks_test.go
#	x/protorev/keeper/keeper_test.go
#	x/protorev/keeper/msg_server_test.go
#	x/protorev/keeper/posthandler_test.go
#	x/protorev/keeper/protorev_test.go
#	x/protorev/keeper/rebalance.go
#	x/protorev/keeper/rebalance_test.go
#	x/protorev/keeper/routes.go
#	x/protorev/keeper/routes_test.go
#	x/protorev/keeper/statistics.go
#	x/protorev/keeper/statistics_test.go
#	x/protorev/types/expected_keepers.go
#	x/protorev/types/msg_test.go
#	x/superfluid/client/cli/query_test.go
#	x/superfluid/keeper/concentrated_liquidity.go
#	x/superfluid/keeper/edge_case_test.go
#	x/superfluid/keeper/epoch.go
#	x/superfluid/keeper/epoch_test.go
#	x/superfluid/keeper/export_test.go
#	x/superfluid/keeper/genesis_test.go
#	x/superfluid/keeper/gov/gov_test.go
#	x/superfluid/keeper/grpc_query.go
#	x/superfluid/keeper/hooks.go
#	x/superfluid/keeper/hooks_test.go
#	x/superfluid/keeper/intermediary_account_test.go
#	x/superfluid/keeper/internal/events/emit_test.go
#	x/superfluid/keeper/invariants.go
#	x/superfluid/keeper/keeper_test.go
#	x/superfluid/keeper/msg_server_test.go
#	x/superfluid/keeper/stake_test.go
#	x/superfluid/keeper/superfluid_asset_test.go
#	x/superfluid/keeper/twap_price.go
#	x/superfluid/keeper/twap_price_test.go
#	x/superfluid/keeper/unpool_test.go
#	x/superfluid/simulation/genesis.go
#	x/superfluid/types/errors.go
#	x/superfluid/types/expected_keepers.go
#	x/superfluid/types/msg_test.go
#	x/tokenfactory/keeper/createdenom_test.go
#	x/tokenfactory/module.go
#	x/tokenfactory/types/msgs_test.go
#	x/twap/api.go
#	x/twap/client/query_proto_wrap_test.go
#	x/twap/listeners.go
#	x/twap/migrate_test.go
#	x/twap/store_test.go
#	x/twap/types/twapmock/amminterface.go
#	x/txfees/keeper/feedecorator.go
#	x/txfees/keeper/feedecorator_test.go
#	x/txfees/keeper/feetokens.go
#	x/txfees/keeper/hooks.go
#	x/txfees/keeper/hooks_test.go
#	x/txfees/keeper/keeper_test.go
#	x/txfees/types/expected_keepers.go
#	x/valset-pref/client/cli/query_test.go
#	x/valset-pref/export_test.go
#	x/valset-pref/keeper.go
#	x/valset-pref/keeper_test.go
#	x/valset-pref/msg_server_test.go
#	x/valset-pref/simulation/sim_msgs.go
#	x/valset-pref/types/expected_interfaces.go
#	x/valset-pref/types/msgs_test.go
#	x/valset-pref/validator_set_test.go
  • Loading branch information
p0mvn authored and mergify[bot] committed Sep 1, 2023
1 parent 5e781a8 commit 742a010
Show file tree
Hide file tree
Showing 415 changed files with 14,776 additions and 9,110 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ Fixes mainnet bugs w/ incorrect accumulation sumtrees, and CL handling for a bal

### API breaks

* [#6238](https://github.com/osmosis-labs/osmosis/pull/6238) switch osmomath to sdkmath types and rename BigDec constructors to contain "Big" in the name.
* Note: with the update, the Dec and Int do not get initialized to zero values
by default in proto marhaling/unmarshaling. Instead, they get set to nil values.
* maxDecBitLen has changed by one bit so overflow panic can be triggerred sooner.
* [#6071](https://github.com/osmosis-labs/osmosis/pull/6071) reduce number of returns for UpdatePosition and TicksToSqrtPrice functions

## v17.0.0
Expand All @@ -67,7 +71,7 @@ Fixes mainnet bugs w/ incorrect accumulation sumtrees, and CL handling for a bal
* [#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
* [#6033](https://github.com/osmosis-labs/osmosis/pull/6033) change tick API from sdk.Dec to osmomath.BigDec
* [#6033](https://github.com/osmosis-labs/osmosis/pull/6033) change tick API from osmomath.Dec to osmomath.BigDec

### Features

Expand Down
12 changes: 6 additions & 6 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,13 +219,13 @@ func TestGetPoolAssetsByDenom(t *testing.T) {
poolAssets: []balancer.PoolAsset {
{
Token: sdk.NewInt64Coin("uosmo", 1e12),
Weight: sdk.NewInt(100),
Weight: osmomath.NewInt(100),
},
},
expectedPoolAssetsByDenom: map[string]balancer.PoolAsset {
"uosmo": {
Token: sdk.NewInt64Coin("uosmo", 1e12),
Weight: sdk.NewInt(100),
Weight: osmomath.NewInt(100),
},
},
},
Expand All @@ -234,10 +234,10 @@ func TestGetPoolAssetsByDenom(t *testing.T) {
poolAssets: []balancer.PoolAsset {
{
Token: sdk.NewInt64Coin("uosmo", 1e12),
Weight: sdk.NewInt(100),
Weight: osmomath.NewInt(100),
}, {
Token: sdk.NewInt64Coin("uosmo", 123),
Weight: sdk.NewInt(400),
Weight: osmomath.NewInt(400),
},
},
err: fmt.Errorf(balancer.ErrMsgFormatRepeatingPoolAssetsNotAllowed, "uosmo"),
Expand Down Expand Up @@ -495,7 +495,7 @@ Additionally, this affects `LastResultsHash` because it contains a `Data` field
Version A
```go
func (sk Keeper) validateAmount(ctx context.Context, amount sdk.Int) error {
func (sk Keeper) validateAmount(ctx context.Context, amount osmomath.Int) error {
if amount.IsNegative() {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "amount must be positive or zero")
}
Expand All @@ -506,7 +506,7 @@ func (sk Keeper) validateAmount(ctx context.Context, amount sdk.Int) error {
Version B
```go
func (sk Keeper) validateAmount(ctx context.Context, amount sdk.Int) error {
func (sk Keeper) validateAmount(ctx context.Context, amount osmomath.Int) error {
if amount.IsNegative() || amount.IsZero() {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "amount must be positive")
}
Expand Down
31 changes: 19 additions & 12 deletions app/apptesting/concentrated_liquidity.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,15 @@ import (

sdk "github.com/cosmos/cosmos-sdk/types"

<<<<<<< HEAD
clmodel "github.com/osmosis-labs/osmosis/v18/x/concentrated-liquidity/model"
"github.com/osmosis-labs/osmosis/v18/x/concentrated-liquidity/types"
=======
"github.com/osmosis-labs/osmosis/osmomath"
clmodel "github.com/osmosis-labs/osmosis/v19/x/concentrated-liquidity/model"
"github.com/osmosis-labs/osmosis/v19/x/concentrated-liquidity/types"
poolmanagertypes "github.com/osmosis-labs/osmosis/v19/x/poolmanager/types"
>>>>>>> ca75f4c3 (refactor(deps): switch to cosmossdk.io/math from fork math (#6238))

cl "github.com/osmosis-labs/osmosis/v18/x/concentrated-liquidity"
)
Expand All @@ -18,24 +25,24 @@ var (
DefaultTickSpacing = uint64(100)
DefaultLowerTick = int64(30545000)
DefaultUpperTick = int64(31500000)
DefaultCoinAmount = sdk.NewInt(1000000000000000000)
DefaultCoinAmount = osmomath.NewInt(1000000000000000000)
)

// PrepareConcentratedPool sets up an eth usdc concentrated liquidity pool with a tick spacing of 100,
// no liquidity and zero spread factor.
func (s *KeeperTestHelper) PrepareConcentratedPool() types.ConcentratedPoolExtension {
return s.PrepareCustomConcentratedPool(s.TestAccs[0], ETH, USDC, DefaultTickSpacing, sdk.ZeroDec())
return s.PrepareCustomConcentratedPool(s.TestAccs[0], ETH, USDC, DefaultTickSpacing, osmomath.ZeroDec())
}

// PrepareConcentratedPoolWithCoins sets up a concentrated liquidity pool with custom denoms.
func (s *KeeperTestHelper) PrepareConcentratedPoolWithCoins(denom1, denom2 string) types.ConcentratedPoolExtension {
return s.PrepareCustomConcentratedPool(s.TestAccs[0], denom1, denom2, DefaultTickSpacing, sdk.ZeroDec())
return s.PrepareCustomConcentratedPool(s.TestAccs[0], denom1, denom2, DefaultTickSpacing, osmomath.ZeroDec())
}

// PrepareConcentratedPoolWithCoinsAndFullRangePosition sets up a concentrated liquidity pool with custom denoms.
// It also creates a full range position.
func (s *KeeperTestHelper) PrepareConcentratedPoolWithCoinsAndFullRangePosition(denom1, denom2 string) types.ConcentratedPoolExtension {
clPool := s.PrepareCustomConcentratedPool(s.TestAccs[0], denom1, denom2, DefaultTickSpacing, sdk.ZeroDec())
clPool := s.PrepareCustomConcentratedPool(s.TestAccs[0], denom1, denom2, DefaultTickSpacing, osmomath.ZeroDec())
fundCoins := sdk.NewCoins(sdk.NewCoin(denom1, DefaultCoinAmount), sdk.NewCoin(denom2, DefaultCoinAmount))
s.FundAcc(s.TestAccs[0], fundCoins)
s.CreateFullRangePosition(clPool, fundCoins)
Expand All @@ -44,14 +51,14 @@ func (s *KeeperTestHelper) PrepareConcentratedPoolWithCoinsAndFullRangePosition(

// createConcentratedPoolsFromCoinsWithSpreadFactor creates CL pools from given sets of coins and respective swap fees.
// Where element 1 of the input corresponds to the first pool created, element 2 to the second pool created etc.
func (s *KeeperTestHelper) CreateConcentratedPoolsAndFullRangePositionWithSpreadFactor(poolDenoms [][]string, spreadFactor []sdk.Dec) {
func (s *KeeperTestHelper) CreateConcentratedPoolsAndFullRangePositionWithSpreadFactor(poolDenoms [][]string, spreadFactor []osmomath.Dec) {
for i, curPoolDenoms := range poolDenoms {
s.Require().Equal(2, len(curPoolDenoms))
var curSpreadFactor sdk.Dec
var curSpreadFactor osmomath.Dec
if len(spreadFactor) > i {
curSpreadFactor = spreadFactor[i]
} else {
curSpreadFactor = sdk.ZeroDec()
curSpreadFactor = osmomath.ZeroDec()
}

clPool := s.PrepareCustomConcentratedPool(s.TestAccs[0], curPoolDenoms[0], curPoolDenoms[1], DefaultTickSpacing, curSpreadFactor)
Expand All @@ -64,13 +71,13 @@ func (s *KeeperTestHelper) CreateConcentratedPoolsAndFullRangePositionWithSpread
// createConcentratedPoolsFromCoins creates CL pools from given sets of coins (with zero swap fees).
// Where element 1 of the input corresponds to the first pool created, element 2 to the second pool created etc.
func (s *KeeperTestHelper) CreateConcentratedPoolsAndFullRangePosition(poolDenoms [][]string) {
s.CreateConcentratedPoolsAndFullRangePositionWithSpreadFactor(poolDenoms, []sdk.Dec{sdk.ZeroDec()})
s.CreateConcentratedPoolsAndFullRangePositionWithSpreadFactor(poolDenoms, []osmomath.Dec{osmomath.ZeroDec()})
}

// PrepareConcentratedPoolWithCoinsAndLockedFullRangePosition sets up a concentrated liquidity pool with custom denoms.
// It also creates a full range position and locks it for 14 days.
func (s *KeeperTestHelper) PrepareConcentratedPoolWithCoinsAndLockedFullRangePosition(denom1, denom2 string) (types.ConcentratedPoolExtension, uint64, uint64) {
clPool := s.PrepareCustomConcentratedPool(s.TestAccs[0], denom1, denom2, DefaultTickSpacing, sdk.ZeroDec())
clPool := s.PrepareCustomConcentratedPool(s.TestAccs[0], denom1, denom2, DefaultTickSpacing, osmomath.ZeroDec())
fundCoins := sdk.NewCoins(sdk.NewCoin(denom1, DefaultCoinAmount), sdk.NewCoin(denom2, DefaultCoinAmount))
s.FundAcc(s.TestAccs[0], fundCoins)
positionData, concentratedLockId, err := s.App.ConcentratedLiquidityKeeper.CreateFullRangePositionLocked(s.Ctx, clPool.GetId(), s.TestAccs[0], fundCoins, time.Hour*24*14)
Expand All @@ -81,7 +88,7 @@ func (s *KeeperTestHelper) PrepareConcentratedPoolWithCoinsAndLockedFullRangePos
}

// PrepareCustomConcentratedPool sets up a concentrated liquidity pool with the custom parameters.
func (s *KeeperTestHelper) PrepareCustomConcentratedPool(owner sdk.AccAddress, denom0, denom1 string, tickSpacing uint64, spreadFactor sdk.Dec) types.ConcentratedPoolExtension {
func (s *KeeperTestHelper) PrepareCustomConcentratedPool(owner sdk.AccAddress, denom0, denom1 string, tickSpacing uint64, spreadFactor osmomath.Dec) types.ConcentratedPoolExtension {
// Mint some assets to the account.
s.FundAcc(s.TestAccs[0], DefaultAcctFunds)

Expand Down Expand Up @@ -112,15 +119,15 @@ func (s *KeeperTestHelper) PrepareMultipleConcentratedPools(poolsToCreate uint16
}

// CreateFullRangePosition creates a full range position and returns position id and the liquidity created.
func (s *KeeperTestHelper) CreateFullRangePosition(pool types.ConcentratedPoolExtension, coins sdk.Coins) (uint64, sdk.Dec) {
func (s *KeeperTestHelper) CreateFullRangePosition(pool types.ConcentratedPoolExtension, coins sdk.Coins) (uint64, osmomath.Dec) {
s.FundAcc(s.TestAccs[0], coins)
positionData, err := s.App.ConcentratedLiquidityKeeper.CreateFullRangePosition(s.Ctx, pool.GetId(), s.TestAccs[0], coins)
s.Require().NoError(err)
return positionData.ID, positionData.Liquidity
}

// WithdrawFullRangePosition withdraws given liquidity from a position specified by id.
func (s *KeeperTestHelper) WithdrawFullRangePosition(pool types.ConcentratedPoolExtension, positionId uint64, liquidityToRemove sdk.Dec) {
func (s *KeeperTestHelper) WithdrawFullRangePosition(pool types.ConcentratedPoolExtension, positionId uint64, liquidityToRemove osmomath.Dec) {
clMsgServer := cl.NewMsgServerImpl(s.App.ConcentratedLiquidityKeeper)

_, err := clMsgServer.WithdrawPosition(sdk.WrapSDKContext(s.Ctx), &types.MsgWithdrawPosition{
Expand Down
Loading

0 comments on commit 742a010

Please sign in to comment.