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(poolmanager): taker fee reduction whitelist #6632

Merged
merged 10 commits into from
Oct 7, 2023
Merged
Changes from 1 commit
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
Prev Previous commit
add test with different sender whitelisted
  • Loading branch information
p0mvn committed Oct 7, 2023
commit d8f2c27ddeab86244f56b228b292544c847203cd
27 changes: 21 additions & 6 deletions x/poolmanager/taker_fee_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ import (
// Otherwise, the taker fee is charged.
func (s *KeeperTestSuite) TestChargeTakerFee() {

const (
whitelistedSenderIndex = iota
nonWhitelistedSenderIndex
)

var (
defaultTakerFee = osmomath.MustNewDecFromStr("0.01")
defaultAmount = sdk.NewInt(100)
Expand All @@ -21,7 +26,7 @@ func (s *KeeperTestSuite) TestChargeTakerFee() {
shouldSetSenderWhitelist bool
tokenIn sdk.Coin
tokenOutDenom string
sender sdk.AccAddress
senderIndex int
exactIn bool
takerFee osmomath.Dec

Expand All @@ -32,16 +37,26 @@ func (s *KeeperTestSuite) TestChargeTakerFee() {
takerFee: defaultTakerFee,
tokenIn: sdk.NewCoin(apptesting.ETH, defaultAmount),
tokenOutDenom: apptesting.USDC,
sender: s.TestAccs[0],
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,
sender: s.TestAccs[0],
senderIndex: whitelistedSenderIndex,
exactIn: true,
shouldSetSenderWhitelist: true,

Expand All @@ -61,7 +76,7 @@ func (s *KeeperTestSuite) TestChargeTakerFee() {
// Set whitelist.
if tc.shouldSetSenderWhitelist {
poolManagerParams := poolManager.GetParams(s.Ctx)
poolManagerParams.TakerFeeParams.ReducedFeeWhitelist = []string{tc.sender.String()}
poolManagerParams.TakerFeeParams.ReducedFeeWhitelist = []string{s.TestAccs[whitelistedSenderIndex].String()}
poolManager.SetParams(s.Ctx, poolManagerParams)
}

Expand All @@ -72,10 +87,10 @@ func (s *KeeperTestSuite) TestChargeTakerFee() {
poolManager.SetDenomPairTakerFee(s.Ctx, tc.tokenIn.Denom, tc.tokenOutDenom, tc.takerFee)

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

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

if tc.expectError != nil {
s.Require().Error(err)
Expand Down