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(spike): taker fee (backport #6034) #6212

Merged
merged 8 commits into from
Aug 29, 2023
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
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ jobs:
needs: get_diff
if: needs.get_diff.outputs.git_diff
runs-on: self-hosted
timeout-minutes: 25
timeout-minutes: 20
steps:
- name: Clean up Pre-Existing E2E Docker containers
run: |
Expand Down
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## v18.0.0

<<<<<<< HEAD
=======
### Misc Improvements

* [#6161](https://github.com/osmosis-labs/osmosis/pull/6161) Reduce CPU time of epochs

### Bug Fixes

* [#6162](https://github.com/osmosis-labs/osmosis/pull/6162) allow zero qualifying balancer shares in CL incentives

### Features

* [#6034](https://github.com/osmosis-labs/osmosis/pull/6034) feat(spike): taker fee
## v18.0.0

>>>>>>> 5c8fd80f (feat(spike): taker fee (#6034))
Fixes mainnet bugs w/ incorrect accumulation sumtrees, and CL handling for a balancer pool with 0 bonded shares.

### Improvements
Expand Down
6 changes: 5 additions & 1 deletion app/apptesting/concentrated_liquidity.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

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"

cl "github.com/osmosis-labs/osmosis/v19/x/concentrated-liquidity"
)
Expand Down Expand Up @@ -139,6 +140,9 @@ func (s *KeeperTestHelper) SetupConcentratedLiquidityDenomsAndPoolCreation() {
// modify authorized quote denoms to include test denoms.
defaultParams := types.DefaultParams()
defaultParams.IsPermissionlessPoolCreationEnabled = true
defaultParams.AuthorizedQuoteDenoms = append(defaultParams.AuthorizedQuoteDenoms, ETH, USDC, BAR, BAZ, FOO, UOSMO, STAKE, WBTC)
s.App.ConcentratedLiquidityKeeper.SetParams(s.Ctx, defaultParams)

poolManagerParams := s.App.PoolManagerKeeper.GetParams(s.Ctx)
poolManagerParams.AuthorizedQuoteDenoms = append(poolmanagertypes.DefaultParams().AuthorizedQuoteDenoms, ETH, USDC, BAR, BAZ, FOO, UOSMO, STAKE, WBTC)
s.App.PoolManagerKeeper.SetParams(s.Ctx, poolManagerParams)
}
50 changes: 25 additions & 25 deletions app/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,31 +98,31 @@ import (
// moduleAccountPermissions defines module account permissions
// TODO: Having to input nil's here is unacceptable, we need a way to automatically derive this.
var moduleAccountPermissions = map[string][]string{
authtypes.FeeCollectorName: nil,
distrtypes.ModuleName: nil,
ibchookstypes.ModuleName: nil,
icatypes.ModuleName: nil,
icqtypes.ModuleName: nil,
minttypes.ModuleName: {authtypes.Minter, authtypes.Burner},
minttypes.DeveloperVestingModuleAcctName: nil,
stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking},
stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking},
govtypes.ModuleName: {authtypes.Burner},
ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
gammtypes.ModuleName: {authtypes.Minter, authtypes.Burner},
incentivestypes.ModuleName: {authtypes.Minter, authtypes.Burner},
protorevtypes.ModuleName: {authtypes.Minter, authtypes.Burner},
lockuptypes.ModuleName: {authtypes.Minter, authtypes.Burner},
poolincentivestypes.ModuleName: nil,
superfluidtypes.ModuleName: {authtypes.Minter, authtypes.Burner},
txfeestypes.ModuleName: nil,
txfeestypes.NonNativeFeeCollectorForStakingRewardsName: nil,
txfeestypes.NonNativeFeeCollectorForCommunityPoolName: nil,
wasm.ModuleName: {authtypes.Burner},
tokenfactorytypes.ModuleName: {authtypes.Minter, authtypes.Burner},
valsetpreftypes.ModuleName: {authtypes.Staking},
poolmanagertypes.ModuleName: nil,
cosmwasmpooltypes.ModuleName: nil,
authtypes.FeeCollectorName: nil,
distrtypes.ModuleName: nil,
ibchookstypes.ModuleName: nil,
icatypes.ModuleName: nil,
icqtypes.ModuleName: nil,
minttypes.ModuleName: {authtypes.Minter, authtypes.Burner},
minttypes.DeveloperVestingModuleAcctName: nil,
stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking},
stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking},
govtypes.ModuleName: {authtypes.Burner},
ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
gammtypes.ModuleName: {authtypes.Minter, authtypes.Burner},
incentivestypes.ModuleName: {authtypes.Minter, authtypes.Burner},
protorevtypes.ModuleName: {authtypes.Minter, authtypes.Burner},
lockuptypes.ModuleName: {authtypes.Minter, authtypes.Burner},
poolincentivestypes.ModuleName: nil,
superfluidtypes.ModuleName: {authtypes.Minter, authtypes.Burner},
txfeestypes.ModuleName: nil,
txfeestypes.FeeCollectorForStakingRewardsName: nil,
txfeestypes.FeeCollectorForCommunityPoolName: nil,
wasm.ModuleName: {authtypes.Burner},
tokenfactorytypes.ModuleName: {authtypes.Minter, authtypes.Burner},
valsetpreftypes.ModuleName: {authtypes.Staking},
poolmanagertypes.ModuleName: nil,
cosmwasmpooltypes.ModuleName: nil,
}

// appModules return modules to initialize module manager.
Expand Down
3 changes: 2 additions & 1 deletion app/upgrades/v15/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ func CreateUpgradeHandler(
keepers *keepers.AppKeepers,
) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
poolmanagerParams := poolmanagertypes.NewParams(keepers.GAMMKeeper.GetParams(ctx).PoolCreationFee)
poolmanagerParams := keepers.PoolManagerKeeper.GetParams(ctx)
poolmanagerParams.PoolCreationFee = keepers.GAMMKeeper.GetParams(ctx).PoolCreationFee

keepers.PoolManagerKeeper.SetParams(ctx, poolmanagerParams)
keepers.PacketForwardKeeper.SetParams(ctx, packetforwardtypes.DefaultParams())
Expand Down
20 changes: 17 additions & 3 deletions app/upgrades/v19/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ import (

"github.com/osmosis-labs/osmosis/v19/app/keepers"
"github.com/osmosis-labs/osmosis/v19/app/upgrades"
v18 "github.com/osmosis-labs/osmosis/v19/app/upgrades/v18"
poolmanagertypes "github.com/osmosis-labs/osmosis/v19/x/poolmanager/types"
)

// OSMO / DAI CL pool ID
const lastPoolToCorrect = 1066
const lastPoolToCorrect = v18.FirstCLPoolId - 1

func CreateUpgradeHandler(
mm *module.Manager,
Expand All @@ -28,9 +29,22 @@ func CreateUpgradeHandler(
return nil, err
}

for id := 1; id < lastPoolToCorrect; id++ {
for id := 1; id <= lastPoolToCorrect; id++ {
resetSuperfluidSumtree(keepers, ctx, uint64(id))
}

// Move the current authorized quote denoms from the concentrated liquidity params to the pool manager params.
// This needs to be moved because the pool manager requires access to these denoms to determine if the taker fee should
// be swapped into OSMO or not. The concentrated liquidity module already requires access to the pool manager keeper,
// so the right move in this case is to move this parameter upwards in order to prevent circular dependencies.
// TODO: In v20 upgrade handler, delete this param from the concentrated liquidity params.
currentConcentratedLiquidityParams := keepers.ConcentratedLiquidityKeeper.GetParams(ctx)
defaultPoolManagerParams := poolmanagertypes.DefaultParams()

defaultPoolManagerParams.AuthorizedQuoteDenoms = currentConcentratedLiquidityParams.AuthorizedQuoteDenoms
defaultPoolManagerParams.TakerFeeParams.DefaultTakerFee = sdk.ZeroDec()
keepers.PoolManagerKeeper.SetParams(ctx, defaultPoolManagerParams)

return migrations, nil
}
}
Expand Down
76 changes: 76 additions & 0 deletions proto/osmosis/poolmanager/v1beta1/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,21 @@ message Params {
(gogoproto.moretags) = "yaml:\"pool_creation_fee\"",
(gogoproto.nullable) = false
];
// taker_fee_params is the container of taker fee parameters.
TakerFeeParams taker_fee_params = 2 [
(gogoproto.moretags) = "yaml:\"taker_fee_params\"",
(gogoproto.nullable) = false
];
// authorized_quote_denoms is a list of quote denoms that can be used as
// token1 when creating a concentrated pool. We limit the quote assets to a
// small set for the purposes of having convinient price increments stemming
// from tick to price conversion. These increments are in a human readable
// magnitude only for token1 as a quote. For limit orders in the future, this
// will be a desirable property in terms of UX as to allow users to set limit
// orders at prices in terms of token1 (quote asset) that are easy to reason
// about.
repeated string authorized_quote_denoms = 3
[ (gogoproto.moretags) = "yaml:\"authorized_quote_denoms\"" ];
}

// GenesisState defines the poolmanager module's genesis state.
Expand All @@ -28,3 +43,64 @@ message GenesisState {
// pool_routes is the container of the mappings from pool id to pool type.
repeated ModuleRoute pool_routes = 3 [ (gogoproto.nullable) = false ];
}

// TakerFeeParams consolidates the taker fee parameters for the poolmanager.
message TakerFeeParams {
// default_taker_fee is the fee used when creating a new pool that doesn't
// fall under a custom pool taker fee or stableswap taker fee category.
string default_taker_fee = 1 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.customname) = "DefaultTakerFee",
(gogoproto.nullable) = false
];
// osmo_taker_fee_distribution defines the distribution of taker fees
// generated in OSMO. As of this writing, it has two catagories:
// - staking_rewards: the percent of the taker fee that gets distributed to
// stakers.
// - community_pool: the percent of the taker fee that gets sent to the
// community pool.
TakerFeeDistributionPercentage osmo_taker_fee_distribution = 2 [
(gogoproto.customname) = "OsmoTakerFeeDistribution",
(gogoproto.nullable) = false
];
// non_osmo_taker_fee_distribution defines the distribution of taker fees
// generated in non-OSMO. As of this writing, it has two categories:
// - staking_rewards: the percent of the taker fee that gets swapped to OSMO
// and then distirbuted to stakers.
// - community_pool: the percent of the taker fee that gets sent to the
// community pool. Note: If the non-OSMO asset is an authorized_quote_denom,
// that denom is sent directly to the community pool. Otherwise, it is
// swapped to the community_pool_denom_to_swap_non_whitelisted_assets_to and
// then sent to the community pool as that denom.
TakerFeeDistributionPercentage non_osmo_taker_fee_distribution = 3 [
(gogoproto.customname) = "NonOsmoTakerFeeDistribution",
(gogoproto.nullable) = false
];
// admin_addresses is a list of addresses that are allowed to set and remove
// custom taker fees for denom pairs. Governance also has the ability to set
// and remove custom taker fees for denom pairs, but with the normal
// governance delay.
repeated string admin_addresses = 4
[ (gogoproto.moretags) = "yaml:\"admin_addresses\"" ];
// community_pool_denom_to_swap_non_whitelisted_assets_to is the denom that
// non-whitelisted taker fees will be swapped to before being sent to
// the community pool.
string community_pool_denom_to_swap_non_whitelisted_assets_to = 5
[ (gogoproto.moretags) =
"yaml:\"community_pool_denom_to_swap_non_whitelisted_assets_to\"" ];
}

