Skip to content

Commit f59d3a7

Browse files
authored
Merge pull request #185 from mars-protocol/perps
Perps release
2 parents c82858d + 02ca7cd commit f59d3a7

File tree

416 files changed

+56252
-6084
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

416 files changed

+56252
-6084
lines changed

CHANGELOG.md

Lines changed: 215 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,221 @@
22

33
All notable changes to this project will be documented in this file.
44

5+
## v2.2.0 - Neutron Perps release
6+
7+
### Perps Integration
8+
- Added new `perps` contract with perps functionality integrated into Credit Manager
9+
10+
### Credit Manager Enhancements
11+
- Integrated perps positions as account collateral, with direct impact on account Health Factor
12+
- Implemented flexible loss settlement mechanism for perps:
13+
- First attempts to deduct from existing deposits
14+
- If deposits are insufficient, will unlock lending positions
15+
- As a last resort, will borrow the required USDC amount
16+
17+
#### New Execute Messages
18+
- Added execute messages:
19+
- `UpdateBalanceAfterDeleverage`
20+
- `ExecuteTriggerOrder`
21+
22+
#### New Actions
23+
- Introduced new actions:
24+
- `DepositToPerpVault`
25+
- `UnlockFromPerpVault`
26+
- `WithdrawFromPerpVault`
27+
- `CreateTriggerOrder`
28+
- `DeleteTriggerOrder`
29+
- `ExecutePerpOrder`
30+
31+
#### New Queries
32+
- Added queries:
33+
- `AllAccountTriggerOrders`
34+
- `AllTriggerOrders`
35+
- Updated `Positions` query to include perps positions
36+
37+
#### Positions Struct Update
38+
```diff
39+
pub struct Positions {
40+
pub account_id: String,
41+
pub account_kind: AccountKind,
42+
pub deposits: Vec<Coin>,
43+
pub debts: Vec<DebtAmount>,
44+
pub lends: Vec<Coin>,
45+
pub vaults: Vec<VaultPosition>,
46+
pub staked_astro_lps: Vec<Coin>,
47+
+ pub perps: Vec<PerpPosition>, // New field
48+
}
49+
```
50+
51+
### Liquidation Mechanism
52+
#### Perps Liquidation
53+
- Implemented comprehensive perps liquidation process:
54+
- When an account becomes liquidatable, perps positions are closed first
55+
- Normal liquidation executes after perps closure
56+
- If closing perps is sufficient to restore account health, liquidator receives a bonus
57+
- Liquidation bonus calculation:
58+
- Uses the same bonus mechanism as general liquidation (based on Health Factor)
59+
- Bonus specifically reduced to 60% to prevent over-rewarding
60+
- Added `perps_liquidation_bonus_ratio` to Credit Manager configuration
61+
- Special liquidation scenario:
62+
- Liquidation possible even when no spot debt exists
63+
- Triggered if perps positions could potentially bring account Health Factor below 1
64+
- Allows liquidator to close perps at a loss without additional debt repayment
65+
66+
#### Liquidation Changes
67+
- Simplified liquidation mechanism by changing to static close factor
68+
- Removed Max Debt Repayable (MDR) formula for dynamic bonus calculation in Credit Manager and Red Bank
69+
70+
### Health Calculations
71+
- Health Contract now includes calculations based on perps positions
72+
- Returns additional perp loss and profit information
73+
- Removed `kind` from health-related queries
74+
- HealthComputer integrated into CreditManager to reduce gas consumption
75+
76+
#### Health Struct Update
77+
```diff
78+
pub struct Health {
79+
pub total_debt_value: Uint128,
80+
pub total_collateral_value: Uint128,
81+
pub max_ltv_adjusted_collateral: Uint128,
82+
pub liquidation_threshold_adjusted_collateral: Uint128,
83+
pub max_ltv_health_factor: Option<Decimal>,
84+
pub liquidation_health_factor: Option<Decimal>,
85+
+ pub perps_pnl_profit: Uint128, // New field
86+
+ pub perps_pnl_loss: Uint128, // New field
87+
+ pub has_perps: bool, // New field
88+
}
89+
```
90+
91+
### Oracle and Pricing
92+
- Introduced Slinky oracle price support for perps
93+
- Added new Oracle contract query for prices by denoms
94+
95+
### Incentives Contract
96+
- Added support for perpetual vault deposit incentives
97+
- New execute and query messages to handle perps-related incentives
98+
- `SetAssetIncentive` with support for different incentive kinds
99+
- Updated reward claiming and emission tracking
100+
101+
#### Incentives Contract Struct Updates
102+
```diff
103+
// Execute Message
104+
pub enum ExecuteMsg {
105+
SetAssetIncentive {
106+
+ kind: IncentiveKind, // New field
107+
+ denom: String, // New field
108+
incentive_denom: String,
109+
emission_per_second: Uint128,
110+
start_time: u64,
111+
duration: u64,
112+
},
113+
114+
BalanceChange {
115+
user_addr: Addr,
116+
account_id: Option<String>,
117+
+ kind: IncentiveKind, // New field
118+
denom: String,
119+
- user_amount_scaled_before: Uint128,
120+
+ user_amount: Uint128, // Updated field
121+
- total_amount_scaled_before: Uint128,
122+
+ total_amount: Uint128, // Updated field
123+
},
124+
125+
ClaimRewards {
126+
account_id: Option<String>,
127+
+ start_after_kind: Option<IncentiveKind>, // New field
128+
- start_after_collateral_denom: Option<String>,
129+
+ start_after_denom: Option<String>, // Updated field
130+
start_after_incentive_denom: Option<String>,
131+
limit: Option<u32>,
132+
}
133+
}
134+
135+
// Query Messages
136+
pub enum QueryMsg {
137+
ActiveEmissions {
138+
+ kind: IncentiveKind, // New field
139+
- collateral_denom: String,
140+
+ denom: String, // Updated field
141+
},
142+
143+
IncentiveState {
144+
+ kind: IncentiveKind, // New field
145+
- collateral_denom: String,
146+
+ denom: String, // Updated field
147+
incentive_denom: String,
148+
},
149+
150+
IncentiveStates {
151+
+ start_after_kind: Option<IncentiveKind>, // New field
152+
- start_after_collateral_denom: Option<String>,
153+
+ start_after_denom: Option<String>, // Updated field
154+
start_after_incentive_denom: Option<String>,
155+
limit: Option<u32>,
156+
},
157+
158+
Emission {
159+
+ kind: IncentiveKind, // New field
160+
- collateral_denom: String,
161+
+ denom: String, // Updated field
162+
incentive_denom: String,
163+
timestamp: u64,
164+
},
165+
166+
UserUnclaimedRewards {
167+
user: String,
168+
account_id: Option<String>,
169+
+ start_after_kind: Option<IncentiveKind>, // New field
170+
- start_after_collateral_denom: Option<String>,
171+
+ start_after_denom: Option<String>, // Updated field
172+
start_after_incentive_denom: Option<String>,
173+
limit: Option<u32>,
174+
}
175+
}
176+
```
177+
178+
### Params Contract
179+
- Added Perps params setup and queries
180+
- New configurations:
181+
- Maximum number of perps
182+
- Risk Owner role to modify market parameters
183+
- `withdraw_enabled` for Credit Manager and Red Bank settings for Assets
184+
- Introduced paginated queries for asset parameters
185+
186+
#### Params Contract Struct Updates
187+
```diff
188+
pub enum ExecuteMsg {
189+
+ UpdatePerpParams(PerpParamsUpdate), // New execute message
190+
191+
// Existing messages...
192+
}
193+
194+
pub enum QueryMsg {
195+
+ PerpParams { // New query
196+
denom: String,
197+
},
198+
199+
+ AllPerpParams { // New query
200+
start_after: Option<String>,
201+
limit: Option<u32>,
202+
},
203+
204+
+ AllPerpParamsV2 { // New paginated query
205+
start_after: Option<String>,
206+
limit: Option<u32>,
207+
},
208+
209+
+ AllAssetParamsV2 { // New paginated query for assets
210+
start_after: Option<String>,
211+
limit: Option<u32>,
212+
}
213+
}
214+
```
215+
216+
### Miscellaneous
217+
- Enhanced HealthComputer with Perps-aligned functions and added max_perp_size parameter to support frontend requirements
218+
- Removed `QueryMsg::AccountKind` call in account-nft contract
219+
5220
## v1.2.0
6221

7222
- Allow Credit account to lend/reclaim to the Red Bank (calls Deposit/Withdraw in Red Bank), claim incentive rewards from lending to the Red Bank (pass account_id to track Credit Manager users in `red-bank` and `incentives` contract).

0 commit comments

Comments
 (0)