Skip to content

Commit 90cdb75

Browse files
authored
making perpetual safety factor per pool (#1412)
* making perpetual safety factor per pool * making perpetual safety factor per pool * making perpetual safety factor per pool
1 parent 5a1dcfe commit 90cdb75

35 files changed

+2464
-8065
lines changed

api/elys/perpetual/params.pulsar.go

Lines changed: 149 additions & 2347 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/elys/perpetual/pool.pulsar.go

Lines changed: 187 additions & 2332 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/elys/perpetual/tx.pulsar.go

Lines changed: 933 additions & 171 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

go.work.sum

Lines changed: 35 additions & 8 deletions
Large diffs are not rendered by default.

proto/elys/perpetual/params.proto

Lines changed: 0 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -6,108 +6,6 @@ import "cosmos_proto/cosmos.proto";
66

77
option go_package = "github.com/elys-network/elys/v7/x/perpetual/types";
88

9-
message LegacyParams {
10-
string leverage_max = 1 [
11-
(cosmos_proto.scalar) = "cosmos.Dec",
12-
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
13-
(gogoproto.nullable) = false
14-
];
15-
string borrow_interest_rate_max = 2 [
16-
(cosmos_proto.scalar) = "cosmos.Dec",
17-
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
18-
(gogoproto.nullable) = false
19-
];
20-
string borrow_interest_rate_min = 3 [
21-
(cosmos_proto.scalar) = "cosmos.Dec",
22-
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
23-
(gogoproto.nullable) = false
24-
];
25-
string borrow_interest_rate_increase = 4 [
26-
(cosmos_proto.scalar) = "cosmos.Dec",
27-
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
28-
(gogoproto.nullable) = false
29-
];
30-
string borrow_interest_rate_decrease = 5 [
31-
(cosmos_proto.scalar) = "cosmos.Dec",
32-
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
33-
(gogoproto.nullable) = false
34-
];
35-
string health_gain_factor = 6 [
36-
(cosmos_proto.scalar) = "cosmos.Dec",
37-
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
38-
(gogoproto.nullable) = false
39-
];
40-
int64 max_open_positions = 7;
41-
string pool_max_liabilities_threshold = 8 [
42-
(cosmos_proto.scalar) = "cosmos.Dec",
43-
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
44-
(gogoproto.nullable) = false
45-
];
46-
string borrow_interest_payment_fund_percentage = 9 [
47-
(cosmos_proto.scalar) = "cosmos.Dec",
48-
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
49-
(gogoproto.nullable) = false
50-
];
51-
string legacy_borrow_interest_payment_fund_address = 10;
52-
string safety_factor = 11 [
53-
(cosmos_proto.scalar) = "cosmos.Dec",
54-
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
55-
(gogoproto.nullable) = false
56-
];
57-
bool borrow_interest_payment_enabled = 12;
58-
bool whitelisting_enabled = 13;
59-
string perpetual_swap_fee = 14 [
60-
(cosmos_proto.scalar) = "cosmos.Dec",
61-
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
62-
(gogoproto.nullable) = false
63-
];
64-
int64 max_limit_order = 15;
65-
string fixed_funding_rate = 16 [
66-
(cosmos_proto.scalar) = "cosmos.Dec",
67-
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
68-
(gogoproto.nullable) = false
69-
];
70-
// minimum value for take_profit_price/current price for long, should be
71-
// greater than 1
72-
string minimum_long_take_profit_price_ratio = 17 [
73-
(cosmos_proto.scalar) = "cosmos.Dec",
74-
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
75-
(gogoproto.nullable) = false
76-
];
77-
// max value for take_profit_price/current price for long, should be greater
78-
// than 1
79-
string maximum_long_take_profit_price_ratio = 18 [
80-
(cosmos_proto.scalar) = "cosmos.Dec",
81-
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
82-
(gogoproto.nullable) = false
83-
];
84-
// max value for take_profit_price/current price for short, should be less
85-
// than 1
86-
string maximum_short_take_profit_price_ratio = 19 [
87-
(cosmos_proto.scalar) = "cosmos.Dec",
88-
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
89-
(gogoproto.nullable) = false
90-
];
91-
// No need for minimumShortTakeProfitPriceRatio as it will be 0, checked in
92-
// validate message
93-
bool enable_take_profit_custody_liabilities = 20;
94-
// We create this and send this value to estimate swap ONLY when opening and
95-
// closing the position Ideally this value is set to half. When trader open a
96-
// position if they receive a weight balance bonus (which is half of weight
97-
// breaking fee, ideally) then while closing position they are charged weight
98-
// breaking fee. So we just directly apply half weight breaking fee on
99-
// perpetual swaps Question: does each need to have separate value of this
100-
// because PoolParams.WeightRecoveryFeePortion can be different Also, if
101-
// trader has no bonus only fee, then overall we are only applying the fee
102-
// half time
103-
string weight_breaking_fee_factor = 21 [
104-
(cosmos_proto.scalar) = "cosmos.Dec",
105-
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
106-
(gogoproto.nullable) = false
107-
];
108-
repeated uint64 enabled_pools = 22;
109-
}
110-
1119
message Params {
11210
string leverage_max = 1 [
11311
(cosmos_proto.scalar) = "cosmos.Dec",

proto/elys/perpetual/pool.proto

Lines changed: 5 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -7,73 +7,6 @@ import "cosmos_proto/cosmos.proto";
77

88
option go_package = "github.com/elys-network/elys/v7/x/perpetual/types";
99

10-
message LegacyPoolAsset {
11-
string liabilities = 1 [
12-
(cosmos_proto.scalar) = "cosmos.Int",
13-
(gogoproto.customtype) = "cosmossdk.io/math.Int",
14-
(gogoproto.nullable) = false
15-
];
16-
string custody = 2 [
17-
(cosmos_proto.scalar) = "cosmos.Int",
18-
(gogoproto.customtype) = "cosmossdk.io/math.Int",
19-
(gogoproto.nullable) = false
20-
];
21-
string take_profit_liabilities = 3 [
22-
(cosmos_proto.scalar) = "cosmos.Int",
23-
(gogoproto.customtype) = "cosmossdk.io/math.Int",
24-
(gogoproto.nullable) = false
25-
];
26-
string take_profit_custody = 4 [
27-
(cosmos_proto.scalar) = "cosmos.Int",
28-
(gogoproto.customtype) = "cosmossdk.io/math.Int",
29-
(gogoproto.nullable) = false
30-
];
31-
string asset_denom = 5;
32-
string collateral = 6 [
33-
(cosmos_proto.scalar) = "cosmos.Int",
34-
(gogoproto.customtype) = "cosmossdk.io/math.Int",
35-
(gogoproto.nullable) = false
36-
];
37-
}
38-
39-
message LegacyPool {
40-
uint64 amm_pool_id = 1;
41-
string base_asset_liabilities_ratio = 2 [
42-
(cosmos_proto.scalar) = "cosmos.Dec",
43-
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
44-
(gogoproto.nullable) = false
45-
];
46-
string quote_asset_liabilities_ratio = 3 [
47-
(cosmos_proto.scalar) = "cosmos.Dec",
48-
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
49-
(gogoproto.nullable) = false
50-
];
51-
52-
string borrow_interest_rate = 4 [
53-
(cosmos_proto.scalar) = "cosmos.Dec",
54-
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
55-
(gogoproto.nullable) = false
56-
];
57-
repeated LegacyPoolAsset pool_assets_long = 5
58-
[ (gogoproto.nullable) = false ];
59-
repeated LegacyPoolAsset pool_assets_short = 6
60-
[ (gogoproto.nullable) = false ];
61-
int64 last_height_borrow_interest_rate_computed = 7;
62-
// funding rate, if positive longs pay shorts, if negative shorts pay longs
63-
string funding_rate = 8 [
64-
(cosmos_proto.scalar) = "cosmos.Dec",
65-
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
66-
(gogoproto.nullable) = false
67-
];
68-
repeated cosmos.base.v1beta1.Coin fees_collected = 9
69-
[ (gogoproto.nullable) = false ];
70-
string leverage_max = 10 [
71-
(cosmos_proto.scalar) = "cosmos.Dec",
72-
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
73-
(gogoproto.nullable) = false
74-
];
75-
}
76-
7710
message PoolAsset {
7811
string asset_denom = 1;
7912
string liabilities = 2 [
@@ -127,6 +60,11 @@ message Pool {
12760
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
12861
(gogoproto.nullable) = false
12962
];
63+
string mtp_safety_factor = 11 [
64+
(cosmos_proto.scalar) = "cosmos.Dec",
65+
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
66+
(gogoproto.nullable) = false
67+
];
13068
}
13169

13270
message PerpetualCounter {

proto/elys/perpetual/tx.proto

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,20 @@ message MsgUpdateMaxLeverageForPool {
165165
}
166166

167167
message MsgUpdateMaxLeverageForPoolResponse {}
168+
169+
message PoolParams {
170+
uint64 pool_id = 1;
171+
string mtp_safety_factor = 2 [
172+
(cosmos_proto.scalar) = "cosmos.Dec",
173+
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
174+
(gogoproto.nullable) = false
175+
];
176+
string leverage_max = 3 [
177+
(cosmos_proto.scalar) = "cosmos.Dec",
178+
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
179+
(gogoproto.nullable) = false
180+
];
181+
}
168182
message MsgUpdateEnabledPools {
169183
option (cosmos.msg.v1.signer) = "authority";
170184
option (amino.name) = "perpetual/MsgUpdateEnabledPools";
@@ -174,6 +188,7 @@ message MsgUpdateEnabledPools {
174188
repeated uint64 enabled_pools = 2;
175189
repeated uint64 add_pools = 3;
176190
repeated uint64 remove_pools = 4;
191+
repeated PoolParams update_pool_params = 5 [ (gogoproto.nullable) = false ];
177192
}
178193

179194
message MsgUpdateEnabledPoolsResponse {}

x/perpetual/keeper/begin_blocker_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func (suite *PerpetualKeeperTestSuite) TestComputeFundingRate() {
4646
},
4747
},
4848
}
49-
pool := types.NewPool(ammPool, math.LegacyMustNewDecFromStr("5.5"))
49+
pool := types.NewPool(ammPool, math.LegacyMustNewDecFromStr("5.5"), math.LegacyMustNewDecFromStr("1.025000000000000000"))
5050
pool.PoolAssetsLong = []types.PoolAsset{
5151
{
5252
Liabilities: math.NewInt(0),

x/perpetual/keeper/force_close_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func (suite *PerpetualKeeperTestSuite) TestForceCloseShort_Successful() {
3838
_, err := leveragelpmodulekeeper.NewMsgServerImpl(*suite.app.LeveragelpKeeper).AddPool(ctx, &enablePoolMsg)
3939
suite.Require().NoError(err)
4040

41-
pool := types.NewPool(ammPool, math.LegacyMustNewDecFromStr("5.5"))
41+
pool := types.NewPool(ammPool, math.LegacyMustNewDecFromStr("5.5"), math.LegacyMustNewDecFromStr("1.025000000000000000"))
4242
k.SetPool(ctx, pool)
4343

4444
openPositionMsg := &types.MsgOpen{

x/perpetual/keeper/get_net_open_interest_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func (suite *PerpetualKeeperTestSuite) TestGetFundingPaymentRates() {
1919
},
2020
},
2121
}
22-
pool := types.NewPool(ammPool, math.LegacyMustNewDecFromStr("5.5"))
22+
pool := types.NewPool(ammPool, math.LegacyMustNewDecFromStr("5.5"), math.LegacyMustNewDecFromStr("1.025000000000000000"))
2323
pool.PoolAssetsLong = []types.PoolAsset{
2424
{
2525
Liabilities: math.NewInt(0),

0 commit comments

Comments
 (0)