-
Notifications
You must be signed in to change notification settings - Fork 638
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(poolmanager): taker fee reduction whitelist #6632
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
710ed4a
feat(poolmanager): taker fee bypass whitelist
p0mvn 47f1402
changelog
p0mvn 091eee1
go mod
p0mvn 898f277
fix
p0mvn 75efdde
link TODO issue
p0mvn ed52712
Merge branch 'main' into roman/taker-fee-bypass-whitelist
p0mvn 2500631
updates
p0mvn b9fb0cf
go mod updates
p0mvn adb197c
renames
p0mvn d8f2c27
add test with different sender whitelisted
p0mvn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
p0mvn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
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()) | ||
}) | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: copied from the x/concentrated-liquidity to reduce code duplication