Skip to content

Commit

Permalink
refactor: move MinOrderQty, MinOrderQuote into Market
Browse files Browse the repository at this point in the history
also add MaxOrderQty, MaxOrderQuote
  • Loading branch information
kingcre committed Sep 27, 2023
1 parent d7da354 commit 05470f1
Show file tree
Hide file tree
Showing 55 changed files with 2,142 additions and 1,473 deletions.
28 changes: 15 additions & 13 deletions app/upgrades/mainnet/v5/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ func UpgradeHandler(
sdk.NewDecWithPrec(1, 3), // Maker: 0.1%
sdk.NewDecWithPrec(2, 3), // Taker: 0.2%
sdk.NewDecWithPrec(8, 1)) // Order source: Taker * 80%
exchangeParams.DefaultMinOrderQuantity = sdk.NewInt(10000)
exchangeParams.DefaultMinOrderQuote = sdk.NewInt(10000)
exchangeKeeper.SetParams(ctx, exchangeParams)
ammParams := ammtypes.DefaultParams()
ammParams.PoolCreationFee = sdk.NewCoins(sdk.NewInt64Coin("ucre", 1000_000000))
ammParams.DefaultMinOrderQuantity = sdk.NewInt(10000)
ammParams.DefaultMinOrderQuote = sdk.NewInt(10000)
ammParams.PrivateFarmingPlanCreationFee = sdk.NewCoins(sdk.NewInt64Coin("ucre", 1000_000000))
ammKeeper.SetParams(ctx, ammParams)

