Skip to content

Commit

Permalink
merge main
Browse files Browse the repository at this point in the history
  • Loading branch information
czarcas7ic committed Oct 8, 2023
1 parent 1184ff2 commit a0ed7a0
Show file tree
Hide file tree
Showing 13 changed files with 305 additions and 104 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

* [#6468](https://github.com/osmosis-labs/osmosis/pull/6468) feat: remove osmo multihop discount
* [#6420](https://github.com/osmosis-labs/osmosis/pull/6420) feat[CL]: Creates a governance set whitelist of addresses that can bypass the normal pool creation restrictions on concentrated liquidity pools
* [#6632](https://github.com/osmosis-labs/osmosis/pull/6632) Taker fee bypass whitelist

### State Breaking

Expand Down
10 changes: 8 additions & 2 deletions app/upgrades/v20/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
incentivestypes "github.com/osmosis-labs/osmosis/v19/x/incentives/types"
lockuptypes "github.com/osmosis-labs/osmosis/v19/x/lockup/types"
poolincenitvestypes "github.com/osmosis-labs/osmosis/v19/x/pool-incentives/types"
poolmanagertypes "github.com/osmosis-labs/osmosis/v19/x/poolmanager/types"
)

type IncentivizedCFMMDirectWhenMigrationLinkPresentError struct {
Expand All @@ -21,6 +22,8 @@ type IncentivizedCFMMDirectWhenMigrationLinkPresentError struct {
CFMMGaugeID uint64
}

var emptySlice = []string{}

func (e IncentivizedCFMMDirectWhenMigrationLinkPresentError) Error() string {
return fmt.Sprintf("CFMM gauge ID (%d) incentivized CFMM pool (%d) directly when migration link is present with concentrated pool (%d)", e.CFMMGaugeID, e.CFMMPoolID, e.ConcentratedPoolID)
}
Expand All @@ -40,11 +43,14 @@ func CreateUpgradeHandler(
}

// Initialize the newly created param
keepers.ConcentratedLiquidityKeeper.SetParam(ctx, cltypes.KeyUnrestrictedPoolCreatorWhitelist, []string{})
keepers.ConcentratedLiquidityKeeper.SetParam(ctx, cltypes.KeyUnrestrictedPoolCreatorWhitelist, emptySlice)

// Initialize the new params in incentives for group creation.
keepers.IncentivesKeeper.SetParam(ctx, incentivestypes.KeyGroupCreationFee, incentivestypes.DefaultGroupCreationFee)
keepers.IncentivesKeeper.SetParam(ctx, incentivestypes.KeyCreatorWhitelist, []string{})
keepers.IncentivesKeeper.SetParam(ctx, incentivestypes.KeyCreatorWhitelist, emptySlice)

// Initialize new param in the poolmanager module with a whitelist allowing to bypass taker fees.
keepers.PoolManagerKeeper.SetParam(ctx, poolmanagertypes.KeyReducedTakerFeeByWhitelist, emptySlice)

// Converts pool incentive distribution records from concentrated gauges to group gauges.
err = createGroupsForIncentivePairs(ctx, keepers)
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ require (
github.com/mattn/go-sqlite3 v1.14.17
github.com/ory/dockertest/v3 v3.10.0
github.com/osmosis-labs/go-mutesting v0.0.0-20221208041716-b43bcd97b3b3
github.com/osmosis-labs/osmosis/osmomath v0.0.7-0.20231003135651-7418f98f1a04
github.com/osmosis-labs/osmosis/osmoutils v0.0.7-0.20230929193736-aae32321cac7
github.com/osmosis-labs/osmosis/osmomath v0.0.7-0.20231007115900-2500631de18e
github.com/osmosis-labs/osmosis/osmoutils v0.0.7-0.20231007115900-2500631de18e
github.com/osmosis-labs/osmosis/x/epochs v0.0.3-0.20230911120014-b14342e08daf
github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.9-0.20230911120014-b14342e08daf
github.com/pkg/errors v0.9.1
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -964,10 +964,10 @@ github.com/osmosis-labs/cosmos-sdk v0.45.0-rc1.0.20230922030206-734f99fba785 h1:
github.com/osmosis-labs/cosmos-sdk v0.45.0-rc1.0.20230922030206-734f99fba785/go.mod h1:toI9Pf+e5C4TuWAFpXfkxnkpr1RVFMK2qr7QMdkFrY8=
github.com/osmosis-labs/go-mutesting v0.0.0-20221208041716-b43bcd97b3b3 h1:YlmchqTmlwdWSmrRmXKR+PcU96ntOd8u10vTaTZdcNY=
github.com/osmosis-labs/go-mutesting v0.0.0-20221208041716-b43bcd97b3b3/go.mod h1:lV6KnqXYD/ayTe7310MHtM3I2q8Z6bBfMAi+bhwPYtI=
github.com/osmosis-labs/osmosis/osmomath v0.0.7-0.20231003135651-7418f98f1a04 h1:C8LtPGkhJxfJNj7Xtok1If5yAV53O6XG3USaOJSgeg4=
github.com/osmosis-labs/osmosis/osmomath v0.0.7-0.20231003135651-7418f98f1a04/go.mod h1:jtOM+8RJMOn5e8YIaodzvO0b8kvBcHDgtCVCmWrx6wU=
github.com/osmosis-labs/osmosis/osmoutils v0.0.7-0.20230929193736-aae32321cac7 h1:E5rwhxKEt6XOIfLkoLNiqCCFNCymJjiwMYIP+0ABMKM=
github.com/osmosis-labs/osmosis/osmoutils v0.0.7-0.20230929193736-aae32321cac7/go.mod h1:YT53hlXr54D4MVKp3eoBxigiiYvy3F+h+xTZuGPW5R8=
github.com/osmosis-labs/osmosis/osmomath v0.0.7-0.20231007115900-2500631de18e h1:jzLtdFKLMvdqq+k3FYwvwCU3y1tzczXAs+R6JD+sxlY=
github.com/osmosis-labs/osmosis/osmomath v0.0.7-0.20231007115900-2500631de18e/go.mod h1:jtOM+8RJMOn5e8YIaodzvO0b8kvBcHDgtCVCmWrx6wU=
github.com/osmosis-labs/osmosis/osmoutils v0.0.7-0.20231007115900-2500631de18e h1:TyAleAgHjQeQCXH+2qAgtLix+OcBRqFizIdiJE+r2GU=
github.com/osmosis-labs/osmosis/osmoutils v0.0.7-0.20231007115900-2500631de18e/go.mod h1:YT53hlXr54D4MVKp3eoBxigiiYvy3F+h+xTZuGPW5R8=
github.com/osmosis-labs/osmosis/x/epochs v0.0.3-0.20230911120014-b14342e08daf h1:8lkIsAj3L7zxvOZbqVLNJRpSdDxaYhYfAIG7XjPaJiU=
github.com/osmosis-labs/osmosis/x/epochs v0.0.3-0.20230911120014-b14342e08daf/go.mod h1:C0Uqe6X4N5ASA+1xZ6guaaJyUVKLcaVJIQa4Q4LG9Vk=
github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.9-0.20230911120014-b14342e08daf h1:ZEi+yJJPgpYtmNwZ1bMiP5cMBDQ83FK/YGgmTnWmoAI=
Expand Down
30 changes: 30 additions & 0 deletions osmoutils/params_validation.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package osmoutils

import (
"fmt"

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

// ValidateAddressList validates a slice of addresses.
//
// Parameters:
// - i: The parameter to validate.
//
// Returns:
// - An error if any of the strings are not addresses
func ValidateAddressList(i interface{}) error {
whitelist, ok := i.([]string)

if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}

for _, a := range whitelist {
if _, err := sdk.AccAddressFromBech32(a); err != nil {
return fmt.Errorf("invalid address")
}
}

return nil
}
10 changes: 10 additions & 0 deletions proto/osmosis/poolmanager/v1beta1/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,16 @@ message TakerFeeParams {
string community_pool_denom_to_swap_non_whitelisted_assets_to = 5
[ (gogoproto.moretags) =
"yaml:\"community_pool_denom_to_swap_non_whitelisted_assets_to\"" ];

// reduced_fee_whitelist is a list of addresses that are
// allowed to pay a reduce taker fee when performing a swap
// (i.e. swap without paying the taker fee).
// It is intended to be used for integrators who meet qualifying factors
// that are approved by governance.
// Initially, the taker fee is allowed to be bypassed completely. However
// In the future, we will charge a reduced taker fee instead of no fee at all.
repeated string reduced_fee_whitelist = 6
[ (gogoproto.moretags) = "yaml:\"reduced_fee_whitelist\"" ];
}

// TakerFeeDistributionPercentage defines what percent of the taker fee category
Expand Down
29 changes: 3 additions & 26 deletions x/concentrated-liquidity/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"

"github.com/osmosis-labs/osmosis/osmomath"
"github.com/osmosis-labs/osmosis/osmoutils"
)

// Parameter store keys.
Expand Down Expand Up @@ -78,7 +79,7 @@ func (p Params) Validate() error {
if err := validateAuthorizedUptimes(p.AuthorizedUptimes); err != nil {
return err
}
if err := validateUnrestrictedPoolCreatorWhitelist(p.UnrestrictedPoolCreatorWhitelist); err != nil {
if err := osmoutils.ValidateAddressList(p.UnrestrictedPoolCreatorWhitelist); err != nil {
return err
}
return nil
Expand All @@ -93,7 +94,7 @@ func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs {
paramtypes.NewParamSetPair(KeyIsPermisionlessPoolCreationEnabled, &p.IsPermissionlessPoolCreationEnabled, validateIsPermissionLessPoolCreationEnabled),
paramtypes.NewParamSetPair(KeyDiscountRate, &p.BalancerSharesRewardDiscount, validateBalancerSharesDiscount),
paramtypes.NewParamSetPair(KeyAuthorizedUptimes, &p.AuthorizedUptimes, validateAuthorizedUptimes),
paramtypes.NewParamSetPair(KeyUnrestrictedPoolCreatorWhitelist, &p.UnrestrictedPoolCreatorWhitelist, validateUnrestrictedPoolCreatorWhitelist),
paramtypes.NewParamSetPair(KeyUnrestrictedPoolCreatorWhitelist, &p.UnrestrictedPoolCreatorWhitelist, osmoutils.ValidateAddressList),
}
}

Expand Down Expand Up @@ -242,27 +243,3 @@ func validateAuthorizedUptimes(i interface{}) error {

return nil
}

// validateUnrestrictedPoolCreatorWhitelist validates a slice of addresses
// that are allowed to bypass the restrictions on permissionless pool creation
//
// Parameters:
// - i: The parameter to validate.
//
// Returns:
// - An error if any of the strings are not addresses
func validateUnrestrictedPoolCreatorWhitelist(i interface{}) error {
whitelist, ok := i.([]string)

if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}

for _, a := range whitelist {
if _, err := sdk.AccAddressFromBech32(a); err != nil {
return fmt.Errorf("invalid address")
}
}

return nil
}
24 changes: 7 additions & 17 deletions x/incentives/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

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

"github.com/osmosis-labs/osmosis/osmoutils"
epochtypes "github.com/osmosis-labs/osmosis/x/epochs/types"

paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
Expand Down Expand Up @@ -52,6 +53,11 @@ func (p Params) Validate() error {
if err := ValidateGroupCreaionFee(p.GroupCreationFee); err != nil {
return err
}

if err := osmoutils.ValidateAddressList(p.UnrestrictedCreatorWhitelist); err != nil {
return err
}

return nil
}

Expand All @@ -63,22 +69,6 @@ func ValidateGroupCreaionFee(i interface{}) error {
return v.Validate()
}

func ValidateCreatorWhitelist(i interface{}) error {
v, ok := i.([]string)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}

// Validate that addresses are set correctly
for _, creator := range v {
if _, err := sdk.AccAddressFromBech32(creator); err != nil {
return err
}
}

return nil
}

func ValidateGroupCreationFee(i interface{}) error {
v, ok := i.(sdk.Coins)
if !ok {
Expand All @@ -92,6 +82,6 @@ func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs {
return paramtypes.ParamSetPairs{
paramtypes.NewParamSetPair(KeyDistrEpochIdentifier, &p.DistrEpochIdentifier, epochtypes.ValidateEpochIdentifierInterface),
paramtypes.NewParamSetPair(KeyGroupCreationFee, &p.GroupCreationFee, ValidateGroupCreaionFee),
paramtypes.NewParamSetPair(KeyCreatorWhitelist, &p.UnrestrictedCreatorWhitelist, ValidateCreatorWhitelist),
paramtypes.NewParamSetPair(KeyCreatorWhitelist, &p.UnrestrictedCreatorWhitelist, osmoutils.ValidateAddressList),
}
}
4 changes: 4 additions & 0 deletions x/poolmanager/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,7 @@ func (k Keeper) CalcTakerFeeExactOut(tokenOut sdk.Coin, takerFee osmomath.Dec) (
func (k Keeper) TrackVolume(ctx sdk.Context, poolId uint64, volumeGenerated sdk.Coin) {
k.trackVolume(ctx, poolId, volumeGenerated)
}

func (k Keeper) ChargeTakerFee(ctx sdk.Context, tokenIn sdk.Coin, tokenOutDenom string, sender sdk.AccAddress, exactIn bool) (sdk.Coin, error) {
return k.chargeTakerFee(ctx, tokenIn, tokenOutDenom, sender, exactIn)
}
7 changes: 7 additions & 0 deletions x/poolmanager/taker_fee.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,19 @@ func (k Keeper) GetTradingPairTakerFee(ctx sdk.Context, denom0, denom1 string) (

// chargeTakerFee extracts the taker fee from the given tokenIn and sends it to the appropriate
// module account. It returns the tokenIn after the taker fee has been extracted.
// If the sender is in the taker fee reduced whitelisted, it returns the tokenIn without extracting the taker fee.
// In the future, we might charge a lower taker fee as opposed to no fee at all.
func (k Keeper) chargeTakerFee(ctx sdk.Context, tokenIn sdk.Coin, tokenOutDenom string, sender sdk.AccAddress, exactIn bool) (sdk.Coin, error) {
feeCollectorForStakingRewardsName := txfeestypes.FeeCollectorForStakingRewardsName
feeCollectorForCommunityPoolName := txfeestypes.FeeCollectorForCommunityPoolName
defaultTakerFeeDenom := appparams.BaseCoinUnit
poolManagerParams := k.GetParams(ctx)

// Determine if eligible to bypass taker fee.
if osmoutils.Contains(poolManagerParams.TakerFeeParams.ReducedFeeWhitelist, sender.String()) {
return tokenIn, nil
}

takerFee, err := k.GetTradingPairTakerFee(ctx, tokenIn.Denom, tokenOutDenom)
if err != nil {
return sdk.Coin{}, err
Expand Down
105 changes: 105 additions & 0 deletions x/poolmanager/taker_fee_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
package poolmanager_test

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

"github.com/osmosis-labs/osmosis/osmomath"
"github.com/osmosis-labs/osmosis/v19/app/apptesting"
)

// validates that the pool manager keeper can charge taker fees correctly.
// If the sender is whitelisted, then the taker fee is not charged.
// Otherwise, the taker fee is charged.
func (s *KeeperTestSuite) TestChargeTakerFee() {

const (
whitelistedSenderIndex = iota
nonWhitelistedSenderIndex
)

var (
defaultTakerFee = osmomath.MustNewDecFromStr("0.01")
defaultAmount = sdk.NewInt(100)
)

tests := map[string]struct {
shouldSetSenderWhitelist bool
tokenIn sdk.Coin
tokenOutDenom string
senderIndex int
exactIn bool
takerFee osmomath.Dec

expectedResult sdk.Coin
expectError error
}{
"fee charged on token in": {
takerFee: defaultTakerFee,
tokenIn: sdk.NewCoin(apptesting.ETH, defaultAmount),
tokenOutDenom: apptesting.USDC,
senderIndex: whitelistedSenderIndex,
exactIn: true,

expectedResult: sdk.NewCoin(apptesting.ETH, defaultAmount.ToLegacyDec().Mul(osmomath.OneDec().Sub(defaultTakerFee)).TruncateInt()),
},
"fee charged on token in due to different address being whitelisted": {
takerFee: defaultTakerFee,
tokenIn: sdk.NewCoin(apptesting.ETH, defaultAmount),
tokenOutDenom: apptesting.USDC,
senderIndex: nonWhitelistedSenderIndex,
exactIn: true,
shouldSetSenderWhitelist: true,

expectedResult: sdk.NewCoin(apptesting.ETH, defaultAmount.ToLegacyDec().Mul(osmomath.OneDec().Sub(defaultTakerFee)).TruncateInt()),
},
"fee bypassed due to sender being whitelisted": {
takerFee: defaultTakerFee,
tokenIn: sdk.NewCoin(apptesting.ETH, defaultAmount),
tokenOutDenom: apptesting.USDC,
senderIndex: whitelistedSenderIndex,
exactIn: true,
shouldSetSenderWhitelist: true,

expectedResult: sdk.NewCoin(apptesting.ETH, defaultAmount),
},
// TODO: under more test cases
// https://github.com/osmosis-labs/osmosis/issues/6633
// - exactOut: false
// - sender does not have enough coins
}

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

// Set whitelist.
if tc.shouldSetSenderWhitelist {
poolManagerParams := poolManager.GetParams(s.Ctx)
poolManagerParams.TakerFeeParams.ReducedFeeWhitelist = []string{s.TestAccs[whitelistedSenderIndex].String()}
poolManager.SetParams(s.Ctx, poolManagerParams)
}

// Create pool.
s.PrepareConcentratedPool()

// Set taker fee.
poolManager.SetDenomPairTakerFee(s.Ctx, tc.tokenIn.Denom, tc.tokenOutDenom, tc.takerFee)

// Pre-fund owner.
s.FundAcc(s.TestAccs[tc.senderIndex], sdk.NewCoins(tc.tokenIn))

// System under test.
tokenInAfterTakerFee, err := poolManager.ChargeTakerFee(s.Ctx, tc.tokenIn, tc.tokenOutDenom, s.TestAccs[tc.senderIndex], tc.exactIn)

if tc.expectError != nil {
s.Require().Error(err)
return
}
s.Require().NoError(err)

// Validate results.
s.Require().Equal(tc.expectedResult.String(), tokenInAfterTakerFee.String())
})
}
}
Loading

0 comments on commit a0ed7a0

Please sign in to comment.