Skip to content

Commit 9b4228e

Browse files
committed
Merge branch 'master' into lukas/per-market-lev-swift-plus-more
2 parents ce41149 + 107f0a8 commit 9b4228e

29 files changed

+310
-233
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Features
1111

12+
- program: auction order params account for twap divergence ([#1882](https://github.com/drift-labs/protocol-v2/pull/1882))
13+
- program: add delegate stake if ([#1859](https://github.com/drift-labs/protocol-v2/pull/1859))
14+
15+
### Fixes
16+
17+
### Breaking
18+
19+
## [2.138.0] - 2025-09-22
20+
21+
### Features
22+
1223
- program: support scaled ui extension ([#1894](https://github.com/drift-labs/protocol-v2/pull/1894))
24+
- Revert "Crispeaney/revert swift max margin ratio ([#1877](https://github.com/drift-labs/protocol-v2/pull/1877))
1325

1426
### Fixes
1527

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"prettify:fix": "prettier --write './sdk/src/**/*.ts' './tests/**.ts' './cli/**.ts'",
5151
"lint": "eslint . --ext ts --quiet --format unix",
5252
"lint:fix": "eslint . --ext ts --fix",
53-
"update-idl": "cp target/idl/drift.json sdk/src/idl/drift.json"
53+
"update-idl": "anchor build -- --features anchor-test && cp target/idl/drift.json sdk/src/idl/drift.json"
5454
},
5555
"engines": {
5656
"node": ">=12"

programs/drift/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "drift"
3-
version = "2.137.0"
3+
version = "2.138.0"
44
description = "Created with Anchor"
55
edition = "2018"
66

programs/drift/src/controller/amm.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ use crate::math::amm::calculate_quote_asset_amount_swapped;
1515
use crate::math::amm_spread::{calculate_spread_reserves, get_spread_reserves};
1616
use crate::math::casting::Cast;
1717
use crate::math::constants::{
18-
CONCENTRATION_PRECISION, FEE_ADJUSTMENT_MAX, FEE_POOL_TO_REVENUE_POOL_THRESHOLD,
19-
K_BPS_UPDATE_SCALE, MAX_CONCENTRATION_COEFFICIENT, MAX_K_BPS_INCREASE, MAX_SQRT_K,
18+
CONCENTRATION_PRECISION, FEE_POOL_TO_REVENUE_POOL_THRESHOLD, K_BPS_UPDATE_SCALE,
19+
MAX_CONCENTRATION_COEFFICIENT, MAX_K_BPS_INCREASE, MAX_SQRT_K,
2020
};
2121
use crate::math::cp_curve::get_update_k_result;
2222
use crate::math::repeg::get_total_fee_lower_bound;

programs/drift/src/controller/insurance.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -973,7 +973,7 @@ pub fn handle_if_begin_swap(
973973
out_insurance_fund_vault_amount: u64,
974974
in_spot_market: &mut SpotMarket,
975975
out_spot_market: &mut SpotMarket,
976-
in_amount: u64,
976+
_in_amount: u64,
977977
now: i64,
978978
) -> DriftResult<()> {
979979
if now
@@ -1098,6 +1098,14 @@ pub fn handle_if_end_swap(
10981098
if_rebalance_config.epoch_max_in_amount
10991099
)?;
11001100

1101+
validate!(
1102+
if_rebalance_config.current_in_amount <= if_rebalance_config.total_in_amount,
1103+
ErrorCode::InvalidIfRebalanceSwap,
1104+
"current_in_amount={} > total_in_amount={}",
1105+
if_rebalance_config.current_in_amount,
1106+
if_rebalance_config.total_in_amount
1107+
)?;
1108+
11011109
let oracle_twap = out_spot_market
11021110
.historical_oracle_data
11031111
.last_oracle_price_twap;

programs/drift/src/controller/liquidation.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,9 @@ use crate::math::safe_math::SafeMath;
5050

5151
use crate::math::spot_balance::get_token_value;
5252
use crate::state::events::{
53-
emit_stack, LPAction, LPRecord, LiquidateBorrowForPerpPnlRecord,
54-
LiquidatePerpPnlForDepositRecord, LiquidatePerpRecord, LiquidateSpotRecord, LiquidationRecord,
55-
LiquidationType, OrderAction, OrderActionExplanation, OrderActionRecord, OrderRecord,
56-
PerpBankruptcyRecord, SpotBankruptcyRecord,
53+
LiquidateBorrowForPerpPnlRecord, LiquidatePerpPnlForDepositRecord, LiquidatePerpRecord,
54+
LiquidateSpotRecord, LiquidationRecord, LiquidationType, OrderAction, OrderActionExplanation,
55+
OrderActionRecord, OrderRecord, PerpBankruptcyRecord, SpotBankruptcyRecord,
5756
};
5857
use crate::state::fill_mode::FillMode;
5958
use crate::state::margin_calculation::{MarginCalculation, MarginContext, MarketIdentifier};
@@ -65,7 +64,6 @@ use crate::state::perp_market_map::PerpMarketMap;
6564
use crate::state::spot_market::SpotBalanceType;
6665
use crate::state::spot_market_map::SpotMarketMap;
6766
use crate::state::state::State;
68-
use crate::state::traits::Size;
6967
use crate::state::user::{MarketType, Order, OrderStatus, OrderType, User, UserStats};
7068
use crate::state::user_map::{UserMap, UserStatsMap};
7169
use crate::{get_then_update_id, load_mut, LST_POOL_ID};

programs/drift/src/controller/orders.rs

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,7 @@ use crate::math::spot_balance::{get_signed_token_amount, get_token_amount};
4848
use crate::math::spot_swap::select_margin_type_for_swap;
4949
use crate::math::{amm, fees, margin::*, orders::*};
5050
use crate::print_error;
51-
use crate::state::events::{
52-
emit_stack, get_order_action_record, LPAction, LPRecord, OrderActionRecord, OrderRecord,
53-
};
51+
use crate::state::events::{emit_stack, get_order_action_record, OrderActionRecord, OrderRecord};
5452
use crate::state::events::{OrderAction, OrderActionExplanation};
5553
use crate::state::fill_mode::FillMode;
5654
use crate::state::fulfillment::{PerpFulfillmentMethod, SpotFulfillmentMethod};
@@ -985,23 +983,12 @@ pub fn fill_perp_order(
985983
.position(|order| order.order_id == order_id && order.status == OrderStatus::Open)
986984
.ok_or_else(print_error!(ErrorCode::OrderDoesNotExist))?;
987985

988-
let (
989-
order_status,
990-
market_index,
991-
order_market_type,
992-
order_price,
993-
order_oracle_price_offset,
994-
order_direction,
995-
order_auction_duration,
996-
) = get_struct_values!(
986+
let (order_status, market_index, order_market_type, order_direction) = get_struct_values!(
997987
user.orders[order_index],
998988
status,
999989
market_index,
1000990
market_type,
1001-
price,
1002-
oracle_price_offset,
1003-
direction,
1004-
auction_duration
991+
direction
1005992
);
1006993

1007994
validate!(
@@ -2246,7 +2233,7 @@ pub fn fulfill_perp_order_with_amm(
22462233
filler_reward,
22472234
referee_discount,
22482235
referrer_reward,
2249-
fee_to_market_for_lp,
2236+
fee_to_market_for_lp: _fee_to_market_for_lp,
22502237
maker_rebate,
22512238
} = fees::calculate_fee_for_fulfillment_with_amm(
22522239
user_stats,
@@ -2263,9 +2250,6 @@ pub fn fulfill_perp_order_with_amm(
22632250
user.is_high_leverage_mode(MarginRequirementType::Initial),
22642251
)?;
22652252

2266-
let user_position_delta =
2267-
get_position_delta_for_fill(base_asset_amount, quote_asset_amount, order_direction)?;
2268-
22692253
// Increment the protocol's total fee variables
22702254
market.amm.total_fee = market.amm.total_fee.safe_add(fee_to_market.cast()?)?;
22712255
market.amm.total_exchange_fee = market.amm.total_exchange_fee.safe_add(user_fee.cast()?)?;

programs/drift/src/controller/pnl.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,11 @@ use crate::math::oracle::{is_oracle_valid_for_action, DriftAction};
1414

1515
use crate::math::casting::Cast;
1616
use crate::math::margin::{
17-
calculate_margin_requirement_and_total_collateral_and_liability_info,
1817
meets_maintenance_margin_requirement, meets_settle_pnl_maintenance_margin_requirement,
19-
MarginRequirementType,
2018
};
2119
use crate::math::position::calculate_base_asset_value_with_expiry_price;
2220
use crate::math::safe_math::SafeMath;
2321
use crate::math::spot_balance::get_token_amount;
24-
use crate::state::margin_calculation::MarginContext;
2522

2623
use crate::msg;
2724
use crate::state::events::{OrderActionExplanation, SettlePnlExplanation, SettlePnlRecord};

programs/drift/src/controller/repeg.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use std::cmp::min;
33
use crate::math::oracle::LogMode;
44
use crate::msg;
55
use crate::state::oracle::MMOraclePriceData;
6-
use crate::state::oracle::OraclePriceData;
76
use anchor_lang::prelude::AccountInfo;
87
use anchor_lang::prelude::*;
98

0 commit comments

Comments
 (0)