// TakerFeeDistributionPercentage defines what percent of the taker fee category
// gets distributed to the available categories.
message TakerFeeDistributionPercentage {
string staking_rewards = 1 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.moretags) = "yaml:\"staking_rewards\"",
(gogoproto.nullable) = false
];
string community_pool = 2 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.moretags) = "yaml:\"community_pool\"",
(gogoproto.nullable) = false
];
}
4 changes: 3 additions & 1 deletion proto/osmosis/poolmanager/v1beta1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,13 @@ message MsgSetDenomPairTakerFee {
message MsgSetDenomPairTakerFeeResponse { bool success = 1; }

message DenomPairTakerFee {
// denom0 and denom1 get automatically lexigographically sorted
// when being stored, so the order of input here does not matter.
string denom0 = 1 [ (gogoproto.moretags) = "yaml:\"denom0\"" ];
string denom1 = 2 [ (gogoproto.moretags) = "yaml:\"denom1\"" ];
string taker_fee = 3 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.moretags) = "yaml:\"taker_fee\"",
(gogoproto.nullable) = false
];
}
}
47 changes: 25 additions & 22 deletions tests/cl-genesis-positions/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ module cl-get-positions-subgraph
go 1.20

require (
github.com/cosmos/cosmos-sdk v0.47.3
github.com/cosmos/cosmos-sdk v0.47.4
github.com/ignite/cli v0.23.0
github.com/osmosis-labs/osmosis/osmomath v0.0.3-dev.0.20230621002052-afb82fbaa312
github.com/osmosis-labs/osmosis/osmoutils v0.0.0-20230623115558-38aaab07d343
github.com/osmosis-labs/osmosis/osmomath v0.0.3-dev.0.20230804142026-a81cfe3ddde7
github.com/osmosis-labs/osmosis/osmoutils v0.0.0-20230807183608-16c217dedde5
github.com/tendermint/tendermint v0.37.0-rc1
)

