Skip to content

Commit 46ed536

Browse files
committed
fix: adjust rpc ix for isolated position transfer
1 parent 8ac4a8a commit 46ed536

File tree

1 file changed

+31
-28
lines changed

1 file changed

+31
-28
lines changed

src/swift_server.rs

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ pub async fn process_order(
239239
uuid,
240240
},
241241
max_margin_ratio,
242-
is_isolated_deposit,
242+
isolated_position_deposit,
243243
) = extract_signed_message_info(signed_msg, &taker_authority, current_slot)?;
244244

245245
log::info!(
@@ -302,7 +302,7 @@ pub async fn process_order(
302302
delegate_signer,
303303
current_slot,
304304
max_margin_ratio,
305-
is_isolated_deposit,
305+
isolated_position_deposit,
306306
context,
307307
)
308308
.await
@@ -1062,7 +1062,7 @@ impl ServerParams {
10621062
delegate_signer: Option<&Pubkey>,
10631063
slot: Slot,
10641064
max_margin_ratio: Option<u16>,
1065-
is_isolated_deposit: bool,
1065+
isolated_deposit: Option<u64>,
10661066
context: &RequestContext,
10671067
) -> Result<SimulationStatus, (axum::http::StatusCode, String, Option<Vec<String>>)> {
10681068
let mut sim_result = SimulationStatus::Disabled;
@@ -1132,7 +1132,14 @@ impl ServerParams {
11321132
SystemTime::now().duration_since(t0)
11331133
);
11341134

1135-
if self.simulate_taker_order_local(taker_order_params, &mut user, max_margin_ratio, context)
1135+
// TODO: isolated deposits need changes for local simming
1136+
if isolated_deposit.is_none()
1137+
&& self.simulate_taker_order_local(
1138+
taker_order_params,
1139+
&mut user,
1140+
max_margin_ratio,
1141+
context,
1142+
)
11361143
{
11371144
sim_result = SimulationStatus::Success;
11381145
log::info!(
@@ -1158,6 +1165,12 @@ impl ServerParams {
11581165
margin_ratio,
11591166
);
11601167
}
1168+
if let Some(amount) = isolated_deposit {
1169+
tx = tx.transfer_isolated_perp_position_deposit(
1170+
amount as i64,
1171+
taker_order_params.market_index,
1172+
);
1173+
}
11611174
let message = tx.place_orders(vec![*taker_order_params]).build();
11621175

11631176
let simulate_result_with_timeout = tokio::time::timeout(
@@ -1196,7 +1209,7 @@ impl ServerParams {
11961209
// insufficient collateral is prone to precision errors, allow the order through with some leniency
11971210
// EXCEPT for isolated deposits, where we want to return the error to the client
11981211
if code == ProgramError::Drift(ErrorCode::InsufficientCollateral)
1199-
&& !is_isolated_deposit
1212+
&& isolated_deposit.is_none()
12001213
{
12011214
if let Some(ref logs) = res.value.logs {
12021215
if let Some(collateral_ratio) = extract_collateral_ratio(logs) {
@@ -1526,24 +1539,14 @@ fn validate_order(
15261539
Ok(())
15271540
}
15281541

1529-
fn is_isolated_deposit(signed_msg: &SignedOrderType) -> bool {
1530-
match signed_msg {
1531-
SignedOrderType::Delegated { inner, .. } => inner
1532-
.isolated_position_deposit
1533-
.is_some_and(|amount| amount > 0),
1534-
SignedOrderType::Authority { inner, .. } => inner
1535-
.isolated_position_deposit
1536-
.is_some_and(|amount| amount > 0),
1537-
}
1538-
}
1539-
15401542
fn extract_signed_message_info(
15411543
signed_msg: &SignedOrderType,
15421544
taker_authority: &Pubkey,
15431545
current_slot: Slot,
1544-
) -> Result<(SignedMessageInfo, Option<u16>, bool), (axum::http::StatusCode, ProcessOrderResponse)>
1545-
{
1546-
let is_isolated = is_isolated_deposit(signed_msg);
1546+
) -> Result<
1547+
(SignedMessageInfo, Option<u16>, Option<u64>),
1548+
(axum::http::StatusCode, ProcessOrderResponse),
1549+
> {
15471550
match signed_msg {
15481551
SignedOrderType::Delegated { inner, .. } => {
15491552
validate_order(
@@ -1560,7 +1563,7 @@ fn extract_signed_message_info(
15601563
slot: inner.slot,
15611564
},
15621565
inner.max_margin_ratio,
1563-
is_isolated,
1566+
inner.isolated_position_deposit,
15641567
))
15651568
}
15661569
SignedOrderType::Authority { inner, .. } => {
@@ -1581,7 +1584,7 @@ fn extract_signed_message_info(
15811584
slot: inner.slot,
15821585
},
15831586
inner.max_margin_ratio,
1584-
is_isolated,
1587+
inner.isolated_position_deposit,
15851588
))
15861589
}
15871590
}
@@ -2070,7 +2073,7 @@ mod tests {
20702073
});
20712074
assert!(!is_isolated_deposit(&delegated_msg));
20722075
let result = extract_signed_message_info(&delegated_msg, &taker_authority, current_slot);
2073-
assert!(result.is_ok_and(|(_, _, is_isolated)| !is_isolated));
2076+
assert!(result.is_ok_and(|(_, _, is_isolated)| is_isolated.is_none()));
20742077

20752078
// Test delegated order with isolated deposit of 0 (should be false)
20762079
let delegated_msg = SignedOrderType::delegated(SignedMsgOrderParamsDelegateMessage {
@@ -2095,7 +2098,7 @@ mod tests {
20952098
});
20962099
assert!(!is_isolated_deposit(&delegated_msg));
20972100
let result = extract_signed_message_info(&delegated_msg, &taker_authority, current_slot);
2098-
assert!(result.is_ok_and(|(_, _, is_isolated)| !is_isolated));
2101+
assert!(result.is_ok_and(|(_, _, is_isolated)| is_isolated.is_none()));
20992102

21002103
// Test delegated order with isolated deposit > 0
21012104
let delegated_msg = SignedOrderType::delegated(SignedMsgOrderParamsDelegateMessage {
@@ -2120,7 +2123,7 @@ mod tests {
21202123
});
21212124
assert!(is_isolated_deposit(&delegated_msg));
21222125
let result = extract_signed_message_info(&delegated_msg, &taker_authority, current_slot);
2123-
assert!(result.is_ok_and(|(_, _, is_isolated)| is_isolated));
2126+
assert!(result.is_ok_and(|(_, _, is_isolated)| is_isolated.is_some()));
21242127

21252128
// Test authority order with no isolated deposit
21262129
let authority_msg = SignedOrderType::authority(SignedMsgOrderParamsMessage {
@@ -2145,7 +2148,7 @@ mod tests {
21452148
});
21462149
assert!(!is_isolated_deposit(&authority_msg));
21472150
let result = extract_signed_message_info(&authority_msg, &taker_authority, current_slot);
2148-
assert!(result.is_ok_and(|(_, _, is_isolated)| !is_isolated));
2151+
assert!(result.is_ok_and(|(_, _, is_isolated)| is_isolated.is_none()));
21492152

21502153
// Test authority order with isolated deposit > 0
21512154
let authority_msg = SignedOrderType::authority(SignedMsgOrderParamsMessage {
@@ -2170,7 +2173,7 @@ mod tests {
21702173
});
21712174
assert!(is_isolated_deposit(&authority_msg));
21722175
let result = extract_signed_message_info(&authority_msg, &taker_authority, current_slot);
2173-
assert!(result.is_ok_and(|(_, _, is_isolated)| is_isolated));
2176+
assert!(result.is_ok_and(|(_, _, is_isolated)| is_isolated.is_some()));
21742177
}
21752178

21762179
#[tokio::test]
@@ -2250,7 +2253,7 @@ mod tests {
22502253
Some(&delegate_pubkey),
22512254
1_000,
22522255
None,
2253-
false,
2256+
None,
22542257
&context_primary,
22552258
)
22562259
.await;
@@ -2276,7 +2279,7 @@ mod tests {
22762279
Some(&delegate_pubkey),
22772280
1_000,
22782281
None,
2279-
false,
2282+
None,
22802283
&context_secondary,
22812284
)
22822285
.await;

0 commit comments

Comments
 (0)