Skip to content

Commit

Permalink
weight breaking fee update work
Browse files Browse the repository at this point in the history
  • Loading branch information
jelysn committed Dec 14, 2023
1 parent 931c8cc commit d2bb3f1
Show file tree
Hide file tree
Showing 25 changed files with 173 additions and 36 deletions.
4 changes: 4 additions & 0 deletions proto/elys/amm/pool_params.proto
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ message PoolParams {
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
string weight_breaking_fee_exponent = 11 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
string external_liquidity_ratio = 5 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
Expand Down
1 change: 1 addition & 0 deletions x/amm/client/cli/query_pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func networkWithPoolObjects(t *testing.T, n int) (*network.Network, []types.Pool
ExitFee: sdk.ZeroDec(),
UseOracle: false,
WeightBreakingFeeMultiplier: sdk.ZeroDec(),
WeightBreakingFeeExponent: sdk.NewDecWithPrec(25, 1), // 2.5
ExternalLiquidityRatio: sdk.NewDec(1),
LpFeePortion: sdk.ZeroDec(),
StakingFeePortion: sdk.ZeroDec(),
Expand Down
8 changes: 8 additions & 0 deletions x/amm/client/cli/tx_create_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const (
FlagExitFee = "exit-fee"
FlagUseOracle = "use-oracle"
FlagWeightBreakingFeeMultiplier = "weight-breaking-fee-multiplier"
FlagWeightBreakingFeeExponent = "weight-breaking-fee-exponent"
FlagExternalLiquidityRatio = "extern-liquidity-ratio"
FlagLpFeePortion = "lp-fee"
FlagStakingFeePortion = "staking-fee"
Expand Down Expand Up @@ -81,6 +82,11 @@ func CmdCreatePool() *cobra.Command {
return err
}

weightBreakingFeeExponentStr, err := cmd.Flags().GetString(FlagWeightBreakingFeeExponent)
if err != nil {
return err
}

externalLiquidityRatioStr, err := cmd.Flags().GetString(FlagExternalLiquidityRatio)
if err != nil {
return err
Expand Down Expand Up @@ -116,6 +122,7 @@ func CmdCreatePool() *cobra.Command {
ExitFee: sdk.MustNewDecFromStr(exitFeeStr),
UseOracle: useOracle,
WeightBreakingFeeMultiplier: sdk.MustNewDecFromStr(weightBreakingFeeMultiplierStr),
WeightBreakingFeeExponent: sdk.MustNewDecFromStr(weightBreakingFeeExponentStr),
ExternalLiquidityRatio: sdk.MustNewDecFromStr(externalLiquidityRatioStr),
LpFeePortion: sdk.MustNewDecFromStr(lpFeePortionStr),
StakingFeePortion: sdk.MustNewDecFromStr(stakingFeePortionStr),
Expand All @@ -142,6 +149,7 @@ func CmdCreatePool() *cobra.Command {
cmd.Flags().String(FlagExitFee, "0.00", "exit fee")
cmd.Flags().Bool(FlagUseOracle, false, "flag to be an oracle pool or non-oracle pool")
cmd.Flags().String(FlagWeightBreakingFeeMultiplier, "0.00", "weight breaking fee multiplier")
cmd.Flags().String(FlagWeightBreakingFeeExponent, "2.50", "weight breaking fee exponent")
cmd.Flags().String(FlagExternalLiquidityRatio, "0.00", "external liquidity ratio - valid for oracle pools")
cmd.Flags().String(FlagLpFeePortion, "0.00", "lp fee portion")
cmd.Flags().String(FlagStakingFeePortion, "0.00", "staking fee portion")
Expand Down
6 changes: 6 additions & 0 deletions x/amm/client/cli/tx_update_pool_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ func CmdUpdatePoolParams() *cobra.Command {
return err
}

weightBreakingFeeExponentStr, err := cmd.Flags().GetString(FlagWeightBreakingFeeExponent)
if err != nil {
return err
}

externalLiquidityRatioStr, err := cmd.Flags().GetString(FlagExternalLiquidityRatio)
if err != nil {
return err
Expand Down Expand Up @@ -77,6 +82,7 @@ func CmdUpdatePoolParams() *cobra.Command {
ExitFee: sdk.MustNewDecFromStr(exitFeeStr),
UseOracle: useOracle,
WeightBreakingFeeMultiplier: sdk.MustNewDecFromStr(weightBreakingFeeMultiplierStr),
WeightBreakingFeeExponent: sdk.MustNewDecFromStr(weightBreakingFeeExponentStr),
ExternalLiquidityRatio: sdk.MustNewDecFromStr(externalLiquidityRatioStr),
LpFeePortion: sdk.MustNewDecFromStr(lpFeePortionStr),
StakingFeePortion: sdk.MustNewDecFromStr(stakingFeePortionStr),
Expand Down
1 change: 1 addition & 0 deletions x/amm/keeper/apply_exit_pool_state_change_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func (suite *KeeperTestSuite) TestApplyExitPoolStateChange_WithdrawFromCommitmen
ExitFee: exitFee,
UseOracle: true,
WeightBreakingFeeMultiplier: sdk.ZeroDec(),
WeightBreakingFeeExponent: sdk.NewDecWithPrec(25, 1), // 2.5
ExternalLiquidityRatio: sdk.NewDec(1),
LpFeePortion: sdk.ZeroDec(),
StakingFeePortion: sdk.ZeroDec(),
Expand Down
2 changes: 2 additions & 0 deletions x/amm/keeper/fee_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ func (suite *KeeperTestSuite) TestOnCollectFee() {
ExitFee: sdk.ZeroDec(),
UseOracle: false,
WeightBreakingFeeMultiplier: sdk.ZeroDec(),
WeightBreakingFeeExponent: sdk.NewDecWithPrec(25, 1), // 2.5
ExternalLiquidityRatio: sdk.NewDec(1),
LpFeePortion: sdk.ZeroDec(),
StakingFeePortion: sdk.ZeroDec(),
Expand Down Expand Up @@ -186,6 +187,7 @@ func (suite *KeeperTestSuite) TestSwapFeesToRevenueToken() {
ExitFee: sdk.ZeroDec(),
UseOracle: false,
WeightBreakingFeeMultiplier: sdk.ZeroDec(),
WeightBreakingFeeExponent: sdk.NewDecWithPrec(25, 1), // 2.5
ExternalLiquidityRatio: sdk.NewDec(1),
LpFeePortion: sdk.ZeroDec(),
StakingFeePortion: sdk.ZeroDec(),
Expand Down
1 change: 1 addition & 0 deletions x/amm/keeper/keeper_swap_exact_amount_in_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ func (suite *KeeperTestSuite) TestSwapExactAmountIn() {
UseOracle: tc.isOraclePool,
ExternalLiquidityRatio: sdk.NewDec(2),
WeightBreakingFeeMultiplier: sdk.ZeroDec(),
WeightBreakingFeeExponent: sdk.NewDecWithPrec(25, 1), // 2.5
LpFeePortion: sdk.ZeroDec(),
StakingFeePortion: sdk.ZeroDec(),
WeightRecoveryFeePortion: sdk.ZeroDec(),
Expand Down
1 change: 1 addition & 0 deletions x/amm/keeper/keeper_swap_exact_amount_out_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ func (suite *KeeperTestSuite) TestSwapExactAmountOut() {
UseOracle: tc.isOraclePool,
ExternalLiquidityRatio: sdk.NewDec(2),
WeightBreakingFeeMultiplier: sdk.ZeroDec(),
WeightBreakingFeeExponent: sdk.NewDecWithPrec(25, 1), // 2.5
LpFeePortion: sdk.ZeroDec(),
StakingFeePortion: sdk.ZeroDec(),
WeightRecoveryFeePortion: sdk.ZeroDec(),
Expand Down
3 changes: 3 additions & 0 deletions x/amm/keeper/msg_server_create_pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func (suite *KeeperTestSuite) TestMsgServerCreatePool() {
ExitFee: sdk.ZeroDec(),
UseOracle: false,
WeightBreakingFeeMultiplier: sdk.ZeroDec(),
WeightBreakingFeeExponent: sdk.NewDecWithPrec(25, 1), // 2.5
ExternalLiquidityRatio: sdk.NewDec(1),
LpFeePortion: sdk.ZeroDec(),
StakingFeePortion: sdk.ZeroDec(),
Expand Down Expand Up @@ -57,6 +58,7 @@ func (suite *KeeperTestSuite) TestMsgServerCreatePool() {
ExitFee: sdk.ZeroDec(),
UseOracle: false,
WeightBreakingFeeMultiplier: sdk.ZeroDec(),
WeightBreakingFeeExponent: sdk.NewDecWithPrec(25, 1), // 2.5
ExternalLiquidityRatio: sdk.NewDec(1),
LpFeePortion: sdk.ZeroDec(),
StakingFeePortion: sdk.ZeroDec(),
Expand Down Expand Up @@ -86,6 +88,7 @@ func (suite *KeeperTestSuite) TestMsgServerCreatePool() {
ExitFee: sdk.ZeroDec(),
UseOracle: false,
WeightBreakingFeeMultiplier: sdk.ZeroDec(),
WeightBreakingFeeExponent: sdk.NewDecWithPrec(25, 1), // 2.5
ExternalLiquidityRatio: sdk.NewDec(1),
LpFeePortion: sdk.ZeroDec(),
StakingFeePortion: sdk.ZeroDec(),
Expand Down
8 changes: 6 additions & 2 deletions x/amm/keeper/msg_server_exit_pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func (suite *KeeperTestSuite) TestMsgServerExitPool() {
ExitFee: sdk.ZeroDec(),
UseOracle: false,
WeightBreakingFeeMultiplier: sdk.ZeroDec(),
WeightBreakingFeeExponent: sdk.NewDecWithPrec(25, 1), // 2.5
ExternalLiquidityRatio: sdk.NewDec(1),
LpFeePortion: sdk.ZeroDec(),
StakingFeePortion: sdk.ZeroDec(),
Expand All @@ -52,6 +53,7 @@ func (suite *KeeperTestSuite) TestMsgServerExitPool() {
ExitFee: sdk.ZeroDec(),
UseOracle: false,
WeightBreakingFeeMultiplier: sdk.ZeroDec(),
WeightBreakingFeeExponent: sdk.NewDecWithPrec(25, 1), // 2.5
ExternalLiquidityRatio: sdk.NewDec(1),
LpFeePortion: sdk.ZeroDec(),
StakingFeePortion: sdk.ZeroDec(),
Expand All @@ -72,7 +74,8 @@ func (suite *KeeperTestSuite) TestMsgServerExitPool() {
SwapFee: sdk.ZeroDec(),
ExitFee: sdk.ZeroDec(),
UseOracle: true,
WeightBreakingFeeMultiplier: sdk.NewDecWithPrec(1, 0), // 1.00
WeightBreakingFeeMultiplier: sdk.NewDecWithPrec(1, 0), // 1.00
WeightBreakingFeeExponent: sdk.NewDecWithPrec(25, 1), // 2.5
ExternalLiquidityRatio: sdk.NewDec(1),
LpFeePortion: sdk.ZeroDec(),
StakingFeePortion: sdk.ZeroDec(),
Expand All @@ -94,7 +97,8 @@ func (suite *KeeperTestSuite) TestMsgServerExitPool() {
SwapFee: sdk.ZeroDec(),
ExitFee: sdk.ZeroDec(),
UseOracle: true,
WeightBreakingFeeMultiplier: sdk.NewDecWithPrec(1, 0), // 1.00
WeightBreakingFeeMultiplier: sdk.NewDecWithPrec(1, 0), // 1.00
WeightBreakingFeeExponent: sdk.NewDecWithPrec(25, 1), // 2.5
ExternalLiquidityRatio: sdk.NewDec(1),
LpFeePortion: sdk.ZeroDec(),
StakingFeePortion: sdk.ZeroDec(),
Expand Down
11 changes: 8 additions & 3 deletions x/amm/keeper/msg_server_join_pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func (suite *KeeperTestSuite) TestMsgServerJoinPool() {
ExitFee: sdk.ZeroDec(),
UseOracle: false,
WeightBreakingFeeMultiplier: sdk.ZeroDec(),
WeightBreakingFeeExponent: sdk.NewDecWithPrec(25, 1), // 2.5
ExternalLiquidityRatio: sdk.NewDec(1),
LpFeePortion: sdk.ZeroDec(),
StakingFeePortion: sdk.ZeroDec(),
Expand All @@ -51,6 +52,7 @@ func (suite *KeeperTestSuite) TestMsgServerJoinPool() {
ExitFee: sdk.ZeroDec(),
UseOracle: false,
WeightBreakingFeeMultiplier: sdk.ZeroDec(),
WeightBreakingFeeExponent: sdk.NewDecWithPrec(25, 1), // 2.5
ExternalLiquidityRatio: sdk.NewDec(1),
LpFeePortion: sdk.ZeroDec(),
StakingFeePortion: sdk.ZeroDec(),
Expand All @@ -71,7 +73,8 @@ func (suite *KeeperTestSuite) TestMsgServerJoinPool() {
SwapFee: sdk.ZeroDec(),
ExitFee: sdk.ZeroDec(),
UseOracle: true,
WeightBreakingFeeMultiplier: sdk.NewDecWithPrec(1, 0), // 1.00
WeightBreakingFeeMultiplier: sdk.NewDecWithPrec(1, 0), // 1.00
WeightBreakingFeeExponent: sdk.NewDecWithPrec(25, 1), // 2.5
ExternalLiquidityRatio: sdk.NewDec(1),
LpFeePortion: sdk.ZeroDec(),
StakingFeePortion: sdk.ZeroDec(),
Expand All @@ -93,7 +96,8 @@ func (suite *KeeperTestSuite) TestMsgServerJoinPool() {
SwapFee: sdk.ZeroDec(),
ExitFee: sdk.ZeroDec(),
UseOracle: true,
WeightBreakingFeeMultiplier: sdk.NewDecWithPrec(1, 0), // 1.00
WeightBreakingFeeMultiplier: sdk.NewDecWithPrec(1, 0), // 1.00
WeightBreakingFeeExponent: sdk.NewDecWithPrec(25, 1), // 2.5
ExternalLiquidityRatio: sdk.NewDec(1),
LpFeePortion: sdk.ZeroDec(),
StakingFeePortion: sdk.ZeroDec(),
Expand All @@ -115,7 +119,8 @@ func (suite *KeeperTestSuite) TestMsgServerJoinPool() {
SwapFee: sdk.ZeroDec(),
ExitFee: sdk.ZeroDec(),
UseOracle: true,
WeightBreakingFeeMultiplier: sdk.NewDecWithPrec(1, 0), // 1.00
WeightBreakingFeeMultiplier: sdk.NewDecWithPrec(1, 0), // 1.00
WeightBreakingFeeExponent: sdk.NewDecWithPrec(25, 1), // 2.5
ExternalLiquidityRatio: sdk.NewDec(1),
LpFeePortion: sdk.ZeroDec(),
StakingFeePortion: sdk.ZeroDec(),
Expand Down
5 changes: 5 additions & 0 deletions x/amm/keeper/msg_server_update_pool_params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func (suite *KeeperTestSuite) TestMsgServerUpdatePoolParams() {
ExitFee: sdk.ZeroDec(),
UseOracle: false,
WeightBreakingFeeMultiplier: sdk.ZeroDec(),
WeightBreakingFeeExponent: sdk.NewDecWithPrec(25, 1), // 2.5
ExternalLiquidityRatio: sdk.NewDec(1),
LpFeePortion: sdk.ZeroDec(),
StakingFeePortion: sdk.ZeroDec(),
Expand All @@ -42,6 +43,7 @@ func (suite *KeeperTestSuite) TestMsgServerUpdatePoolParams() {
ExitFee: sdk.MustNewDecFromStr("0.02"),
UseOracle: false,
WeightBreakingFeeMultiplier: sdk.ZeroDec(),
WeightBreakingFeeExponent: sdk.NewDecWithPrec(25, 1), // 2.5
ExternalLiquidityRatio: sdk.NewDec(1),
LpFeePortion: sdk.ZeroDec(),
StakingFeePortion: sdk.ZeroDec(),
Expand Down Expand Up @@ -71,6 +73,7 @@ func (suite *KeeperTestSuite) TestMsgServerUpdatePoolParams() {
ExitFee: sdk.ZeroDec(),
UseOracle: false,
WeightBreakingFeeMultiplier: sdk.ZeroDec(),
WeightBreakingFeeExponent: sdk.NewDecWithPrec(25, 1), // 2.5
ExternalLiquidityRatio: sdk.NewDec(1),
LpFeePortion: sdk.ZeroDec(),
StakingFeePortion: sdk.ZeroDec(),
Expand All @@ -83,6 +86,7 @@ func (suite *KeeperTestSuite) TestMsgServerUpdatePoolParams() {
ExitFee: sdk.ZeroDec(),
UseOracle: false,
WeightBreakingFeeMultiplier: sdk.ZeroDec(),
WeightBreakingFeeExponent: sdk.NewDecWithPrec(25, 1), // 2.5
ExternalLiquidityRatio: sdk.NewDec(1),
LpFeePortion: sdk.ZeroDec(),
StakingFeePortion: sdk.ZeroDec(),
Expand Down Expand Up @@ -112,6 +116,7 @@ func (suite *KeeperTestSuite) TestMsgServerUpdatePoolParams() {
ExitFee: sdk.ZeroDec(),
UseOracle: false,
WeightBreakingFeeMultiplier: sdk.ZeroDec(),
WeightBreakingFeeExponent: sdk.NewDecWithPrec(25, 1), // 2.5
ExternalLiquidityRatio: sdk.NewDec(1),
LpFeePortion: sdk.ZeroDec(),
StakingFeePortion: sdk.ZeroDec(),
Expand Down
1 change: 1 addition & 0 deletions x/amm/keeper/pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func createNPool(keeper *keeper.Keeper, ctx sdk.Context, n int) []types.Pool {
ExitFee: sdk.ZeroDec(),
UseOracle: false,
WeightBreakingFeeMultiplier: sdk.ZeroDec(),
WeightBreakingFeeExponent: sdk.NewDecWithPrec(25, 1), // 2.5
ExternalLiquidityRatio: sdk.ZeroDec(),
LpFeePortion: sdk.ZeroDec(),
StakingFeePortion: sdk.ZeroDec(),
Expand Down
1 change: 1 addition & 0 deletions x/amm/keeper/update_pool_for_swap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ func (suite *KeeperTestSuite) TestUpdatePoolForSwap() {
ExitFee: sdk.ZeroDec(),
UseOracle: false,
WeightBreakingFeeMultiplier: sdk.ZeroDec(),
WeightBreakingFeeExponent: sdk.NewDecWithPrec(25, 1), // 2.5
ExternalLiquidityRatio: sdk.NewDec(1),
LpFeePortion: sdk.ZeroDec(),
StakingFeePortion: sdk.ZeroDec(),
Expand Down
1 change: 1 addition & 0 deletions x/amm/types/calc_exit_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ func CalcExitPool(ctx sdk.Context, oracleKeeper OracleKeeper, pool Pool, account
weightBreakingFee := sdk.ZeroDec()
if distanceDiff.IsPositive() {
weightBreakingFee = pool.PoolParams.WeightBreakingFeeMultiplier.Mul(distanceDiff)
// TODO: weight breaking fee might need to be changed for exit pool
}

tokenOutAmount := oracleOutAmount.Mul(sdk.OneDec().Sub(weightBreakingFee)).RoundInt()
Expand Down
1 change: 1 addition & 0 deletions x/amm/types/pool_join_pool_no_swap.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ func (p *Pool) JoinPool(ctx sdk.Context, oracleKeeper OracleKeeper, accountedPoo
weightBreakingFee := sdk.ZeroDec()
if distanceDiff.IsPositive() {
weightBreakingFee = p.PoolParams.WeightBreakingFeeMultiplier.Mul(distanceDiff)
// TODO: weight breaking fee might need to be changed for exit pool
}
weightBalanceBonus := sdk.ZeroDec()
if initialWeightDistance.GT(p.PoolParams.ThresholdWeightDifference) && distanceDiff.IsNegative() {
Expand Down
Loading

0 comments on commit d2bb3f1

Please sign in to comment.