-
Notifications
You must be signed in to change notification settings - Fork 608
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1184ff2
commit a0ed7a0
Showing
13 changed files
with
305 additions
and
104 deletions.
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 | ||
} | ||
|
||
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.