Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support CL pools in TX Fee module #7267

Merged
merged 2 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* [#7233](https://github.com/osmosis-labs/osmosis/pull/7233) fix: config overwrite ignores app.toml values
* [#7243](https://github.com/osmosis-labs/osmosis/pull/7243) fix: chore: update gov metadata length from 256 to 10200
* [#7246](https://github.com/osmosis-labs/osmosis/pull/7246) fix: config overwrite fails with exit code 1 if wrong permissions
* [#7267](https://github.com/osmosis-labs/osmosis/pull/7267) fix: support CL pools in tx fee module

## v21.1.5

Expand Down
1 change: 0 additions & 1 deletion app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,6 @@ func (appKeepers *AppKeepers) InitNormalKeepers(
appKeepers.BankKeeper,
appKeepers.keys[txfeestypes.StoreKey],
appKeepers.PoolManagerKeeper,
appKeepers.GAMMKeeper,
appKeepers.ProtoRevKeeper,
appKeepers.DistrKeeper,
dataDir,
Expand Down
4 changes: 2 additions & 2 deletions x/txfees/keeper/feetokens.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (k Keeper) CalcFeeSpotPrice(ctx sdk.Context, inputDenom string) (osmomath.B
return osmomath.BigDec{}, err
}

spotPrice, err := k.spotPriceCalculator.CalculateSpotPrice(ctx, feeToken.PoolID, baseDenom, feeToken.Denom)
spotPrice, err := k.poolManager.RouteCalculateSpotPrice(ctx, feeToken.PoolID, baseDenom, feeToken.Denom)
if err != nil {
return osmomath.BigDec{}, err
}
Expand Down Expand Up @@ -105,7 +105,7 @@ func (k Keeper) ValidateFeeToken(ctx sdk.Context, feeToken types.FeeToken) error
// - feeToken.Denom exists
// - feeToken.PoolID exists
// - feeToken.PoolID has both feeToken.Denom and baseDenom
_, err = k.spotPriceCalculator.CalculateSpotPrice(ctx, feeToken.PoolID, feeToken.Denom, baseDenom)
_, err = k.poolManager.RouteCalculateSpotPrice(ctx, feeToken.PoolID, feeToken.Denom, baseDenom)

return err
}
Expand Down
58 changes: 57 additions & 1 deletion x/txfees/keeper/feetokens_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package keeper_test

import (
"github.com/osmosis-labs/osmosis/osmomath"
"github.com/osmosis-labs/osmosis/v21/x/txfees/types"

sdk "github.com/cosmos/cosmos-sdk/types"
Expand All @@ -19,6 +20,61 @@ func (s *KeeperTestSuite) TestBaseDenom() {
s.Require().NoError(err)
}

func (s *KeeperTestSuite) TestCalcFeeSpotPrice() {
s.SetupTest(false)

tests := []struct {
name string
inputDenom string
expectPass bool
expectedSp osmomath.BigDec
}{
{
"calc spot price from balancer pool",
"foo",
true,
osmomath.NewBigDec(1),
},
{
"calc spot price from cl pool",
"eth",
true,
osmomath.NewBigDec(1),
},
{
"invalid denom",
"invalid-denom",
false,
osmomath.BigDec{},
},
}

for _, tc := range tests {
// we set up two pools here, one Balancer pool, one CL Pool
// then use different denoms for each pool to test
balancerPoolId := s.PrepareBalancerPoolWithCoins(
sdk.NewCoin("foo", osmomath.NewInt(10000000)),
sdk.NewCoin("stake", osmomath.NewInt(10000000)),
)
clPool := s.PrepareConcentratedPoolWithCoinsAndFullRangePosition("eth", "stake")
clPoolId := clPool.GetId()

// register both denoms
err := s.ExecuteUpgradeFeeTokenProposal("foo", balancerPoolId)
s.Require().NoError(err)
err = s.ExecuteUpgradeFeeTokenProposal("eth", clPoolId)
s.Require().NoError(err)

sp, err := s.App.TxFeesKeeper.CalcFeeSpotPrice(s.Ctx, tc.inputDenom)
if tc.expectPass {
s.Require().NoError(err)
s.Require().True(sp.Equal(tc.expectedSp))
} else {
s.Require().Error(err)
}
}
}

func (s *KeeperTestSuite) TestUpgradeFeeTokenProposals() {
s.SetupTest(false)

Expand Down Expand Up @@ -65,7 +121,7 @@ func (s *KeeperTestSuite) TestUpgradeFeeTokenProposals() {
{
name: "proposal with non-existent pool",
feeToken: "foo",
poolId: 100000000000,
poolId: 10000000,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this changed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in pool manager keeper we only use 12 bytes for storing pool id, this requires 13 bytes & causes panic in tests thus needs to be lowered!

expectPass: false,
},
{
Expand Down
29 changes: 13 additions & 16 deletions x/txfees/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@ import (
type Keeper struct {
storeKey storetypes.StoreKey

accountKeeper types.AccountKeeper
bankKeeper types.BankKeeper
poolManager types.PoolManager
spotPriceCalculator types.SpotPriceCalculator
protorevKeeper types.ProtorevKeeper
distributionKeeper types.DistributionKeeper
dataDir string
accountKeeper types.AccountKeeper
bankKeeper types.BankKeeper
poolManager types.PoolManager
protorevKeeper types.ProtorevKeeper
distributionKeeper types.DistributionKeeper
dataDir string
}

var _ types.TxFeesKeeper = (*Keeper)(nil)
Expand All @@ -32,20 +31,18 @@ func NewKeeper(
bankKeeper types.BankKeeper,
storeKey storetypes.StoreKey,
poolManager types.PoolManager,
spotPriceCalculator types.SpotPriceCalculator,
protorevKeeper types.ProtorevKeeper,
distributionKeeper types.DistributionKeeper,
dataDir string,
) Keeper {
return Keeper{
accountKeeper: accountKeeper,
bankKeeper: bankKeeper,
storeKey: storeKey,
poolManager: poolManager,
spotPriceCalculator: spotPriceCalculator,
protorevKeeper: protorevKeeper,
distributionKeeper: distributionKeeper,
dataDir: dataDir,
accountKeeper: accountKeeper,
bankKeeper: bankKeeper,
storeKey: storeKey,
poolManager: poolManager,
protorevKeeper: protorevKeeper,
distributionKeeper: distributionKeeper,
dataDir: dataDir,
}
}

Expand Down
7 changes: 7 additions & 0 deletions x/txfees/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ type PoolManager interface {
) (osmomath.Int, error)

GetParams(ctx sdk.Context) (params poolmanagertypes.Params)

RouteCalculateSpotPrice(
ctx sdk.Context,
poolId uint64,
quoteAssetDenom string,
baseAssetDenom string,
) (price osmomath.BigDec, err error)
}

// AccountKeeper defines the contract needed for AccountKeeper related APIs.
Expand Down