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

feat: exempt UnrestrictedPoolCreatorWhitelist addresses from pool creation fee #8609

Merged
merged 2 commits into from
Aug 13, 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
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* [#8535](https://github.com/osmosis-labs/osmosis/pull/8535) Prevent Setting Invalid Before Send Hook
* [#8310](https://github.com/osmosis-labs/osmosis/pull/8310) Taker fee share
* [#8494](https://github.com/osmosis-labs/osmosis/pull/8494) Add additional events in x/lockup, x/superfluid, x/concentratedliquidity
* [#8581](https://github.com/osmosis-labs/osmosis/pull/8581) feat: add ledger signing to smart account module
* [#8573](https://github.com/osmosis-labs/osmosis/pull/8573) fix: increase unauthenticated gas to fix fee token issue
* [#8581](https://github.com/osmosis-labs/osmosis/pull/8581) Add ledger signing to smart account module
* [#8573](https://github.com/osmosis-labs/osmosis/pull/8573) Increase unauthenticated gas to fix fee token issue
* [#8609](https://github.com/osmosis-labs/osmosis/pull/8609) Exempt `UnrestrictedPoolCreatorWhitelist` addresses from pool creation fee

### Config

Expand Down
4 changes: 4 additions & 0 deletions x/concentrated-liquidity/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,7 @@ func (k Keeper) SetAuthorizedQuoteDenoms(ctx sdk.Context, authorizedQuoteDenoms
params.AuthorizedQuoteDenoms = authorizedQuoteDenoms
k.poolmanagerKeeper.SetParams(ctx, params)
}

func (k Keeper) GetWhitelistedAddresses(ctx sdk.Context) []string {
return k.GetParams(ctx).UnrestrictedPoolCreatorWhitelist
}
31 changes: 28 additions & 3 deletions x/poolmanager/create_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,9 @@ func (k Keeper) CreatePool(ctx sdk.Context, msg types.CreatePoolMsg) (uint64, er
return 0, err
}

// Send pool creation fee from pool creator to community pool
poolCreationFee := k.GetParams(ctx).PoolCreationFee
sender := msg.PoolCreator()
if err := k.communityPoolKeeper.FundCommunityPool(ctx, poolCreationFee, sender); err != nil {
err = k.fundCommunityPoolIfNotWhitelisted(ctx, sender)
if err != nil {
return 0, err
}

Expand Down Expand Up @@ -249,3 +248,29 @@ func parsePoolRouteWithKey(key []byte, value []byte) (types.ModuleRoute, error)
parsedValue.PoolId = poolId
return parsedValue, nil
}

// fundCommunityPoolIfNotWhitelisted checks if the sender is in the UnrestrictedPoolCreatorWhitelist
// and funds the community pool if the sender is not whitelisted.
func (k Keeper) fundCommunityPoolIfNotWhitelisted(ctx sdk.Context, sender sdk.AccAddress) error {
// Get the UnrestrictedPoolCreatorWhitelist from the concentrated pool module
whitelist := k.concentratedKeeper.GetWhitelistedAddresses(ctx)

// Check if sender is in the whitelist
isWhitelisted := false
for _, addr := range whitelist {
if addr == sender.String() {
isWhitelisted = true
break
}
}

// Run FundCommunityPool logic if sender is not in the whitelist
if !isWhitelisted {
poolCreationFee := k.GetParams(ctx).PoolCreationFee
if err := k.communityPoolKeeper.FundCommunityPool(ctx, poolCreationFee, sender); err != nil {
return err
}
}

return nil
}
4 changes: 4 additions & 0 deletions x/poolmanager/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,7 @@ func (k *Keeper) SetCacheTrackers(takerFeeShareAgreement map[string]types.TakerF
k.cachedRegisteredAlloyPoolByAlloyDenomMap = registeredAlloyPoolToState
}
}

func (k Keeper) FundCommunityPoolIfNotWhitelisted(ctx sdk.Context, sender sdk.AccAddress) error {
return k.fundCommunityPoolIfNotWhitelisted(ctx, sender)
}
4 changes: 2 additions & 2 deletions x/poolmanager/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type Keeper struct {
storeKey storetypes.StoreKey

gammKeeper types.PoolModuleI
concentratedKeeper types.PoolModuleI
concentratedKeeper types.ConcentratedI
cosmwasmpoolKeeper types.PoolModuleI
poolIncentivesKeeper types.PoolIncentivesKeeperI
bankKeeper types.BankI
Expand Down Expand Up @@ -52,7 +52,7 @@ type Keeper struct {
cachedRegisteredAlloyPoolByAlloyDenomMap map[string]types.AlloyContractTakerFeeShareState
}

func NewKeeper(storeKey storetypes.StoreKey, paramSpace paramtypes.Subspace, gammKeeper types.PoolModuleI, concentratedKeeper types.PoolModuleI, cosmwasmpoolKeeper types.PoolModuleI, bankKeeper types.BankI, accountKeeper types.AccountI, communityPoolKeeper types.CommunityPoolI, stakingKeeper types.StakingKeeper, protorevKeeper types.ProtorevKeeper, wasmKeeper types.WasmKeeper) *Keeper {
func NewKeeper(storeKey storetypes.StoreKey, paramSpace paramtypes.Subspace, gammKeeper types.PoolModuleI, concentratedKeeper types.ConcentratedI, cosmwasmpoolKeeper types.PoolModuleI, bankKeeper types.BankI, accountKeeper types.AccountI, communityPoolKeeper types.CommunityPoolI, stakingKeeper types.StakingKeeper, protorevKeeper types.ProtorevKeeper, wasmKeeper types.WasmKeeper) *Keeper {
// set KeyTable if it has not already been set
if !paramSpace.HasKeyTable() {
paramSpace = paramSpace.WithKeyTable(types.ParamKeyTable())
Expand Down
59 changes: 59 additions & 0 deletions x/poolmanager/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (

"github.com/cosmos/gogoproto/proto"

distributiontypes "github.com/cosmos/cosmos-sdk/x/distribution/types"

"github.com/osmosis-labs/osmosis/osmomath"
"github.com/osmosis-labs/osmosis/v25/app/apptesting"
appparams "github.com/osmosis-labs/osmosis/v25/app/params"
Expand Down Expand Up @@ -432,3 +434,60 @@ func (s *KeeperTestSuite) TestEndBlock() {
})
}
}

func (s *KeeperTestSuite) TestFundCommunityPoolIfNotWhitelisted() {
tests := []struct {
name string
whitelist []string
sender sdk.AccAddress
expectFundCall bool
}{
{
name: "sender is whitelisted",
whitelist: []string{"osmo1044qatzg4a0wm63jchrfdnn2u8nwdgxxt6e524"},
sender: sdk.MustAccAddressFromBech32("osmo1044qatzg4a0wm63jchrfdnn2u8nwdgxxt6e524"),
expectFundCall: false,
},
{
name: "sender is not whitelisted",
whitelist: []string{"osmo1044qatzg4a0wm63jchrfdnn2u8nwdgxxt6e524"},
sender: sdk.MustAccAddressFromBech32("osmo1j537vtv60wz322n2sgfm4st7y3dm8e4e9js57h"),
expectFundCall: true,
},
{
name: "whitelist is empty",
whitelist: []string{},
sender: sdk.MustAccAddressFromBech32("osmo1j537vtv60wz322n2sgfm4st7y3dm8e4e9js57h"),
expectFundCall: true,
},
}

for _, tc := range tests {
s.Run(tc.name, func() {
s.SetupTest()

oldParams := s.App.ConcentratedLiquidityKeeper.GetParams(s.Ctx)
oldParams.UnrestrictedPoolCreatorWhitelist = tc.whitelist
s.App.ConcentratedLiquidityKeeper.SetParams(s.Ctx, oldParams)

// Fund the sender with pool creation fee
poolCreationFee := s.App.PoolManagerKeeper.GetParams(s.Ctx).PoolCreationFee
s.FundAcc(tc.sender, poolCreationFee)

// Get the community pool balance
preCommunityPoolBalance := s.App.BankKeeper.GetAllBalances(s.Ctx, s.App.AccountKeeper.GetModuleAddress(distributiontypes.ModuleName))

err := s.App.PoolManagerKeeper.FundCommunityPoolIfNotWhitelisted(s.Ctx, tc.sender)
s.Require().NoError(err)

// Get the community pool balance after the function call
postCommunityPoolBalance := s.App.BankKeeper.GetAllBalances(s.Ctx, s.App.AccountKeeper.GetModuleAddress(distributiontypes.ModuleName))

if tc.expectFundCall {
s.Require().Equal(postCommunityPoolBalance, preCommunityPoolBalance.Add(poolCreationFee...))
} else {
s.Require().Equal(preCommunityPoolBalance, postCommunityPoolBalance)
}
})
}
}
5 changes: 5 additions & 0 deletions x/poolmanager/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ type PoolModuleI interface {
GetTotalLiquidity(ctx sdk.Context) (sdk.Coins, error)
}

type ConcentratedI interface {
PoolModuleI
GetWhitelistedAddresses(ctx sdk.Context) []string
}

type PoolIncentivesKeeperI interface {
IsPoolIncentivized(ctx sdk.Context, poolId uint64) (bool, error)
}
Expand Down