Expand Down Expand Up @@ -155,6 +155,10 @@ func UpgradeHandler(
defaultMakerFeeRate := exchangeParams.Fees.DefaultMakerFeeRate
defaultTakerFeeRate := exchangeParams.Fees.DefaultTakerFeeRate
defaultOrderSourceFeeRatio := exchangeParams.Fees.DefaultOrderSourceFeeRatio
defaultMinOrderQty := exchangeParams.DefaultMinOrderQuantity
defaultMinOrderQuote := exchangeParams.DefaultMinOrderQuote
defaultMaxOrderQty := exchangeParams.DefaultMaxOrderQuantity
defaultMaxOrderQuote := exchangeParams.DefaultMaxOrderQuote
pairs := map[uint64]liquiditytypes.Pair{}
var pairIds []uint64 // For ordered map access
var lastMarketId uint64
Expand Down Expand Up @@ -190,7 +194,8 @@ func UpgradeHandler(
// corresponding indexes, too.
market := exchangetypes.NewMarket(
pair.Id, pair.BaseCoinDenom, pair.QuoteCoinDenom,
defaultMakerFeeRate, defaultTakerFeeRate, defaultOrderSourceFeeRatio)
defaultMakerFeeRate, defaultTakerFeeRate, defaultOrderSourceFeeRatio,
defaultMinOrderQty, defaultMinOrderQuote, defaultMaxOrderQty, defaultMaxOrderQuote)
exchangeKeeper.SetMarket(ctx, market)
exchangeKeeper.SetMarketByDenomsIndex(ctx, market)
exchangeKeeper.SetMarketState(ctx, market.Id, exchangetypes.NewMarketState(pair.LastPrice))
Expand All @@ -204,8 +209,6 @@ func UpgradeHandler(
// Create a new pool for each market if the market's corresponding pair
// had at least one active pool.
defaultTickSpacing := ammParams.DefaultTickSpacing
defaultMinOrderQty := ammParams.DefaultMinOrderQuantity
defaultMinOrderQuote := ammParams.DefaultMinOrderQuote
newPoolIdByPairId := map[uint64]uint64{}
pairIdByOldPoolId := map[uint64]uint64{}
oldPoolsById := map[uint64]liquiditytypes.Pool{}
Expand Down Expand Up @@ -251,8 +254,7 @@ func UpgradeHandler(
newPoolId := ammKeeper.GetNextPoolIdWithUpdate(ctx)
marketId := pairId // We used the same ids as pairs for markets.
newPool := ammtypes.NewPool(
newPoolId, marketId, pair.BaseCoinDenom, pair.QuoteCoinDenom, defaultTickSpacing,
defaultMinOrderQty, defaultMinOrderQuote)
newPoolId, marketId, pair.BaseCoinDenom, pair.QuoteCoinDenom, defaultTickSpacing)
ammKeeper.SetPool(ctx, newPool)
// Set corresponding indexes.
ammKeeper.SetPoolByMarketIndex(ctx, newPool)
Expand Down Expand Up @@ -573,6 +575,12 @@ func UpgradeHandler(
if ParamChanges[pairId].TakerFeeRate != nil {
market.TakerFeeRate = *ParamChanges[pairId].TakerFeeRate
}
if ParamChanges[pairId].MinOrderQuantity != nil {
market.MinOrderQuantity = *ParamChanges[pairId].MinOrderQuantity
}
if ParamChanges[pairId].MinOrderQuote != nil {
market.MinOrderQuote = *ParamChanges[pairId].MinOrderQuote
}
exchangeKeeper.SetMarket(ctx, market)
}
if ParamChanges[pairId].TickSpacing != nil || ParamChanges[pairId].MinOrderQuantity != nil || ParamChanges[pairId].MinOrderQuote != nil {
Expand All @@ -584,12 +592,6 @@ func UpgradeHandler(
if ParamChanges[pairId].TickSpacing != nil {
pool.TickSpacing = *ParamChanges[pairId].TickSpacing
}
if ParamChanges[pairId].MinOrderQuantity != nil {
pool.MinOrderQuantity = *ParamChanges[pairId].MinOrderQuantity
}
if ParamChanges[pairId].MinOrderQuote != nil {
pool.MinOrderQuote = *ParamChanges[pairId].MinOrderQuote
}
ammKeeper.SetPool(ctx, pool)
}
}
Expand Down
2 changes: 1 addition & 1 deletion client/docs/statik/statik.go

Large diffs are not rendered by default.

96 changes: 64 additions & 32 deletions client/docs/swagger-ui/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11610,6 +11610,14 @@ paths:
type: string
order_source_fee_ratio:
type: string
min_order_quantity:
type: string
min_order_quote:
type: string
max_order_quantity:
type: string
max_order_quote:
type: string
last_price:
type: string
last_matching_height:
Expand Down Expand Up @@ -11751,6 +11759,14 @@ paths:
type: string
order_source_fee_ratio:
type: string
min_order_quantity:
type: string
min_order_quote:
type: string
max_order_quantity:
type: string
max_order_quote:
type: string
last_price:
type: string
last_matching_height:
Expand Down Expand Up @@ -12137,6 +12153,14 @@ paths:
title: >-
max_order_price_ratio defines the ratio of the maximum
possible order price compared to the market's last price
default_min_order_quantity:
type: string
default_min_order_quote:
type: string
default_max_order_quantity:
type: string
default_max_order_quote:
type: string
max_swap_routes_len:
type: integer
format: int64
Expand Down Expand Up @@ -12543,10 +12567,6 @@ paths:
default_tick_spacing:
type: integer
format: int64
default_min_order_quantity:
type: string
default_min_order_quote:
type: string
private_farming_plan_creation_fee:
type: array
items:
Expand Down Expand Up @@ -12650,10 +12670,6 @@ paths:
tick_spacing:
type: integer
format: int64
min_order_quantity:
type: string
min_order_quote:
type: string
current_tick:
type: integer
format: int32
Expand Down Expand Up @@ -12868,10 +12884,6 @@ paths:
tick_spacing:
type: integer
format: int64
min_order_quantity:
type: string
min_order_quote:
type: string
current_tick:
type: integer
format: int32
Expand Down Expand Up @@ -20172,6 +20184,14 @@ definitions:
type: string
order_source_fee_ratio:
type: string
min_order_quantity:
type: string
min_order_quote:
type: string
max_order_quantity:
type: string
max_order_quote:
type: string
last_price:
type: string
last_matching_height:
Expand Down Expand Up @@ -20288,6 +20308,14 @@ definitions:
title: >-
max_order_price_ratio defines the ratio of the maximum possible order
price compared to the market's last price
default_min_order_quantity:
type: string
default_min_order_quote:
type: string
default_max_order_quantity:
type: string
default_max_order_quote:
type: string
max_swap_routes_len:
type: integer
format: int64
Expand Down Expand Up @@ -20317,6 +20345,14 @@ definitions:
type: string
order_source_fee_ratio:
type: string
min_order_quantity:
type: string
min_order_quote:
type: string
max_order_quantity:
type: string
max_order_quote:
type: string
last_price:
type: string
last_matching_height:
Expand Down Expand Up @@ -20508,6 +20544,14 @@ definitions:
type: string
order_source_fee_ratio:
type: string
min_order_quantity:
type: string
min_order_quote:
type: string
max_order_quantity:
type: string
max_order_quote:
type: string
last_price:
type: string
last_matching_height:
Expand Down Expand Up @@ -20622,6 +20666,14 @@ definitions:
title: >-
max_order_price_ratio defines the ratio of the maximum possible
order price compared to the market's last price
default_min_order_quantity:
type: string
default_min_order_quote:
type: string
default_max_order_quantity:
type: string
default_max_order_quote:
type: string
max_swap_routes_len:
type: integer
format: int64
Expand Down Expand Up @@ -20761,10 +20813,6 @@ definitions:
default_tick_spacing:
type: integer
format: int64
default_min_order_quantity:
type: string
default_min_order_quote:
type: string
private_farming_plan_creation_fee:
type: array
items:
Expand Down Expand Up @@ -20824,10 +20872,6 @@ definitions:
tick_spacing:
type: integer
format: int64
min_order_quantity:
type: string
min_order_quote:
type: string
current_tick:
type: integer
format: int32
Expand Down Expand Up @@ -21087,10 +21131,6 @@ definitions:
tick_spacing:
type: integer
format: int64
min_order_quantity:
type: string
min_order_quote:
type: string
current_tick:
type: integer
format: int32
Expand Down Expand Up @@ -21463,10 +21503,6 @@ definitions:
default_tick_spacing:
type: integer
format: int64
default_min_order_quantity:
type: string
default_min_order_quote:
type: string
private_farming_plan_creation_fee:
type: array
items:
Expand Down Expand Up @@ -21538,10 +21574,6 @@ definitions:
tick_spacing:
type: integer
format: int64
min_order_quantity:
type: string
min_order_quote:
type: string
current_tick:
type: integer
format: int32
Expand Down
18 changes: 7 additions & 11 deletions proto/crescent/amm/v1beta1/amm.proto
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,13 @@ option go_package = "github.com/crescent-network/crescent/v
option (gogoproto.goproto_getters_all) = false;

message Pool {
uint64 id = 1;
uint64 market_id = 2;
string denom0 = 3;
string denom1 = 4;
string reserve_address = 5;
string rewards_pool = 6;
uint32 tick_spacing = 7;
string min_order_quantity = 8
[(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", (gogoproto.nullable) = false];
string min_order_quote = 9
[(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", (gogoproto.nullable) = false];
uint64 id = 1;
uint64 market_id = 2;
string denom0 = 3;
string denom1 = 4;
string reserve_address = 5;
string rewards_pool = 6;
uint32 tick_spacing = 7;
}

message PoolState {
Expand Down
6 changes: 2 additions & 4 deletions proto/crescent/amm/v1beta1/event.proto
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ message EventFarmingPlanTerminated {
}

message EventPoolParameterChanged {
uint64 pool_id = 1;
uint32 tick_spacing = 2;
string min_order_quantity = 3 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int"];
string min_order_quote = 4 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int"];
uint64 pool_id = 1;
uint32 tick_spacing = 2;
}
6 changes: 1 addition & 5 deletions proto/crescent/amm/v1beta1/params.proto
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@ option (gogoproto.goproto_getters_all) = false;
message Params {
repeated cosmos.base.v1beta1.Coin pool_creation_fee = 1
[(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins", (gogoproto.nullable) = false];
uint32 default_tick_spacing = 2;
string default_min_order_quantity = 3
[(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", (gogoproto.nullable) = false];
string default_min_order_quote = 4
[(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", (gogoproto.nullable) = false];
uint32 default_tick_spacing = 2;
repeated cosmos.base.v1beta1.Coin private_farming_plan_creation_fee = 5
[(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins", (gogoproto.nullable) = false];
uint32 max_num_private_farming_plans = 6;
Expand Down
6 changes: 2 additions & 4 deletions proto/crescent/amm/v1beta1/proposal.proto
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ message PoolParameterChangeProposal {
}

message PoolParameterChange {
uint64 pool_id = 1;
uint32 tick_spacing = 2;
string min_order_quantity = 3 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int"];
string min_order_quote = 4 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int"];
uint64 pool_id = 1;
uint32 tick_spacing = 2;
}
30 changes: 13 additions & 17 deletions proto/crescent/amm/v1beta1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -185,27 +185,23 @@ message QueryFarmingPlanResponse {
}

message PoolResponse {
uint64 id = 1;
uint64 market_id = 2;
cosmos.base.v1beta1.Coin balance0 = 3 [(gogoproto.nullable) = false];
cosmos.base.v1beta1.Coin balance1 = 4 [(gogoproto.nullable) = false];
string reserve_address = 5;
string rewards_pool = 6;
uint32 tick_spacing = 7;
string min_order_quantity = 8
[(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", (gogoproto.nullable) = false];
string min_order_quote = 9
[(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", (gogoproto.nullable) = false];
int32 current_tick = 10;
string current_price = 11
uint64 id = 1;
uint64 market_id = 2;
cosmos.base.v1beta1.Coin balance0 = 3 [(gogoproto.nullable) = false];
cosmos.base.v1beta1.Coin balance1 = 4 [(gogoproto.nullable) = false];
string reserve_address = 5;
string rewards_pool = 6;
uint32 tick_spacing = 7;
int32 current_tick = 8;
string current_price = 9
[(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false];
string current_liquidity = 12
string current_liquidity = 10
[(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", (gogoproto.nullable) = false];
string total_liquidity = 13
string total_liquidity = 11
[(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", (gogoproto.nullable) = false];
repeated cosmos.base.v1beta1.DecCoin fee_growth_global = 14
repeated cosmos.base.v1beta1.DecCoin fee_growth_global = 12
[(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.DecCoins", (gogoproto.nullable) = false];
repeated cosmos.base.v1beta1.DecCoin farming_rewards_growth_global = 15
repeated cosmos.base.v1beta1.DecCoin farming_rewards_growth_global = 13
[(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.DecCoins", (gogoproto.nullable) = false];
}

Expand Down
4 changes: 4 additions & 0 deletions proto/crescent/exchange/v1beta1/event.proto
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,8 @@ message EventMarketParameterChanged {
[(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false];
string order_source_fee_ratio = 4
[(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false];
string min_order_quantity = 5 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int"];
string min_order_quote = 6 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int"];
string max_order_quantity = 7 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int"];
string max_order_quote = 8 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int"];
}
Loading

0 comments on commit 05470f1

Please sign in to comment.