require github.com/osmosis-labs/osmosis/v16 v16.0.0-20230630175215-d5fcd089a71c
require github.com/osmosis-labs/osmosis/v17 v17.0.0-20230811221421-2e3f19d86dd4

require (
cosmossdk.io/errors v1.0.0-beta.7 // indirect
cosmossdk.io/errors v1.0.0 // indirect
filippo.io/edwards25519 v1.0.0-rc.1 // indirect
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect
github.com/99designs/keyring v1.2.1 // indirect
Expand All @@ -26,11 +26,11 @@ require (
github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816 // indirect
github.com/blang/semver v3.5.1+incompatible // indirect
github.com/btcsuite/btcd v0.22.3 // indirect
github.com/bytedance/sonic v1.9.1 // indirect
github.com/cenkalti/backoff v2.2.1+incompatible // indirect
github.com/cenkalti/backoff/v4 v4.1.3 // indirect
github.com/cespare/xxhash v1.1.0 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect
github.com/coinbase/rosetta-sdk-go v0.7.9 // indirect
github.com/confio/ics23/go v0.9.0 // indirect
github.com/cosmos/btcutil v1.0.5 // indirect
Expand All @@ -39,7 +39,8 @@ require (
github.com/cosmos/gogoproto v1.4.6 // indirect
github.com/cosmos/gorocksdb v1.2.0 // indirect
github.com/cosmos/iavl v0.19.5 // indirect
github.com/cosmos/ibc-apps/modules/async-icq/v4 v4.0.0-20230524151648-c02fa46c2860 // indirect
github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v4 v4.0.0-20230803185752-97c9635dd74a // indirect
github.com/cosmos/ibc-apps/modules/async-icq/v4 v4.0.0-20230803151532-5c60ac789ef7 // indirect
github.com/cosmos/ibc-go/v4 v4.3.1 // indirect
github.com/cosmos/ledger-cosmos-go v0.12.2 // indirect
github.com/creachadair/taskgroup v0.3.2 // indirect
Expand All @@ -53,15 +54,17 @@ require (
github.com/dvsekhvalnov/jose2go v1.5.0 // indirect
github.com/felixge/httpsnoop v1.0.2 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
github.com/ghodss/yaml v1.0.0 // indirect
github.com/go-kit/kit v0.12.0 // indirect
github.com/go-kit/log v0.2.1 // indirect
github.com/go-logfmt/logfmt v0.5.1 // indirect
github.com/go-playground/validator/v10 v10.14.0 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 // indirect
github.com/gogo/gateway v1.1.0 // indirect
github.com/gogo/protobuf v1.3.3 // indirect
github.com/golang/glog v1.1.0 // indirect
github.com/golang/glog v1.1.1 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/snappy v0.0.4 // indirect
Expand All @@ -82,12 +85,12 @@ require (
github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/hdevalence/ed25519consensus v0.0.0-20220222234857-c00d1f31bab3 // indirect
github.com/iancoleman/orderedmap v0.2.0 // indirect
github.com/iancoleman/orderedmap v0.3.0 // indirect
github.com/improbable-eng/grpc-web v0.15.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jmhodges/levigo v1.0.0 // indirect
github.com/klauspost/compress v1.15.11 // indirect
github.com/klauspost/cpuid/v2 v2.2.5 // indirect
github.com/leodido/go-urn v1.2.4 // indirect
github.com/lib/pq v1.10.7 // indirect
github.com/libp2p/go-buffer-pool v0.1.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
Expand All @@ -100,7 +103,7 @@ require (
github.com/mtibben/percent v0.2.1 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/osmosis-labs/osmosis/x/epochs v0.0.0-20230328024000-175ec88e4304 // indirect
github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.0-20230602130523-f9a94d8bbd10 // indirect
github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.0-20230807183608-16c217dedde5 // indirect
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5 // indirect
github.com/pkg/errors v0.9.1 // indirect
Expand All @@ -121,7 +124,6 @@ require (
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.16.0 // indirect
github.com/strangelove-ventures/packet-forward-middleware/v4 v4.0.5 // indirect
github.com/stretchr/testify v1.8.4 // indirect
github.com/subosito/gotenv v1.4.2 // indirect
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 // indirect
Expand All @@ -130,23 +132,24 @@ require (
github.com/tendermint/go-amino v0.16.0 // indirect
github.com/tendermint/tm-db v0.6.8-0.20220506192307-f628bb5dc95b // indirect
github.com/tidwall/btree v1.6.0 // indirect
github.com/ugorji/go/codec v1.2.11 // indirect
github.com/zondax/hid v0.9.1 // indirect
github.com/zondax/ledger-go v0.14.1 // indirect
go.etcd.io/bbolt v1.3.6 // indirect
go.opencensus.io v0.24.0 // indirect
golang.org/x/arch v0.3.0 // indirect
golang.org/x/crypto v0.9.0 // indirect
golang.org/x/crypto v0.11.0 // indirect
golang.org/x/exp v0.0.0-20230131160201-f062dba9d201 // indirect
golang.org/x/mod v0.10.0 // indirect
golang.org/x/net v0.10.0 // indirect
golang.org/x/net v0.12.0 // indirect
golang.org/x/sync v0.2.0 // indirect
golang.org/x/sys v0.8.0 // indirect
golang.org/x/term v0.8.0 // indirect
golang.org/x/text v0.9.0 // indirect
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 // indirect
google.golang.org/grpc v1.55.0 // indirect
google.golang.org/protobuf v1.30.0 // indirect
golang.org/x/sys v0.10.0 // indirect
golang.org/x/term v0.10.0 // indirect
golang.org/x/text v0.11.0 // indirect
google.golang.org/genproto v0.0.0-20230726155614-23370e0ffb3e // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20230706204954-ccb25ca9f130 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230706204954-ccb25ca9f130 // indirect
google.golang.org/grpc v1.56.2 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
Loading