Skip to content

Commit

Permalink
refactor: rename swap fee to spread factor (#5138)
Browse files Browse the repository at this point in the history
* refactor: rename swap fee to spread factor

* lint

* updates

* updates
  • Loading branch information
p0mvn authored and pysel committed Jun 6, 2023
1 parent c15e829 commit 3da305f
Show file tree
Hide file tree
Showing 118 changed files with 1,868 additions and 1,707 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* [#4868](https://github.com/osmosis-labs/osmosis/pull/4868) Remove wasmEnabledProposals []wasm.ProposalType from NewOsmosisApp
* [#4983](https://github.com/osmosis-labs/osmosis/pull/4983) Consume a gas when creating a new token using tokenfactory as a spam deterrence mechanism.
* [#4951](https://github.com/osmosis-labs/osmosis/pull/4951) Implement pool liquidity query in pool manager, deprecate the one in gamm
* [#5138](https://github.com/osmosis-labs/osmosis/pull/5138) Rename swap fee to spread factor. Broke PoolI interface. Did not break CLI, message, pool models, queries or events.


## v15.1.0
Expand Down Expand Up @@ -209,7 +210,7 @@ This release includes stableswap, and expands the IBC safety & composability fun

* Gamm:
* Introduction of the stableswap pool type
* Multi-hop swapfee reduction
* Multi-hop spread factor reduction
* Filtered queries to help front-ends
* Adding a spot price v2 query
* spotprice v1beta1 had baseassetdenom and quoteassetdenom backwards.
Expand Down
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -475,8 +475,9 @@ cl-create-bigbang-config:
### Go Mock ###
###############################################################################

go-mock-update-pool-module:
go-mock-update:
mockgen -source=x/poolmanager/types/routes.go -destination=tests/mocks/pool_module.go -package=mocks
mockgen -source=x/poolmanager/types/pool.go -destination=tests/mocks/pool.go -package=mocks

.PHONY: all build-linux install format lint \
go-mod-cache draw-deps clean build build-contract-tests-hooks \
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ swap-type use cases. Bonding curves, while have found its primary use
case in decentralized exchange mechanisms, its potential use case can be
further extended through the customizability that Osmosis offers.
Through the customizability offered by Osmosis such as custom-curve AMMs,
dynamic adjustments of swap fees, multi-token liquidity pools--the AMM
dynamic adjustments of spread factors, multi-token liquidity pools--the AMM
can offer decentralized formation of token fundraisers, interchain
staking, options market, and more for the Cosmos ecosystem.

Expand Down
22 changes: 11 additions & 11 deletions app/apptesting/concentrated_liquidity.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var (
)

// PrepareConcentratedPool sets up an eth usdc concentrated liquidity pool with pool ID 1, tick spacing of 100,
// no liquidity and zero swap fee.
// no liquidity and zero spread factor.
func (s *KeeperTestHelper) PrepareConcentratedPool() types.ConcentratedPoolExtension {
return s.PrepareCustomConcentratedPool(s.TestAccs[0], ETH, USDC, DefaultTickSpacing, sdk.ZeroDec())
}
Expand All @@ -41,19 +41,19 @@ func (s *KeeperTestHelper) PrepareConcentratedPoolWithCoinsAndFullRangePosition(
return clPool
}

// createConcentratedPoolsFromCoinsWithSwapFee creates CL pools from given sets of coins and respective swap fees.
// 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) CreateConcentratedPoolsAndFullRangePositionWithSwapFee(poolDenoms [][]string, swapFee []sdk.Dec) {
func (s *KeeperTestHelper) CreateConcentratedPoolsAndFullRangePositionWithSpreadFactor(poolDenoms [][]string, spreadFactor []sdk.Dec) {
for i, curPoolDenoms := range poolDenoms {
s.Require().Equal(2, len(curPoolDenoms))
var curSwapFee sdk.Dec
if len(swapFee) > i {
curSwapFee = swapFee[i]
var curSpreadFactor sdk.Dec
if len(spreadFactor) > i {
curSpreadFactor = spreadFactor[i]
} else {
curSwapFee = sdk.ZeroDec()
curSpreadFactor = sdk.ZeroDec()
}

clPool := s.PrepareCustomConcentratedPool(s.TestAccs[0], curPoolDenoms[0], curPoolDenoms[1], DefaultTickSpacing, curSwapFee)
clPool := s.PrepareCustomConcentratedPool(s.TestAccs[0], curPoolDenoms[0], curPoolDenoms[1], DefaultTickSpacing, curSpreadFactor)
fundCoins := sdk.NewCoins(sdk.NewCoin(curPoolDenoms[0], DefaultCoinAmount), sdk.NewCoin(curPoolDenoms[1], DefaultCoinAmount))
s.FundAcc(s.TestAccs[0], fundCoins)
s.CreateFullRangePosition(clPool, fundCoins)
Expand All @@ -63,7 +63,7 @@ func (s *KeeperTestHelper) CreateConcentratedPoolsAndFullRangePositionWithSwapFe
// 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.CreateConcentratedPoolsAndFullRangePositionWithSwapFee(poolDenoms, []sdk.Dec{sdk.ZeroDec()})
s.CreateConcentratedPoolsAndFullRangePositionWithSpreadFactor(poolDenoms, []sdk.Dec{sdk.ZeroDec()})
}

// PrepareConcentratedPoolWithCoinsAndLockedFullRangePosition sets up a concentrated liquidity pool with custom denoms.
Expand All @@ -80,12 +80,12 @@ 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, swapFee sdk.Dec) types.ConcentratedPoolExtension {
func (s *KeeperTestHelper) PrepareCustomConcentratedPool(owner sdk.AccAddress, denom0, denom1 string, tickSpacing uint64, spreadFactor sdk.Dec) types.ConcentratedPoolExtension {
// Mint some assets to the account.
s.FundAcc(s.TestAccs[0], DefaultAcctFunds)

// Create a concentrated pool via the poolmanager
poolID, err := s.App.PoolManagerKeeper.CreatePool(s.Ctx, clmodel.NewMsgCreateConcentratedPool(owner, denom0, denom1, tickSpacing, swapFee))
poolID, err := s.App.PoolManagerKeeper.CreatePool(s.Ctx, clmodel.NewMsgCreateConcentratedPool(owner, denom0, denom1, tickSpacing, spreadFactor))
s.Require().NoError(err)

// Retrieve the poolInterface via the poolID
Expand Down
4 changes: 2 additions & 2 deletions app/apptesting/gamm.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,8 @@ func (s *KeeperTestHelper) ModifySpotPrice(poolID uint64, targetSpotPrice sdk.De
s.Require().NoError(err)
} else {
swapOut := sdk.NewCoins(sdk.NewCoin(quoteDenom, sdk.NewInt(amountTrade.RoundInt64()).Abs()))
swapFee := pool.GetSwapFee(s.Ctx)
tokenIn, err := pool.CalcInAmtGivenOut(s.Ctx, swapOut, baseDenom, swapFee)
spreadFactor := pool.GetSpreadFactor(s.Ctx)
tokenIn, err := pool.CalcInAmtGivenOut(s.Ctx, swapOut, baseDenom, spreadFactor)
s.Require().NoError(err)
s.FundAcc(s.TestAccs[0], sdk.NewCoins(tokenIn))
msg := gammtypes.MsgSwapExactAmountOut{
Expand Down
4 changes: 2 additions & 2 deletions app/upgrades/v15/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,13 @@ func (suite *UpgradeTestSuite) TestMigrateBalancerToStablePools() {
suite.FundAcc(testAccount, DefaultAcctFunds)

// Create the balancer pool
swapFee := sdk.MustNewDecFromStr("0.003")
spreadFactor := sdk.MustNewDecFromStr("0.003")
exitFee := sdk.ZeroDec()
poolID, err := suite.App.PoolManagerKeeper.CreatePool(
suite.Ctx,
balancer.NewMsgCreateBalancerPool(suite.TestAccs[0],
balancer.PoolParams{
SwapFee: swapFee,
SwapFee: spreadFactor,
ExitFee: exitFee,
},
[]balancer.PoolAsset{
Expand Down
2 changes: 1 addition & 1 deletion app/upgrades/v15/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func migrateBalancerPoolToSolidlyStable(ctx sdk.Context, gammKeeper *gammkeeper.
// initialize the stableswap pool
stableswapPool, err := stableswap.NewStableswapPool(
poolId,
stableswap.PoolParams{SwapFee: balancerPool.GetSwapFee(ctx), ExitFee: balancerPool.GetExitFee(ctx)},
stableswap.PoolParams{SwapFee: balancerPool.GetSpreadFactor(ctx), ExitFee: balancerPool.GetExitFee(ctx)},
balancerPoolLiquidity,
[]uint64{1, 1},
"osmo1k8c2m5cn322akk5wy8lpt87dd2f4yh9afcd7af", // Stride Foundation 2/3 multisig
Expand Down
6 changes: 3 additions & 3 deletions app/upgrades/v16/concentrated_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ func createConcentratedPoolFromCFMM(ctx sdk.Context, cfmmPoolIdToLinkWith uint64
return nil, NoDesiredDenomInPoolError{desiredDenom0}
}

// Swap fee is 0.2%, which is an authorized swap fee.
swapFee := cfmmPool.GetSwapFee(ctx)
// Swap fee is 0.2%, which is an authorized spread factor.
spreadFactor := cfmmPool.GetSpreadFactor(ctx)

createPoolMsg := clmodel.NewMsgCreateConcentratedPool(poolCreatorAddress, desiredDenom0, denom1, TickSpacing, swapFee)
createPoolMsg := clmodel.NewMsgCreateConcentratedPool(poolCreatorAddress, desiredDenom0, denom1, TickSpacing, spreadFactor)
concentratedPool, err := poolmanagerKeeper.CreateConcentratedPoolAsPoolManager(ctx, createPoolMsg)
if err != nil {
return nil, err
Expand Down
4 changes: 2 additions & 2 deletions app/upgrades/v16/concentrated_pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ func (suite *ConcentratedUpgradeTestSuite) TestCreateConcentratedPoolFromCFMM()
suite.Require().NoError(err)
suite.Require().Equal(clPoolReturned, clPoolInState)

// Validate CL and balancer pools have the same swap fee.
suite.Require().Equal(balancerPool.GetSwapFee(suite.Ctx), clPoolReturned.GetSwapFee(suite.Ctx))
// Validate CL and balancer pools have the same spread factor.
suite.Require().Equal(balancerPool.GetSpreadFactor(suite.Ctx), clPoolReturned.GetSpreadFactor(suite.Ctx))

// Validate that CL and balancer pools have the same denoms
balancerDenoms, err := suite.App.PoolManagerKeeper.RouteGetPoolDenoms(suite.Ctx, balancerPool.GetId())
Expand Down
2 changes: 1 addition & 1 deletion app/upgrades/v16/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const (
// DAI/OSMO pool ID
// https://app.osmosis.zone/pool/674
// Note, new concentrated liquidity pool
// swap fee is initialized to be the same as the balancers pool swap fee of 0.2%.
// spread factor is initialized to be the same as the balancers pool spread factor of 0.2%.
DaiOsmoPoolId = uint64(674)
// Denom0 translates to a base asset while denom1 to a quote asset
// We want quote asset to be DAI so that when the limit orders on ticks
Expand Down
2 changes: 1 addition & 1 deletion app/upgrades/v9/prop214.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
// Executes prop214, https://www.mintscan.io/osmosis/proposals/214
// Run `osmosisd q gov proposal 214` to see the text.
// It was voted in, and it has update instructions:
// Voting YES for this proposal would reduce the Pool 1 (OSMO/ATOM) swap fee from 0.3% to 0.2%
// Voting YES for this proposal would reduce the Pool 1 (OSMO/ATOM) spread factor from 0.3% to 0.2%
func ExecuteProp214(ctx sdk.Context, gamm *gammkeeper.Keeper) {
poolId := 1
pool, err := gamm.GetPoolAndPoke(ctx, uint64(poolId))
Expand Down
6 changes: 3 additions & 3 deletions app/upgrades/v9/prop214_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ func (suite *UpgradeTestSuite) TestProp214() {
suite.Require().NoError(err)

// Kept as comments for recordkeeping. Since SetPool is now private, the changes being tested for can no longer be made:
// swapFee := pool.GetSwapFee(suite.Ctx)
// expectedSwapFee := sdk.MustNewDecFromStr("0.002")
// spreadFactor := pool.GetSpreadFactor(suite.Ctx)
// expectedSpreadFactor := sdk.MustNewDecFromStr("0.002")
//
// suite.Require().Equal(expectedSwapFee, swapFee)
// suite.Require().Equal(expectedSpreadFactor, spreadFactor)
}
4 changes: 2 additions & 2 deletions proto/osmosis/concentrated-liquidity/gov.proto
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ message CreateConcentratedLiquidityPoolProposal {
(gogoproto.moretags) = "yaml:\"exponent_at_price_one\"",
(gogoproto.nullable) = false
];
string swap_fee = 7 [
string spread_factor = 7 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.moretags) = "yaml:\"swap_fee\"",
(gogoproto.moretags) = "yaml:\"spread_factor\"",
(gogoproto.nullable) = false
];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ message IncentiveRecordBody {
// emission_rate is the incentive emission rate per second
string emission_rate = 2 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.moretags) = "yaml:\"swap_fee\"",
(gogoproto.moretags) = "yaml:\"emission_rate\"",
(gogoproto.nullable) = false
];

Expand Down
4 changes: 2 additions & 2 deletions proto/osmosis/concentrated-liquidity/params.proto
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ message Params {
// to be created with tick spacing of 1, 10, or 30.
repeated uint64 authorized_tick_spacing = 1
[ (gogoproto.moretags) = "yaml:\"authorized_tick_spacing\"" ];
repeated string authorized_swap_fees = 2 [
repeated string authorized_spread_factors = 2 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.moretags) = "yaml:\"authorized_swap_fees\"",
(gogoproto.moretags) = "yaml:\"authorized_spread_factors\"",
(gogoproto.nullable) = false
];
// balancer_shares_reward_discount is the rate by which incentives flowing
Expand Down
4 changes: 2 additions & 2 deletions proto/osmosis/concentrated-liquidity/pool-model/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ message MsgCreateConcentratedPool {
string denom0 = 2 [ (gogoproto.moretags) = "yaml:\"denom0\"" ];
string denom1 = 3 [ (gogoproto.moretags) = "yaml:\"denom1\"" ];
uint64 tick_spacing = 4 [ (gogoproto.moretags) = "yaml:\"tick_spacing\"" ];
string swap_fee = 5 [
string spread_factor = 5 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.moretags) = "yaml:\"swap_fee\"",
(gogoproto.moretags) = "yaml:\"spread_factor\"",
(gogoproto.nullable) = false
];
}
Expand Down
6 changes: 3 additions & 3 deletions proto/osmosis/concentrated-liquidity/pool.proto
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ message Pool {
int64 exponent_at_price_one = 11
[ (gogoproto.moretags) = "yaml:\"exponent_at_price_one\"" ];

// swap_fee is the ratio that is charged on the amount of token in.
string swap_fee = 12 [
// spread_factor is the ratio that is charged on the amount of token in.
string spread_factor = 12 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.moretags) = "yaml:\"swap_fee\"",
(gogoproto.moretags) = "yaml:\"spread_factor\"",
(gogoproto.nullable) = false
];

Expand Down
Loading

0 comments on commit 3da305f

Please sign in to comment.