From 9482221e189f34bfe0a098f723320a54247e17af Mon Sep 17 00:00:00 2001 From: Cosmic Vagabond <121588426+cosmic-vagabond@users.noreply.github.com> Date: Thu, 24 Oct 2024 23:18:16 +0200 Subject: [PATCH] feat(amm): weight recovery reward applied to weight balance bonuses (#870) * feat(amm): weight recovery reward applied to weight balance bonuses * test(amm): fix tests * test(amm): fix tests * fix: setup handler * test(amm): fix tests * test(perpetual): fix test --- app/setup_handlers.go | 3 +- proto/elys/amm/pool.proto | 13 + proto/elys/amm/pool_params.proto | 39 +- x/amm/client/cli/query_pool_test.go | 1 + x/amm/keeper/msg_server_create_pool_test.go | 5 + x/amm/keeper/msg_server_exit_pool_test.go | 8 +- x/amm/keeper/msg_server_join_pool_test.go | 5 + .../msg_server_update_pool_params_test.go | 5 + x/amm/keeper/pool.go | 16 + x/amm/keeper/pool_test.go | 1 + x/amm/migrations/v5_migration.go | 29 +- x/amm/types/calc_exit_pool.go | 23 +- x/amm/types/pool.pb.go | 549 +++++++++++++- x/amm/types/pool_exit_pool.go | 2 +- x/amm/types/pool_join_pool.go | 6 +- x/amm/types/pool_params.pb.go | 667 +++++++++++++++++- x/amm/types/swap_in_amt_given_out.go | 27 +- x/amm/types/swap_in_amt_given_out_test.go | 3 +- x/amm/types/swap_out_amt_given_in.go | 30 +- x/amm/types/swap_out_amt_given_in_test.go | 3 +- x/amm/types/utils.go | 11 +- x/perpetual/keeper/get_amm_pool_test.go | 1 + 22 files changed, 1310 insertions(+), 137 deletions(-) diff --git a/app/setup_handlers.go b/app/setup_handlers.go index 023a5d28f..d37ffa1bd 100644 --- a/app/setup_handlers.go +++ b/app/setup_handlers.go @@ -15,7 +15,7 @@ const ( ) // make sure to update these when you upgrade the version -var NextVersion = "v0.48.0" +var NextVersion = "v0.49.0" func SetupHandlers(app *ElysApp) { setUpgradeHandler(app) @@ -30,6 +30,7 @@ func setUpgradeHandler(app *ElysApp) { app.Logger().Info("Running upgrade handler for " + version.Version) if version.Version == NextVersion || version.Version == LocalNetVersion { + // Add any logic here to run when the chain is upgraded to the new version } diff --git a/proto/elys/amm/pool.proto b/proto/elys/amm/pool.proto index 7802eeaa0..3ecf7033a 100644 --- a/proto/elys/amm/pool.proto +++ b/proto/elys/amm/pool.proto @@ -8,6 +8,19 @@ import "gogoproto/gogo.proto"; import "cosmos/base/v1beta1/coin.proto"; import "cosmos_proto/cosmos.proto"; +message LegacyPool { + uint64 pool_id = 1; + string address = 2; + LegacyPoolParams pool_params = 3 [(gogoproto.nullable) = false]; + cosmos.base.v1beta1.Coin total_shares = 4 [(gogoproto.nullable) = false]; + repeated PoolAsset pool_assets = 5 [(gogoproto.nullable) = false]; + string total_weight = 6 [ + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", + (gogoproto.nullable) = false + ]; + string rebalance_treasury = 7; +} + message Pool { uint64 pool_id = 1; string address = 2; diff --git a/proto/elys/amm/pool_params.proto b/proto/elys/amm/pool_params.proto index 0c0518411..88d35dcf9 100644 --- a/proto/elys/amm/pool_params.proto +++ b/proto/elys/amm/pool_params.proto @@ -6,7 +6,7 @@ import "cosmos_proto/cosmos.proto"; option go_package = "github.com/elys-network/elys/x/amm/types"; -message PoolParams { +message LegacyPoolParams { string swap_fee = 1 [ (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false @@ -38,3 +38,40 @@ message PoolParams { ]; string fee_denom = 8; // denom for fee collection } + +message PoolParams { + string swap_fee = 1 [ + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", + (gogoproto.nullable) = false + ]; + string exit_fee = 2 [ + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", + (gogoproto.nullable) = false + ]; + bool use_oracle = 3; + string weight_breaking_fee_multiplier = 4 [ + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", + (gogoproto.nullable) = false + ]; + string weight_breaking_fee_exponent = 5 [ + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", + (gogoproto.nullable) = false + ]; + string external_liquidity_ratio = 6 [ + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", + (gogoproto.nullable) = false + ]; + string weight_recovery_fee_portion = 7 [ + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", + (gogoproto.nullable) = false + ]; + string threshold_weight_difference = 8 [ + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", + (gogoproto.nullable) = false + ]; + string weight_breaking_fee_portion = 9 [ + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", + (gogoproto.nullable) = false + ]; + string fee_denom = 10; // denom for fee collection +} diff --git a/x/amm/client/cli/query_pool_test.go b/x/amm/client/cli/query_pool_test.go index 90d5c1976..afd94e2af 100644 --- a/x/amm/client/cli/query_pool_test.go +++ b/x/amm/client/cli/query_pool_test.go @@ -39,6 +39,7 @@ func networkWithPoolObjects(t *testing.T, n int) (*network.Network, []types.Pool ExternalLiquidityRatio: sdk.NewDec(1), WeightRecoveryFeePortion: sdk.NewDecWithPrec(10, 2), // 10% ThresholdWeightDifference: sdk.ZeroDec(), + WeightBreakingFeePortion: sdk.NewDecWithPrec(50, 2), // 50% FeeDenom: ptypes.BaseCurrency, }, } diff --git a/x/amm/keeper/msg_server_create_pool_test.go b/x/amm/keeper/msg_server_create_pool_test.go index dbb253a52..17ab0362a 100644 --- a/x/amm/keeper/msg_server_create_pool_test.go +++ b/x/amm/keeper/msg_server_create_pool_test.go @@ -34,6 +34,7 @@ func (suite *KeeperTestSuite) TestMsgServerCreatePool() { ExternalLiquidityRatio: sdk.NewDec(1), WeightRecoveryFeePortion: sdk.NewDecWithPrec(10, 2), // 10% ThresholdWeightDifference: sdk.ZeroDec(), + WeightBreakingFeePortion: sdk.NewDecWithPrec(50, 2), // 50% FeeDenom: ptypes.BaseCurrency, }, poolAssets: []types.PoolAsset{ @@ -63,6 +64,7 @@ func (suite *KeeperTestSuite) TestMsgServerCreatePool() { ExternalLiquidityRatio: sdk.NewDec(1), WeightRecoveryFeePortion: sdk.NewDecWithPrec(10, 2), // 10% ThresholdWeightDifference: sdk.ZeroDec(), + WeightBreakingFeePortion: sdk.NewDecWithPrec(50, 2), // 50% FeeDenom: ptypes.BaseCurrency, }, poolAssets: []types.PoolAsset{ @@ -92,6 +94,7 @@ func (suite *KeeperTestSuite) TestMsgServerCreatePool() { ExternalLiquidityRatio: sdk.NewDec(1), WeightRecoveryFeePortion: sdk.NewDecWithPrec(10, 2), // 10% ThresholdWeightDifference: sdk.ZeroDec(), + WeightBreakingFeePortion: sdk.NewDecWithPrec(50, 2), // 50% FeeDenom: ptypes.BaseCurrency, }, poolAssets: []types.PoolAsset{ @@ -121,6 +124,7 @@ func (suite *KeeperTestSuite) TestMsgServerCreatePool() { ExternalLiquidityRatio: sdk.NewDec(1), WeightRecoveryFeePortion: sdk.NewDecWithPrec(10, 2), // 10% ThresholdWeightDifference: sdk.ZeroDec(), + WeightBreakingFeePortion: sdk.NewDecWithPrec(50, 2), // 50% FeeDenom: ptypes.BaseCurrency, }, poolAssets: []types.PoolAsset{ @@ -150,6 +154,7 @@ func (suite *KeeperTestSuite) TestMsgServerCreatePool() { ExternalLiquidityRatio: sdk.NewDec(1), WeightRecoveryFeePortion: sdk.NewDecWithPrec(10, 2), // 10% ThresholdWeightDifference: sdk.ZeroDec(), + WeightBreakingFeePortion: sdk.NewDecWithPrec(50, 2), // 50% FeeDenom: ptypes.BaseCurrency, }, poolAssets: []types.PoolAsset{ diff --git a/x/amm/keeper/msg_server_exit_pool_test.go b/x/amm/keeper/msg_server_exit_pool_test.go index 1b59575ca..fc88ec208 100644 --- a/x/amm/keeper/msg_server_exit_pool_test.go +++ b/x/amm/keeper/msg_server_exit_pool_test.go @@ -36,6 +36,7 @@ func (suite *KeeperTestSuite) TestMsgServerExitPool() { ExternalLiquidityRatio: sdk.NewDec(1), WeightRecoveryFeePortion: sdk.NewDecWithPrec(10, 2), // 10% ThresholdWeightDifference: sdk.ZeroDec(), + WeightBreakingFeePortion: sdk.NewDecWithPrec(50, 2), // 50% FeeDenom: ptypes.BaseCurrency, }, shareInAmount: types.OneShare.Quo(sdk.NewInt(5)), @@ -56,6 +57,7 @@ func (suite *KeeperTestSuite) TestMsgServerExitPool() { ExternalLiquidityRatio: sdk.NewDec(1), WeightRecoveryFeePortion: sdk.NewDecWithPrec(10, 2), // 10% ThresholdWeightDifference: sdk.ZeroDec(), + WeightBreakingFeePortion: sdk.NewDecWithPrec(50, 2), // 50% FeeDenom: ptypes.BaseCurrency, }, shareInAmount: types.OneShare.Quo(sdk.NewInt(5)), @@ -76,6 +78,7 @@ func (suite *KeeperTestSuite) TestMsgServerExitPool() { ExternalLiquidityRatio: sdk.NewDec(1), WeightRecoveryFeePortion: sdk.NewDecWithPrec(10, 2), // 10% ThresholdWeightDifference: sdk.NewDecWithPrec(2, 1), // 20% + WeightBreakingFeePortion: sdk.NewDecWithPrec(50, 2), // 50% FeeDenom: ptypes.BaseCurrency, }, shareInAmount: types.OneShare.Quo(sdk.NewInt(10)), @@ -97,13 +100,14 @@ func (suite *KeeperTestSuite) TestMsgServerExitPool() { ExternalLiquidityRatio: sdk.NewDec(1), WeightRecoveryFeePortion: sdk.NewDecWithPrec(10, 2), // 10% ThresholdWeightDifference: sdk.NewDecWithPrec(2, 1), // 20% + WeightBreakingFeePortion: sdk.NewDecWithPrec(50, 2), // 50% FeeDenom: ptypes.BaseCurrency, }, shareInAmount: types.OneShare.Quo(sdk.NewInt(10)), tokenOutDenom: ptypes.BaseCurrency, - minAmountsOut: sdk.Coins{sdk.NewInt64Coin(ptypes.BaseCurrency, 100000)}, + minAmountsOut: sdk.Coins{sdk.NewInt64Coin(ptypes.BaseCurrency, 86881)}, // expSenderBalance: sdk.Coins{sdk.NewInt64Coin(ptypes.BaseCurrency, 99197)}, // slippage enabled - expSenderBalance: sdk.Coins{sdk.NewInt64Coin(ptypes.BaseCurrency, 100000)}, // slippage disabled + expSenderBalance: sdk.Coins{sdk.NewInt64Coin(ptypes.BaseCurrency, 86881)}, // slippage disabled expPass: true, }, } { diff --git a/x/amm/keeper/msg_server_join_pool_test.go b/x/amm/keeper/msg_server_join_pool_test.go index 63ce5fb8a..f9c012377 100644 --- a/x/amm/keeper/msg_server_join_pool_test.go +++ b/x/amm/keeper/msg_server_join_pool_test.go @@ -35,6 +35,7 @@ func (suite *KeeperTestSuite) TestMsgServerJoinPool() { ExternalLiquidityRatio: sdk.NewDec(1), WeightRecoveryFeePortion: sdk.NewDecWithPrec(10, 2), // 10% ThresholdWeightDifference: sdk.ZeroDec(), + WeightBreakingFeePortion: sdk.NewDecWithPrec(50, 2), // 50% FeeDenom: ptypes.BaseCurrency, }, shareOutAmount: types.OneShare.Quo(sdk.NewInt(5)), @@ -55,6 +56,7 @@ func (suite *KeeperTestSuite) TestMsgServerJoinPool() { ExternalLiquidityRatio: sdk.NewDec(1), WeightRecoveryFeePortion: sdk.NewDecWithPrec(10, 2), // 10% ThresholdWeightDifference: sdk.ZeroDec(), + WeightBreakingFeePortion: sdk.NewDecWithPrec(50, 2), // 50% FeeDenom: ptypes.BaseCurrency, }, shareOutAmount: types.OneShare.Quo(sdk.NewInt(5)), @@ -75,6 +77,7 @@ func (suite *KeeperTestSuite) TestMsgServerJoinPool() { ExternalLiquidityRatio: sdk.NewDec(1), WeightRecoveryFeePortion: sdk.NewDecWithPrec(10, 2), // 10% ThresholdWeightDifference: sdk.NewDecWithPrec(2, 1), // 20% + WeightBreakingFeePortion: sdk.NewDecWithPrec(50, 2), // 50% FeeDenom: ptypes.BaseCurrency, }, // shareOutAmount: sdk.NewInt(694444166666666666), // weight breaking fee - slippage enable @@ -96,6 +99,7 @@ func (suite *KeeperTestSuite) TestMsgServerJoinPool() { ExternalLiquidityRatio: sdk.NewDec(1), WeightRecoveryFeePortion: sdk.NewDecWithPrec(10, 2), // 10% ThresholdWeightDifference: sdk.NewDecWithPrec(2, 1), // 20% + WeightBreakingFeePortion: sdk.NewDecWithPrec(50, 2), // 50% FeeDenom: ptypes.BaseCurrency, }, // shareOutAmount: sdk.NewInt(805987500000000000), // weight recovery direction - slippage enable @@ -117,6 +121,7 @@ func (suite *KeeperTestSuite) TestMsgServerJoinPool() { ExternalLiquidityRatio: sdk.NewDec(1), WeightRecoveryFeePortion: sdk.NewDecWithPrec(10, 2), // 10% ThresholdWeightDifference: sdk.NewDecWithPrec(2, 1), // 20% + WeightBreakingFeePortion: sdk.NewDecWithPrec(50, 2), // 50% FeeDenom: ptypes.BaseCurrency, }, shareOutAmount: sdk.NewInt(2000000000000000000), diff --git a/x/amm/keeper/msg_server_update_pool_params_test.go b/x/amm/keeper/msg_server_update_pool_params_test.go index ff946fc1f..1d91e0fa1 100644 --- a/x/amm/keeper/msg_server_update_pool_params_test.go +++ b/x/amm/keeper/msg_server_update_pool_params_test.go @@ -34,6 +34,7 @@ func (suite *KeeperTestSuite) TestMsgServerUpdatePoolParams() { ExternalLiquidityRatio: sdk.NewDec(1), WeightRecoveryFeePortion: sdk.NewDecWithPrec(10, 2), // 10% ThresholdWeightDifference: sdk.ZeroDec(), + WeightBreakingFeePortion: sdk.NewDecWithPrec(50, 2), // 50% FeeDenom: ptypes.BaseCurrency, }, updatedPoolParams: types.PoolParams{ @@ -45,6 +46,7 @@ func (suite *KeeperTestSuite) TestMsgServerUpdatePoolParams() { ExternalLiquidityRatio: sdk.NewDec(1), WeightRecoveryFeePortion: sdk.NewDecWithPrec(10, 2), // 10% ThresholdWeightDifference: sdk.ZeroDec(), + WeightBreakingFeePortion: sdk.NewDecWithPrec(50, 2), // 50% FeeDenom: "feedenom", }, poolAssets: []types.PoolAsset{ @@ -73,6 +75,7 @@ func (suite *KeeperTestSuite) TestMsgServerUpdatePoolParams() { ExternalLiquidityRatio: sdk.NewDec(1), WeightRecoveryFeePortion: sdk.NewDecWithPrec(10, 2), // 10% ThresholdWeightDifference: sdk.ZeroDec(), + WeightBreakingFeePortion: sdk.NewDecWithPrec(50, 2), // 50% FeeDenom: ptypes.BaseCurrency, }, updatedPoolParams: types.PoolParams{ @@ -84,6 +87,7 @@ func (suite *KeeperTestSuite) TestMsgServerUpdatePoolParams() { ExternalLiquidityRatio: sdk.NewDec(1), WeightRecoveryFeePortion: sdk.NewDecWithPrec(10, 2), // 10% ThresholdWeightDifference: sdk.ZeroDec(), + WeightBreakingFeePortion: sdk.NewDecWithPrec(50, 2), // 50% FeeDenom: ptypes.BaseCurrency, }, poolAssets: []types.PoolAsset{ @@ -112,6 +116,7 @@ func (suite *KeeperTestSuite) TestMsgServerUpdatePoolParams() { ExternalLiquidityRatio: sdk.NewDec(1), WeightRecoveryFeePortion: sdk.NewDecWithPrec(10, 2), // 10% ThresholdWeightDifference: sdk.ZeroDec(), + WeightBreakingFeePortion: sdk.NewDecWithPrec(50, 2), // 50% FeeDenom: ptypes.BaseCurrency, }, poolAssets: []types.PoolAsset{ diff --git a/x/amm/keeper/pool.go b/x/amm/keeper/pool.go index 28a7608d0..48846de0a 100644 --- a/x/amm/keeper/pool.go +++ b/x/amm/keeper/pool.go @@ -50,6 +50,22 @@ func (k Keeper) GetAllPool(ctx sdk.Context) (list []types.Pool) { return } +// GetAllLegacyPool returns all legacy pool +func (k Keeper) GetAllLegacyPool(ctx sdk.Context) (list []types.LegacyPool) { + store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.PoolKeyPrefix)) + iterator := sdk.KVStorePrefixIterator(store, []byte{}) + + defer iterator.Close() + + for ; iterator.Valid(); iterator.Next() { + var val types.LegacyPool + k.cdc.MustUnmarshal(iterator.Value(), &val) + list = append(list, val) + } + + return +} + // GetLatestPool retrieves the latest pool item from the list of pools func (k Keeper) GetLatestPool(ctx sdk.Context) (val types.Pool, found bool) { store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.PoolKeyPrefix)) diff --git a/x/amm/keeper/pool_test.go b/x/amm/keeper/pool_test.go index 4a3253d82..fe3cc7af9 100644 --- a/x/amm/keeper/pool_test.go +++ b/x/amm/keeper/pool_test.go @@ -30,6 +30,7 @@ func createNPool(keeper *keeper.Keeper, ctx sdk.Context, n int) []types.Pool { ExternalLiquidityRatio: sdk.ZeroDec(), WeightRecoveryFeePortion: sdk.NewDecWithPrec(10, 2), // 10% ThresholdWeightDifference: sdk.ZeroDec(), + WeightBreakingFeePortion: sdk.NewDecWithPrec(50, 2), // 50% FeeDenom: ptypes.BaseCurrency, } diff --git a/x/amm/migrations/v5_migration.go b/x/amm/migrations/v5_migration.go index a3278f424..dba475121 100644 --- a/x/amm/migrations/v5_migration.go +++ b/x/amm/migrations/v5_migration.go @@ -7,10 +7,37 @@ import ( ) func (m Migrator) V5Migration(ctx sdk.Context) error { - m.keeper.SetParams(ctx, types.Params{ + m.keeper.SetParams(ctx, types.Params{ PoolCreationFee: math.NewInt(10_000_000), SlippageTrackDuration: 86400*7, EnableBaseCurrencyPairedPoolOnly: false, }) + + pools := m.keeper.GetAllLegacyPool(ctx) + for _, pool := range pools { + newPool := types.Pool{ + PoolId: pool.PoolId, + Address: pool.Address, + PoolParams: types.PoolParams{ + SwapFee: pool.PoolParams.SwapFee, + ExitFee: pool.PoolParams.ExitFee, + UseOracle: pool.PoolParams.UseOracle, + WeightBreakingFeeMultiplier: pool.PoolParams.WeightBreakingFeeMultiplier, + WeightBreakingFeeExponent: pool.PoolParams.WeightBreakingFeeExponent, + ExternalLiquidityRatio: pool.PoolParams.ExternalLiquidityRatio, + WeightRecoveryFeePortion: pool.PoolParams.WeightRecoveryFeePortion, + ThresholdWeightDifference: pool.PoolParams.ThresholdWeightDifference, + WeightBreakingFeePortion: sdk.NewDecWithPrec(50, 2), // 50% + FeeDenom: pool.PoolParams.FeeDenom, + }, + TotalShares: pool.TotalShares, + PoolAssets: pool.PoolAssets, + TotalWeight: pool.TotalWeight, + RebalanceTreasury: pool.RebalanceTreasury, + } + + m.keeper.RemovePool(ctx, pool.PoolId) + m.keeper.SetPool(ctx, newPool) + } return nil } diff --git a/x/amm/types/calc_exit_pool.go b/x/amm/types/calc_exit_pool.go index 3435e3696..757c4c896 100644 --- a/x/amm/types/calc_exit_pool.go +++ b/x/amm/types/calc_exit_pool.go @@ -95,8 +95,7 @@ func CalcExitPool( // refundedShares = exitingShares * (1 - exit fee) // with 0 exit fee optimization - var refundedShares sdk.Dec - refundedShares = sdk.NewDecFromInt(exitingShares) + refundedShares := sdk.NewDecFromInt(exitingShares) shareOutRatio := refundedShares.QuoInt(totalShares.Amount) // exitedCoins = shareOutRatio * pool liquidity @@ -133,21 +132,15 @@ func CalcExitPool( weightDistance := pool.WeightDistanceFromTarget(ctx, oracleKeeper, newAssetPools) distanceDiff := weightDistance.Sub(initialWeightDistance) - weightBreakingFee := sdk.ZeroDec() - if distanceDiff.IsPositive() { - // old weight breaking fee implementation - // weightBreakingFee = pool.PoolParams.WeightBreakingFeeMultiplier.Mul(distanceDiff) - // target weight - targetWeightOut := NormalizedWeight(ctx, pool.PoolAssets, tokenOutDenom) - targetWeightIn := sdk.OneDec().Sub(targetWeightOut) + // target weight + targetWeightOut := NormalizedWeight(ctx, pool.PoolAssets, tokenOutDenom) + targetWeightIn := sdk.OneDec().Sub(targetWeightOut) - // weight breaking fee as in Plasma pool - weightOut := OracleAssetWeight(ctx, oracleKeeper, newAssetPools, tokenOutDenom) - weightIn := sdk.OneDec().Sub(weightOut) - - weightBreakingFee = GetWeightBreakingFee(weightIn, weightOut, targetWeightIn, targetWeightOut, pool.PoolParams) - } + // weight breaking fee as in Plasma pool + weightOut := OracleAssetWeight(ctx, oracleKeeper, newAssetPools, tokenOutDenom) + weightIn := sdk.OneDec().Sub(weightOut) + weightBreakingFee := GetWeightBreakingFee(weightIn, weightOut, targetWeightIn, targetWeightOut, pool.PoolParams, distanceDiff) tokenOutAmount := oracleOutAmount.Mul(sdk.OneDec().Sub(weightBreakingFee)).RoundInt() return sdk.Coins{sdk.NewCoin(tokenOutDenom, tokenOutAmount)}, weightBreakingFee.Neg(), nil diff --git a/x/amm/types/pool.pb.go b/x/amm/types/pool.pb.go index 69efab666..bc901c1a6 100644 --- a/x/amm/types/pool.pb.go +++ b/x/amm/types/pool.pb.go @@ -26,6 +26,91 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package +type LegacyPool struct { + PoolId uint64 `protobuf:"varint,1,opt,name=pool_id,json=poolId,proto3" json:"pool_id,omitempty"` + Address string `protobuf:"bytes,2,opt,name=address,proto3" json:"address,omitempty"` + PoolParams LegacyPoolParams `protobuf:"bytes,3,opt,name=pool_params,json=poolParams,proto3" json:"pool_params"` + TotalShares types.Coin `protobuf:"bytes,4,opt,name=total_shares,json=totalShares,proto3" json:"total_shares"` + PoolAssets []PoolAsset `protobuf:"bytes,5,rep,name=pool_assets,json=poolAssets,proto3" json:"pool_assets"` + TotalWeight github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,6,opt,name=total_weight,json=totalWeight,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"total_weight"` + RebalanceTreasury string `protobuf:"bytes,7,opt,name=rebalance_treasury,json=rebalanceTreasury,proto3" json:"rebalance_treasury,omitempty"` +} + +func (m *LegacyPool) Reset() { *m = LegacyPool{} } +func (m *LegacyPool) String() string { return proto.CompactTextString(m) } +func (*LegacyPool) ProtoMessage() {} +func (*LegacyPool) Descriptor() ([]byte, []int) { + return fileDescriptor_3ac3be9a215271f9, []int{0} +} +func (m *LegacyPool) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *LegacyPool) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_LegacyPool.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *LegacyPool) XXX_Merge(src proto.Message) { + xxx_messageInfo_LegacyPool.Merge(m, src) +} +func (m *LegacyPool) XXX_Size() int { + return m.Size() +} +func (m *LegacyPool) XXX_DiscardUnknown() { + xxx_messageInfo_LegacyPool.DiscardUnknown(m) +} + +var xxx_messageInfo_LegacyPool proto.InternalMessageInfo + +func (m *LegacyPool) GetPoolId() uint64 { + if m != nil { + return m.PoolId + } + return 0 +} + +func (m *LegacyPool) GetAddress() string { + if m != nil { + return m.Address + } + return "" +} + +func (m *LegacyPool) GetPoolParams() LegacyPoolParams { + if m != nil { + return m.PoolParams + } + return LegacyPoolParams{} +} + +func (m *LegacyPool) GetTotalShares() types.Coin { + if m != nil { + return m.TotalShares + } + return types.Coin{} +} + +func (m *LegacyPool) GetPoolAssets() []PoolAsset { + if m != nil { + return m.PoolAssets + } + return nil +} + +func (m *LegacyPool) GetRebalanceTreasury() string { + if m != nil { + return m.RebalanceTreasury + } + return "" +} + type Pool struct { PoolId uint64 `protobuf:"varint,1,opt,name=pool_id,json=poolId,proto3" json:"pool_id,omitempty"` Address string `protobuf:"bytes,2,opt,name=address,proto3" json:"address,omitempty"` @@ -40,7 +125,7 @@ func (m *Pool) Reset() { *m = Pool{} } func (m *Pool) String() string { return proto.CompactTextString(m) } func (*Pool) ProtoMessage() {} func (*Pool) Descriptor() ([]byte, []int) { - return fileDescriptor_3ac3be9a215271f9, []int{0} + return fileDescriptor_3ac3be9a215271f9, []int{1} } func (m *Pool) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -120,7 +205,7 @@ func (m *PoolExtraInfo) Reset() { *m = PoolExtraInfo{} } func (m *PoolExtraInfo) String() string { return proto.CompactTextString(m) } func (*PoolExtraInfo) ProtoMessage() {} func (*PoolExtraInfo) Descriptor() ([]byte, []int) { - return fileDescriptor_3ac3be9a215271f9, []int{1} + return fileDescriptor_3ac3be9a215271f9, []int{2} } func (m *PoolExtraInfo) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -159,7 +244,7 @@ func (m *OraclePoolSlippageTrack) Reset() { *m = OraclePoolSlippageTrack func (m *OraclePoolSlippageTrack) String() string { return proto.CompactTextString(m) } func (*OraclePoolSlippageTrack) ProtoMessage() {} func (*OraclePoolSlippageTrack) Descriptor() ([]byte, []int) { - return fileDescriptor_3ac3be9a215271f9, []int{2} + return fileDescriptor_3ac3be9a215271f9, []int{3} } func (m *OraclePoolSlippageTrack) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -210,6 +295,7 @@ func (m *OraclePoolSlippageTrack) GetTracked() github_com_cosmos_cosmos_sdk_type } func init() { + proto.RegisterType((*LegacyPool)(nil), "elys.amm.LegacyPool") proto.RegisterType((*Pool)(nil), "elys.amm.Pool") proto.RegisterType((*PoolExtraInfo)(nil), "elys.amm.PoolExtraInfo") proto.RegisterType((*OraclePoolSlippageTrack)(nil), "elys.amm.OraclePoolSlippageTrack") @@ -218,41 +304,129 @@ func init() { func init() { proto.RegisterFile("elys/amm/pool.proto", fileDescriptor_3ac3be9a215271f9) } var fileDescriptor_3ac3be9a215271f9 = []byte{ - // 532 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x53, 0xcf, 0x6e, 0x13, 0x3f, - 0x10, 0xce, 0x36, 0xf9, 0x25, 0xbf, 0x3a, 0x05, 0x09, 0xb7, 0x52, 0xb7, 0x11, 0xda, 0x44, 0x39, - 0xa0, 0x5c, 0xe2, 0xa5, 0xe5, 0x06, 0x17, 0x08, 0x70, 0xc8, 0x89, 0xb0, 0x8d, 0x84, 0xc4, 0x65, - 0xe5, 0xec, 0x0e, 0xc9, 0x2a, 0xde, 0xb5, 0x65, 0xbb, 0x7f, 0xf2, 0x16, 0xbc, 0x05, 0x12, 0x2f, - 0xc0, 0x2b, 0xf4, 0xd8, 0x23, 0xe2, 0x50, 0x50, 0xf2, 0x12, 0x1c, 0x91, 0xbd, 0x4e, 0x49, 0x0e, - 0x20, 0x7a, 0xda, 0x9d, 0xf9, 0xfc, 0x7d, 0xf3, 0xcd, 0x8c, 0x8d, 0xf6, 0x81, 0x2d, 0x54, 0x48, - 0xf3, 0x3c, 0x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- 0xfe, 0xc1, 0xbc, 0x21, 0xa8, 0x68, 0xad, 0x3d, 0x18, 0x5c, 0x2d, 0x03, 0xef, 0x7a, 0x19, 0x78, - 0x3f, 0x96, 0x81, 0xf7, 0x71, 0x15, 0x54, 0xae, 0x57, 0x41, 0xe5, 0xeb, 0x2a, 0xa8, 0xbc, 0xdf, - 0x14, 0x33, 0x17, 0xa6, 0x5f, 0x80, 0xbe, 0xe0, 0x72, 0x6e, 0x83, 0xf0, 0xd2, 0x3e, 0x3f, 0x2b, - 0x39, 0xa9, 0xdb, 0x97, 0xf2, 0xe4, 0x57, 0x00, 0x00, 0x00, 0xff, 0xff, 0x54, 0xf0, 0x44, 0xba, - 0xd2, 0x03, 0x00, 0x00, + // 561 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xec, 0x54, 0xcd, 0x6e, 0xd3, 0x40, + 0x10, 0x8e, 0x9b, 0x90, 0xd0, 0x4d, 0x41, 0x62, 0x5b, 0xa9, 0x6e, 0x84, 0x9c, 0x28, 0x07, 0x94, + 0x4b, 0x6c, 0x5a, 0x6e, 0x70, 0xa1, 0x01, 0x0e, 0x91, 0x90, 0x08, 0x6e, 0x24, 0x24, 0x2e, 0xd6, + 0xc6, 0x1e, 0x1c, 0x2b, 0xb6, 0x77, 0xb5, 0xbb, 0xfd, 0xc9, 0x9d, 0x07, 0xe0, 0x2d, 0x90, 0x78, + 0x01, 0x5e, 0xa1, 0xc7, 0x1e, 0x11, 0x87, 0x82, 0x92, 0x97, 0xe0, 0x88, 0x76, 0xbd, 0x69, 0x12, + 0x89, 0x22, 0xca, 0xb9, 0x27, 0x7b, 0xe6, 0xdb, 0xf9, 0xe6, 0x9b, 0x6f, 0x56, 0x8b, 0xb6, 0x21, + 0x9d, 0x0a, 0x8f, 0x64, 0x99, 0xc7, 0x28, 0x4d, 0x5d, 0xc6, 0xa9, 0xa4, 0xf8, 0xae, 0x4a, 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8, 0x26, 0x55, 0x3d, 0x44, + 0x76, 0x59, 0xaf, 0xed, 0x2f, 0x9b, 0x7f, 0xac, 0xc4, 0x7f, 0xf9, 0xd1, 0xec, 0xfc, 0x83, 0x78, + 0x55, 0x20, 0xfc, 0x05, 0x77, 0xaf, 0x77, 0x3e, 0x73, 0xac, 0x8b, 0x99, 0x63, 0xfd, 0x9c, 0x39, + 0xd6, 0xa7, 0xb9, 0x53, 0xba, 0x98, 0x3b, 0xa5, 0x6f, 0x73, 0xa7, 0xf4, 0x7e, 0x95, 0x4c, 0x5d, + 0x98, 0x6e, 0x0e, 0xf2, 0x94, 0xf2, 0x89, 0x0e, 0xbc, 0x33, 0xfd, 0x0a, 0x6a, 0xca, 0x51, 0x55, + 0x3f, 0x58, 0x4f, 0x7e, 0x07, 0x00, 0x00, 0xff, 0xff, 0xb9, 0x95, 0x53, 0xf5, 0x59, 0x05, 0x00, + 0x00, +} + +func (m *LegacyPool) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *LegacyPool) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *LegacyPool) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.RebalanceTreasury) > 0 { + i -= len(m.RebalanceTreasury) + copy(dAtA[i:], m.RebalanceTreasury) + i = encodeVarintPool(dAtA, i, uint64(len(m.RebalanceTreasury))) + i-- + dAtA[i] = 0x3a + } + { + size := m.TotalWeight.Size() + i -= size + if _, err := m.TotalWeight.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintPool(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x32 + if len(m.PoolAssets) > 0 { + for iNdEx := len(m.PoolAssets) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.PoolAssets[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintPool(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x2a + } + } + { + size, err := m.TotalShares.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintPool(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x22 + { + size, err := m.PoolParams.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintPool(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + if len(m.Address) > 0 { + i -= len(m.Address) + copy(dAtA[i:], m.Address) + i = encodeVarintPool(dAtA, i, uint64(len(m.Address))) + i-- + dAtA[i] = 0x12 + } + if m.PoolId != 0 { + i = encodeVarintPool(dAtA, i, uint64(m.PoolId)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil } func (m *Pool) Marshal() (dAtA []byte, err error) { @@ -442,6 +616,38 @@ func encodeVarintPool(dAtA []byte, offset int, v uint64) int { dAtA[offset] = uint8(v) return base } +func (m *LegacyPool) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.PoolId != 0 { + n += 1 + sovPool(uint64(m.PoolId)) + } + l = len(m.Address) + if l > 0 { + n += 1 + l + sovPool(uint64(l)) + } + l = m.PoolParams.Size() + n += 1 + l + sovPool(uint64(l)) + l = m.TotalShares.Size() + n += 1 + l + sovPool(uint64(l)) + if len(m.PoolAssets) > 0 { + for _, e := range m.PoolAssets { + l = e.Size() + n += 1 + l + sovPool(uint64(l)) + } + } + l = m.TotalWeight.Size() + n += 1 + l + sovPool(uint64(l)) + l = len(m.RebalanceTreasury) + if l > 0 { + n += 1 + l + sovPool(uint64(l)) + } + return n +} + func (m *Pool) Size() (n int) { if m == nil { return 0 @@ -514,6 +720,273 @@ func sovPool(x uint64) (n int) { func sozPool(x uint64) (n int) { return sovPool(uint64((x << 1) ^ uint64((int64(x) >> 63)))) } +func (m *LegacyPool) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPool + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: LegacyPool: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: LegacyPool: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field PoolId", wireType) + } + m.PoolId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPool + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.PoolId |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Address", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPool + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthPool + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthPool + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Address = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field PoolParams", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPool + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthPool + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthPool + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.PoolParams.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field TotalShares", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPool + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthPool + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthPool + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.TotalShares.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field PoolAssets", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPool + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthPool + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthPool + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.PoolAssets = append(m.PoolAssets, PoolAsset{}) + if err := m.PoolAssets[len(m.PoolAssets)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 6: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field TotalWeight", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPool + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthPool + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthPool + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.TotalWeight.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 7: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field RebalanceTreasury", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPool + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthPool + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthPool + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.RebalanceTreasury = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipPool(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthPool + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func (m *Pool) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 diff --git a/x/amm/types/pool_exit_pool.go b/x/amm/types/pool_exit_pool.go index 7d63de1d4..96234286c 100644 --- a/x/amm/types/pool_exit_pool.go +++ b/x/amm/types/pool_exit_pool.go @@ -20,7 +20,7 @@ func (p *Pool) ExitPool(ctx sdk.Context, oracleKeeper OracleKeeper, accountedPoo // exitPool exits the pool given exitingCoins and exitingShares. // updates the pool's liquidity and totalShares. -func (p *Pool) processExitPool(ctx sdk.Context, exitingCoins sdk.Coins, exitingShares math.Int) error { +func (p *Pool) processExitPool(_ sdk.Context, exitingCoins sdk.Coins, exitingShares math.Int) error { balances := p.GetTotalPoolLiquidity().Sub(exitingCoins...) if err := p.UpdatePoolAssetBalances(balances); err != nil { return err diff --git a/x/amm/types/pool_join_pool.go b/x/amm/types/pool_join_pool.go index 5c73a2f5b..caa629623 100644 --- a/x/amm/types/pool_join_pool.go +++ b/x/amm/types/pool_join_pool.go @@ -185,11 +185,9 @@ func (p *Pool) JoinPool( weightDistance := p.WeightDistanceFromTarget(ctx, oracleKeeper, newAssetPools) distanceDiff := weightDistance.Sub(initialWeightDistance) + weightBreakingFee := sdk.ZeroDec() if distanceDiff.IsPositive() { - // old weight breaking fee implementation - // weightBreakingFee = p.PoolParams.WeightBreakingFeeMultiplier.Mul(distanceDiff) - // we only allow tokenInDenom := tokensIn[0].Denom // target weight @@ -199,7 +197,7 @@ func (p *Pool) JoinPool( // weight breaking fee as in Plasma pool weightIn := OracleAssetWeight(ctx, oracleKeeper, newAssetPools, tokenInDenom) weightOut := sdk.OneDec().Sub(weightIn) - weightBreakingFee = GetWeightBreakingFee(weightIn, weightOut, targetWeightIn, targetWeightOut, p.PoolParams) + weightBreakingFee = GetWeightBreakingFee(weightIn, weightOut, targetWeightIn, targetWeightOut, p.PoolParams, distanceDiff) } weightBalanceBonus = weightBreakingFee.Neg() diff --git a/x/amm/types/pool_params.pb.go b/x/amm/types/pool_params.pb.go index 0c8b052dc..eddeae836 100644 --- a/x/amm/types/pool_params.pb.go +++ b/x/amm/types/pool_params.pb.go @@ -25,7 +25,7 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package -type PoolParams struct { +type LegacyPoolParams struct { SwapFee github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,1,opt,name=swap_fee,json=swapFee,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"swap_fee"` ExitFee github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,2,opt,name=exit_fee,json=exitFee,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"exit_fee"` UseOracle bool `protobuf:"varint,3,opt,name=use_oracle,json=useOracle,proto3" json:"use_oracle,omitempty"` @@ -37,11 +37,71 @@ type PoolParams struct { FeeDenom string `protobuf:"bytes,8,opt,name=fee_denom,json=feeDenom,proto3" json:"fee_denom,omitempty"` } +func (m *LegacyPoolParams) Reset() { *m = LegacyPoolParams{} } +func (m *LegacyPoolParams) String() string { return proto.CompactTextString(m) } +func (*LegacyPoolParams) ProtoMessage() {} +func (*LegacyPoolParams) Descriptor() ([]byte, []int) { + return fileDescriptor_3500125990074bc9, []int{0} +} +func (m *LegacyPoolParams) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *LegacyPoolParams) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_LegacyPoolParams.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *LegacyPoolParams) XXX_Merge(src proto.Message) { + xxx_messageInfo_LegacyPoolParams.Merge(m, src) +} +func (m *LegacyPoolParams) XXX_Size() int { + return m.Size() +} +func (m *LegacyPoolParams) XXX_DiscardUnknown() { + xxx_messageInfo_LegacyPoolParams.DiscardUnknown(m) +} + +var xxx_messageInfo_LegacyPoolParams proto.InternalMessageInfo + +func (m *LegacyPoolParams) GetUseOracle() bool { + if m != nil { + return m.UseOracle + } + return false +} + +func (m *LegacyPoolParams) GetFeeDenom() string { + if m != nil { + return m.FeeDenom + } + return "" +} + +type PoolParams struct { + SwapFee github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,1,opt,name=swap_fee,json=swapFee,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"swap_fee"` + ExitFee github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,2,opt,name=exit_fee,json=exitFee,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"exit_fee"` + UseOracle bool `protobuf:"varint,3,opt,name=use_oracle,json=useOracle,proto3" json:"use_oracle,omitempty"` + WeightBreakingFeeMultiplier github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,4,opt,name=weight_breaking_fee_multiplier,json=weightBreakingFeeMultiplier,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"weight_breaking_fee_multiplier"` + WeightBreakingFeeExponent github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,5,opt,name=weight_breaking_fee_exponent,json=weightBreakingFeeExponent,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"weight_breaking_fee_exponent"` + ExternalLiquidityRatio github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,6,opt,name=external_liquidity_ratio,json=externalLiquidityRatio,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"external_liquidity_ratio"` + WeightRecoveryFeePortion github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,7,opt,name=weight_recovery_fee_portion,json=weightRecoveryFeePortion,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"weight_recovery_fee_portion"` + ThresholdWeightDifference github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,8,opt,name=threshold_weight_difference,json=thresholdWeightDifference,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"threshold_weight_difference"` + WeightBreakingFeePortion github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,9,opt,name=weight_breaking_fee_portion,json=weightBreakingFeePortion,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"weight_breaking_fee_portion"` + FeeDenom string `protobuf:"bytes,10,opt,name=fee_denom,json=feeDenom,proto3" json:"fee_denom,omitempty"` +} + func (m *PoolParams) Reset() { *m = PoolParams{} } func (m *PoolParams) String() string { return proto.CompactTextString(m) } func (*PoolParams) ProtoMessage() {} func (*PoolParams) Descriptor() ([]byte, []int) { - return fileDescriptor_3500125990074bc9, []int{0} + return fileDescriptor_3500125990074bc9, []int{1} } func (m *PoolParams) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -85,44 +145,49 @@ func (m *PoolParams) GetFeeDenom() string { } func init() { + proto.RegisterType((*LegacyPoolParams)(nil), "elys.amm.LegacyPoolParams") proto.RegisterType((*PoolParams)(nil), "elys.amm.PoolParams") } func init() { proto.RegisterFile("elys/amm/pool_params.proto", fileDescriptor_3500125990074bc9) } var fileDescriptor_3500125990074bc9 = []byte{ - // 437 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0xd3, 0xcd, 0x8a, 0xdb, 0x30, - 0x10, 0x07, 0xf0, 0xb8, 0x1f, 0xd9, 0x44, 0xbd, 0x99, 0x52, 0xb4, 0x49, 0xeb, 0x5d, 0x7a, 0x28, - 0xb9, 0xac, 0x7d, 0xe8, 0x1b, 0x84, 0x34, 0x50, 0x68, 0x69, 0xf0, 0xa5, 0xd0, 0x8b, 0x70, 0xec, - 0x89, 0x2d, 0x22, 0x69, 0x5c, 0x49, 0x6e, 0x92, 0x87, 0x28, 0xf4, 0xb1, 0xf6, 0xb8, 0xc7, 0xd2, - 0xc3, 0x52, 0x92, 0x17, 0x29, 0x92, 0xbd, 0xa1, 0xd0, 0x9e, 0x7c, 0xb2, 0x47, 0x83, 0x7e, 0x7f, - 0x46, 0x30, 0x64, 0x02, 0xe2, 0x60, 0x92, 0x4c, 0xca, 0xa4, 0x46, 0x14, 0xac, 0xce, 0x74, 0x26, - 0x4d, 0x5c, 0x6b, 0xb4, 0x18, 0x8e, 0x5c, 0x2f, 0xce, 0xa4, 0x9c, 0x3c, 0x2f, 0xb1, 0x44, 0x7f, - 0x98, 0xb8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x85, 0xbd, 0x78, 0xf0, 0x3e, 0x3c, 0x70, 0xa9, 0xd3, 0x42, - 0x49, 0xba, 0xc9, 0x99, 0x86, 0x1c, 0xbf, 0x81, 0x3e, 0xf8, 0xd1, 0x6a, 0xd4, 0x96, 0xa3, 0xa2, - 0xc3, 0x5e, 0x61, 0xb4, 0x25, 0xd3, 0x4e, 0x5c, 0x02, 0xac, 0x5a, 0x2f, 0x54, 0x64, 0x6a, 0x2b, - 0x0d, 0xa6, 0x42, 0x51, 0xb0, 0x2e, 0xb8, 0xe0, 0x9b, 0x0d, 0x68, 0x50, 0x39, 0xd0, 0x8b, 0x7e, - 0x0f, 0x79, 0x26, 0x3f, 0x7b, 0x71, 0x71, 0x06, 0xc3, 0x29, 0x19, 0xbb, 0x71, 0x0a, 0x50, 0x28, - 0xe9, 0xc8, 0xe9, 0xe9, 0x68, 0x03, 0xb0, 0x70, 0xf5, 0x7c, 0x7e, 0x7b, 0x8c, 0x82, 0xbb, 0x63, - 0x14, 0xfc, 0x3e, 0x46, 0xc1, 0x8f, 0x53, 0x34, 0xb8, 0x3b, 0x45, 0x83, 0x9f, 0xa7, 0x68, 0xf0, - 0x65, 0xf6, 0x57, 0xb2, 0xdb, 0xb7, 0x1b, 0x05, 0x76, 0x87, 0x7a, 0xeb, 0x8b, 0x64, 0xef, 0x57, - 0xd3, 0xe7, 0xaf, 0x87, 0x7e, 0xb5, 0xde, 0xfe, 0x09, 0x00, 0x00, 0xff, 0xff, 0x3f, 0x4a, 0x7b, - 0xbc, 0xb3, 0x03, 0x00, 0x00, + // 497 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xec, 0x95, 0x41, 0x8f, 0xd2, 0x40, + 0x14, 0xc7, 0xa9, 0xba, 0x50, 0xc6, 0x8b, 0x69, 0x8c, 0x99, 0x05, 0xed, 0x6e, 0xf6, 0x60, 0xb8, + 0x2c, 0x1c, 0xfc, 0x06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 0x38, 0x39, 0x66, 0x1e, 0xea, 0xc7, 0xcc, 0x43, 0xe3, 0xb8, 0x79, 0xf0, 0xff, 0x75, 0x1e, + 0x7e, 0xd9, 0x3b, 0x98, 0xdc, 0xce, 0x5e, 0xf3, 0x6f, 0xec, 0xdd, 0x19, 0xdc, 0xce, 0xde, 0x41, + 0xfc, 0xc8, 0x61, 0xfc, 0xfa, 0xfd, 0xeb, 0x4d, 0xe8, 0xdd, 0x6c, 0x42, 0xef, 0xfb, 0x26, 0xf4, + 0x3e, 0x6f, 0xc3, 0xda, 0xcd, 0x36, 0xac, 0x7d, 0xdd, 0x86, 0xb5, 0x0f, 0x9d, 0x3b, 0xc2, 0x76, + 0xe9, 0x5d, 0xa6, 0x60, 0x56, 0xa8, 0x16, 0xae, 0xe8, 0xad, 0xdd, 0x7e, 0x74, 0xf2, 0x93, 0xba, + 0xdb, 0x6f, 0xaf, 0x7e, 0x06, 0x00, 0x00, 0xff, 0xff, 0xec, 0x4a, 0x8a, 0x6d, 0x38, 0x07, 0x00, + 0x00, } -func (m *PoolParams) Marshal() (dAtA []byte, err error) { +func (m *LegacyPoolParams) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -132,12 +197,12 @@ func (m *PoolParams) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *PoolParams) MarshalTo(dAtA []byte) (int, error) { +func (m *LegacyPoolParams) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *PoolParams) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *LegacyPoolParams) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int @@ -232,6 +297,126 @@ func (m *PoolParams) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +func (m *PoolParams) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *PoolParams) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *PoolParams) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.FeeDenom) > 0 { + i -= len(m.FeeDenom) + copy(dAtA[i:], m.FeeDenom) + i = encodeVarintPoolParams(dAtA, i, uint64(len(m.FeeDenom))) + i-- + dAtA[i] = 0x52 + } + { + size := m.WeightBreakingFeePortion.Size() + i -= size + if _, err := m.WeightBreakingFeePortion.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintPoolParams(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x4a + { + size := m.ThresholdWeightDifference.Size() + i -= size + if _, err := m.ThresholdWeightDifference.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintPoolParams(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x42 + { + size := m.WeightRecoveryFeePortion.Size() + i -= size + if _, err := m.WeightRecoveryFeePortion.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintPoolParams(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x3a + { + size := m.ExternalLiquidityRatio.Size() + i -= size + if _, err := m.ExternalLiquidityRatio.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintPoolParams(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x32 + { + size := m.WeightBreakingFeeExponent.Size() + i -= size + if _, err := m.WeightBreakingFeeExponent.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintPoolParams(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x2a + { + size := m.WeightBreakingFeeMultiplier.Size() + i -= size + if _, err := m.WeightBreakingFeeMultiplier.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintPoolParams(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x22 + if m.UseOracle { + i-- + if m.UseOracle { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i-- + dAtA[i] = 0x18 + } + { + size := m.ExitFee.Size() + i -= size + if _, err := m.ExitFee.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintPoolParams(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + { + size := m.SwapFee.Size() + i -= size + if _, err := m.SwapFee.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintPoolParams(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + func encodeVarintPoolParams(dAtA []byte, offset int, v uint64) int { offset -= sovPoolParams(v) base := offset @@ -243,7 +428,7 @@ func encodeVarintPoolParams(dAtA []byte, offset int, v uint64) int { dAtA[offset] = uint8(v) return base } -func (m *PoolParams) Size() (n int) { +func (m *LegacyPoolParams) Size() (n int) { if m == nil { return 0 } @@ -273,13 +458,45 @@ func (m *PoolParams) Size() (n int) { return n } +func (m *PoolParams) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.SwapFee.Size() + n += 1 + l + sovPoolParams(uint64(l)) + l = m.ExitFee.Size() + n += 1 + l + sovPoolParams(uint64(l)) + if m.UseOracle { + n += 2 + } + l = m.WeightBreakingFeeMultiplier.Size() + n += 1 + l + sovPoolParams(uint64(l)) + l = m.WeightBreakingFeeExponent.Size() + n += 1 + l + sovPoolParams(uint64(l)) + l = m.ExternalLiquidityRatio.Size() + n += 1 + l + sovPoolParams(uint64(l)) + l = m.WeightRecoveryFeePortion.Size() + n += 1 + l + sovPoolParams(uint64(l)) + l = m.ThresholdWeightDifference.Size() + n += 1 + l + sovPoolParams(uint64(l)) + l = m.WeightBreakingFeePortion.Size() + n += 1 + l + sovPoolParams(uint64(l)) + l = len(m.FeeDenom) + if l > 0 { + n += 1 + l + sovPoolParams(uint64(l)) + } + return n +} + func sovPoolParams(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } func sozPoolParams(x uint64) (n int) { return sovPoolParams(uint64((x << 1) ^ uint64((int64(x) >> 63)))) } -func (m *PoolParams) Unmarshal(dAtA []byte) error { +func (m *LegacyPoolParams) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -302,10 +519,10 @@ func (m *PoolParams) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: PoolParams: wiretype end group for non-group") + return fmt.Errorf("proto: LegacyPoolParams: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: PoolParams: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: LegacyPoolParams: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: @@ -619,6 +836,380 @@ func (m *PoolParams) Unmarshal(dAtA []byte) error { } return nil } +func (m *PoolParams) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPoolParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: PoolParams: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: PoolParams: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field SwapFee", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPoolParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthPoolParams + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthPoolParams + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.SwapFee.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ExitFee", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPoolParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthPoolParams + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthPoolParams + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.ExitFee.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field UseOracle", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPoolParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.UseOracle = bool(v != 0) + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field WeightBreakingFeeMultiplier", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPoolParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthPoolParams + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthPoolParams + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.WeightBreakingFeeMultiplier.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field WeightBreakingFeeExponent", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPoolParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthPoolParams + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthPoolParams + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.WeightBreakingFeeExponent.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 6: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ExternalLiquidityRatio", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPoolParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthPoolParams + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthPoolParams + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.ExternalLiquidityRatio.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 7: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field WeightRecoveryFeePortion", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPoolParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthPoolParams + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthPoolParams + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.WeightRecoveryFeePortion.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 8: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ThresholdWeightDifference", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPoolParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthPoolParams + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthPoolParams + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.ThresholdWeightDifference.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 9: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field WeightBreakingFeePortion", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPoolParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthPoolParams + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthPoolParams + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.WeightBreakingFeePortion.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 10: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field FeeDenom", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPoolParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthPoolParams + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthPoolParams + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.FeeDenom = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipPoolParams(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthPoolParams + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func skipPoolParams(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 diff --git a/x/amm/types/swap_in_amt_given_out.go b/x/amm/types/swap_in_amt_given_out.go index 012e0fe3b..4606535c1 100644 --- a/x/amm/types/swap_in_amt_given_out.go +++ b/x/amm/types/swap_in_amt_given_out.go @@ -119,27 +119,24 @@ func (p *Pool) SwapInAmtGivenOut( weightDistance := p.WeightDistanceFromTarget(ctx, oracleKeeper, newAssetPools) distanceDiff := weightDistance.Sub(initialWeightDistance) - // cut is valid when distance higher than original distance - weightBreakingFee := sdk.ZeroDec() - if distanceDiff.IsPositive() { - // old weight breaking fee implementation - // weightBreakingFee = p.PoolParams.WeightBreakingFeeMultiplier.Mul(distanceDiff) + // target weight + targetWeightIn := NormalizedWeight(ctx, p.PoolAssets, tokenInDenom) + targetWeightOut := NormalizedWeight(ctx, p.PoolAssets, tokenOut.Denom) - // target weight - targetWeightIn := NormalizedWeight(ctx, p.PoolAssets, tokenInDenom) - targetWeightOut := NormalizedWeight(ctx, p.PoolAssets, tokenOut.Denom) + // weight breaking fee as in Plasma pool + weightIn := OracleAssetWeight(ctx, oracleKeeper, newAssetPools, tokenInDenom) + weightOut := OracleAssetWeight(ctx, oracleKeeper, newAssetPools, tokenOut.Denom) + weightBreakingFee := GetWeightBreakingFee(weightIn, weightOut, targetWeightIn, targetWeightOut, p.PoolParams, distanceDiff) - // weight breaking fee as in Plasma pool - weightIn := OracleAssetWeight(ctx, oracleKeeper, newAssetPools, tokenInDenom) - weightOut := OracleAssetWeight(ctx, oracleKeeper, newAssetPools, tokenOut.Denom) - weightBreakingFee = GetWeightBreakingFee(weightIn, weightOut, targetWeightIn, targetWeightOut, p.PoolParams) - - } + // weight recovery reward = weight breaking fee * weight recovery fee portion + weightRecoveryReward := weightBreakingFee.Mul(p.PoolParams.WeightRecoveryFeePortion) // bonus is valid when distance is lower than original distance and when threshold weight reached weightBalanceBonus = weightBreakingFee.Neg() if initialWeightDistance.GT(p.PoolParams.ThresholdWeightDifference) && distanceDiff.IsNegative() { - weightBalanceBonus = p.PoolParams.WeightBreakingFeeMultiplier.Mul(distanceDiff).Abs() + weightBalanceBonus = weightRecoveryReward + // set weight breaking fee to zero if bonus is applied + weightBreakingFee = sdk.ZeroDec() } if swapFee.GTE(sdk.OneDec()) { diff --git a/x/amm/types/swap_in_amt_given_out_test.go b/x/amm/types/swap_in_amt_given_out_test.go index 832ab7087..0e8ab1893 100644 --- a/x/amm/types/swap_in_amt_given_out_test.go +++ b/x/amm/types/swap_in_amt_given_out_test.go @@ -121,7 +121,7 @@ func (suite *TestSuite) TestSwapInAmtGivenOut() { tokenOut: sdk.NewInt64Coin("uusdt", 100_000_000), // 100 USDC inTokenDenom: ptypes.BaseCurrency, swapFee: sdk.ZeroDec(), - expRecoveryBonus: sdk.MustNewDecFromStr("0.000010009437463773"), + expRecoveryBonus: sdk.MustNewDecFromStr("0.000831185594279234"), expTokenIn: sdk.NewInt64Coin(ptypes.BaseCurrency, 100134830), expErr: false, }, @@ -208,6 +208,7 @@ func (suite *TestSuite) TestSwapInAmtGivenOut() { ThresholdWeightDifference: tc.thresholdWeightDiff, WeightBreakingFeeMultiplier: sdk.NewDecWithPrec(2, 4), // 0.02% WeightBreakingFeeExponent: sdk.NewDecWithPrec(25, 1), // 2.5 + WeightRecoveryFeePortion: sdk.NewDecWithPrec(50, 2), // 50% }, TotalShares: sdk.Coin{}, PoolAssets: tc.poolAssets, diff --git a/x/amm/types/swap_out_amt_given_in.go b/x/amm/types/swap_out_amt_given_in.go index 3d1a623f2..a37fc1f25 100644 --- a/x/amm/types/swap_out_amt_given_in.go +++ b/x/amm/types/swap_out_amt_given_in.go @@ -284,26 +284,24 @@ func (p *Pool) SwapOutAmtGivenIn( weightDistance := p.WeightDistanceFromTarget(ctx, oracleKeeper, newAssetPools) distanceDiff := weightDistance.Sub(initialWeightDistance) - // cut is valid when distance higher than original distance - weightBreakingFee := sdk.ZeroDec() - if distanceDiff.IsPositive() { - // old weight breaking fee implementation - // weightBreakingFee = p.PoolParams.WeightBreakingFeeMultiplier.Mul(distanceDiff) - - // target weight - targetWeightIn := NormalizedWeight(ctx, p.PoolAssets, tokenIn.Denom) - targetWeightOut := NormalizedWeight(ctx, p.PoolAssets, tokenOutDenom) - - // weight breaking fee as in Plasma pool - weightIn := OracleAssetWeight(ctx, oracleKeeper, newAssetPools, tokenIn.Denom) - weightOut := OracleAssetWeight(ctx, oracleKeeper, newAssetPools, tokenOutDenom) - weightBreakingFee = GetWeightBreakingFee(weightIn, weightOut, targetWeightIn, targetWeightOut, p.PoolParams) - } + // target weight + targetWeightIn := NormalizedWeight(ctx, p.PoolAssets, tokenIn.Denom) + targetWeightOut := NormalizedWeight(ctx, p.PoolAssets, tokenOutDenom) + + // weight breaking fee as in Plasma pool + weightIn := OracleAssetWeight(ctx, oracleKeeper, newAssetPools, tokenIn.Denom) + weightOut := OracleAssetWeight(ctx, oracleKeeper, newAssetPools, tokenOutDenom) + weightBreakingFee := GetWeightBreakingFee(weightIn, weightOut, targetWeightIn, targetWeightOut, p.PoolParams, distanceDiff) + + // weight recovery reward = weight breaking fee * weight recovery fee portion + weightRecoveryReward := weightBreakingFee.Mul(p.PoolParams.WeightRecoveryFeePortion) // bonus is valid when distance is lower than original distance and when threshold weight reached weightBalanceBonus = weightBreakingFee.Neg() if initialWeightDistance.GT(p.PoolParams.ThresholdWeightDifference) && distanceDiff.IsNegative() { - weightBalanceBonus = p.PoolParams.WeightBreakingFeeMultiplier.Mul(distanceDiff).Abs() + weightBalanceBonus = weightRecoveryReward + // set weight breaking fee to zero if bonus is applied + weightBreakingFee = sdk.ZeroDec() } if swapFee.GTE(sdk.OneDec()) { diff --git a/x/amm/types/swap_out_amt_given_in_test.go b/x/amm/types/swap_out_amt_given_in_test.go index 10f4fbde2..cd9844ea6 100644 --- a/x/amm/types/swap_out_amt_given_in_test.go +++ b/x/amm/types/swap_out_amt_given_in_test.go @@ -531,7 +531,7 @@ func (suite *TestSuite) TestSwapOutAmtGivenIn() { tokenIn: sdk.NewInt64Coin(ptypes.BaseCurrency, 100_000_000), // 100 USDC outTokenDenom: "uusdt", swapFee: sdk.ZeroDec(), - expRecoveryBonus: sdk.MustNewDecFromStr("0.000009996061438555"), + expRecoveryBonus: sdk.MustNewDecFromStr("0.000831847623764616"), expTokenOut: sdk.NewInt64Coin("uusdt", 99868706), expErr: false, }, @@ -618,6 +618,7 @@ func (suite *TestSuite) TestSwapOutAmtGivenIn() { ThresholdWeightDifference: tc.thresholdWeightDiff, WeightBreakingFeeMultiplier: sdk.NewDecWithPrec(2, 4), // 0.02% WeightBreakingFeeExponent: sdk.NewDecWithPrec(25, 1), // 2.5 + WeightRecoveryFeePortion: sdk.NewDecWithPrec(50, 2), // 50% }, TotalShares: sdk.Coin{}, PoolAssets: tc.poolAssets, diff --git a/x/amm/types/utils.go b/x/amm/types/utils.go index 131b4ac4c..7ef5e114b 100644 --- a/x/amm/types/utils.go +++ b/x/amm/types/utils.go @@ -59,12 +59,17 @@ func ApplyDiscount(swapFee sdk.Dec, discount sdk.Dec) sdk.Dec { return swapFee } -func GetWeightBreakingFee(weightIn, weightOut, targetWeightIn, targetWeightOut sdk.Dec, poolParams PoolParams) sdk.Dec { +func GetWeightBreakingFee(weightIn, weightOut, targetWeightIn, targetWeightOut sdk.Dec, poolParams PoolParams, distanceDiff sdk.Dec) sdk.Dec { weightBreakingFee := sdk.ZeroDec() if !weightOut.IsZero() && !weightIn.IsZero() && !targetWeightOut.IsZero() && !targetWeightIn.IsZero() && !poolParams.WeightBreakingFeeMultiplier.IsZero() { // (45/55*60/40) ^ 2.5 - weightBreakingFee = poolParams.WeightBreakingFeeMultiplier. - Mul(Pow(weightIn.Mul(targetWeightOut).Quo(weightOut).Quo(targetWeightIn), poolParams.WeightBreakingFeeExponent)) + if distanceDiff.IsPositive() { + weightBreakingFee = poolParams.WeightBreakingFeeMultiplier. + Mul(Pow(weightIn.Mul(targetWeightOut).Quo(weightOut).Quo(targetWeightIn), poolParams.WeightBreakingFeeExponent)) + } else { + weightBreakingFee = poolParams.WeightBreakingFeeMultiplier. + Mul(Pow(weightOut.Mul(targetWeightIn).Quo(weightIn).Quo(targetWeightOut), poolParams.WeightBreakingFeeExponent)) + } if weightBreakingFee.GT(sdk.NewDecWithPrec(99, 2)) { weightBreakingFee = sdk.NewDecWithPrec(99, 2) diff --git a/x/perpetual/keeper/get_amm_pool_test.go b/x/perpetual/keeper/get_amm_pool_test.go index f2ad92dd2..162e4734a 100644 --- a/x/perpetual/keeper/get_amm_pool_test.go +++ b/x/perpetual/keeper/get_amm_pool_test.go @@ -19,6 +19,7 @@ func (suite *PerpetualKeeperTestSuite) TestGetAmmPool() { WeightBreakingFeeExponent: sdk.NewDecWithPrec(25, 1), // 2.5 WeightRecoveryFeePortion: sdk.NewDecWithPrec(10, 2), // 10% ThresholdWeightDifference: sdk.ZeroDec(), + WeightBreakingFeePortion: sdk.NewDecWithPrec(50, 2), // 50% SwapFee: sdk.ZeroDec(), ExitFee: sdk.ZeroDec(), FeeDenom: ptypes.BaseCurrency,