Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add method to forcefully include market accounts with TransactionBuilder #39

Merged
merged 2 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/drift-ffi-sys
32 changes: 16 additions & 16 deletions crates/src/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,33 +160,33 @@ pub fn calculate_margin_requirement_and_total_collateral_and_liability_info(

impl types::SpotPosition {
pub fn is_available(&self) -> bool {
unsafe { spot_position_is_available(&self) }
unsafe { spot_position_is_available(self) }
}
pub fn get_signed_token_amount(&self, market: &accounts::SpotMarket) -> SdkResult<i128> {
to_sdk_result(unsafe { spot_position_get_signed_token_amount(&self, market) })
to_sdk_result(unsafe { spot_position_get_signed_token_amount(self, market) })
}
pub fn get_token_amount(&self, market: &accounts::SpotMarket) -> SdkResult<u128> {
to_sdk_result(unsafe { spot_position_get_token_amount(&self, market) })
to_sdk_result(unsafe { spot_position_get_token_amount(self, market) })
}
}

impl types::PerpPosition {
pub fn get_unrealized_pnl(&self, oracle_price: i64) -> SdkResult<i128> {
to_sdk_result(unsafe { perp_position_get_unrealized_pnl(&self, oracle_price) })
to_sdk_result(unsafe { perp_position_get_unrealized_pnl(self, oracle_price) })
}
pub fn is_available(&self) -> bool {
unsafe { perp_position_is_available(&self) }
unsafe { perp_position_is_available(self) }
}
pub fn is_open_position(&self) -> bool {
unsafe { perp_position_is_open_position(&self) }
unsafe { perp_position_is_open_position(self) }
}
pub fn worst_case_base_asset_amount(
&self,
oracle_price: i64,
contract_type: ContractType,
) -> SdkResult<i128> {
to_sdk_result(unsafe {
perp_position_worst_case_base_asset_amount(&self, oracle_price, contract_type)
perp_position_worst_case_base_asset_amount(self, oracle_price, contract_type)
})
}
pub fn simulate_settled_lp_position(
Expand All @@ -195,27 +195,27 @@ impl types::PerpPosition {
oracle_price: i64,
) -> SdkResult<types::PerpPosition> {
to_sdk_result(unsafe {
perp_position_simulate_settled_lp_position(&self, market, oracle_price)
perp_position_simulate_settled_lp_position(self, market, oracle_price)
})
}
}

impl accounts::User {
pub fn get_spot_position(&self, market_index: u16) -> SdkResult<types::SpotPosition> {
// TODO: no clone
to_sdk_result(unsafe { user_get_spot_position(&self, market_index) }).map(|p| *p)
to_sdk_result(unsafe { user_get_spot_position(self, market_index) }).copied()
}
pub fn get_perp_position(&self, market_index: u16) -> SdkResult<types::PerpPosition> {
to_sdk_result(unsafe { user_get_perp_position(&self, market_index) }).map(|p| *p)
to_sdk_result(unsafe { user_get_perp_position(self, market_index) }).copied()
}
}

impl types::Order {
pub fn is_limit_order(&self) -> bool {
unsafe { order_is_limit_order(&self) }
unsafe { order_is_limit_order(self) }
}
pub fn is_resting_limit_order(&self, slot: Slot) -> SdkResult<bool> {
to_sdk_result(unsafe { order_is_resting_limit_order(&self, slot) })
to_sdk_result(unsafe { order_is_resting_limit_order(self, slot) })
}
}

Expand All @@ -227,7 +227,7 @@ impl accounts::SpotMarket {
margin_requirement_type: MarginRequirementType,
) -> SdkResult<u32> {
to_sdk_result(unsafe {
spot_market_get_asset_weight(&self, size, oracle_price, margin_requirement_type)
spot_market_get_asset_weight(self, size, oracle_price, margin_requirement_type)
})
}
pub fn get_liability_weight(
Expand All @@ -236,7 +236,7 @@ impl accounts::SpotMarket {
margin_requirement_type: MarginRequirementType,
) -> SdkResult<u32> {
to_sdk_result(unsafe {
spot_market_get_liability_weight(&self, size, margin_requirement_type)
spot_market_get_liability_weight(self, size, margin_requirement_type)
})
}
}
Expand All @@ -247,10 +247,10 @@ impl accounts::PerpMarket {
size: u128,
margin_requirement_type: MarginRequirementType,
) -> SdkResult<u32> {
to_sdk_result(unsafe { perp_market_get_margin_ratio(&self, size, margin_requirement_type) })
to_sdk_result(unsafe { perp_market_get_margin_ratio(self, size, margin_requirement_type) })
}
pub fn get_open_interest(&self) -> u128 {
unsafe { perp_market_get_open_interest(&self) }
unsafe { perp_market_get_open_interest(self) }
}
}

Expand Down
4 changes: 2 additions & 2 deletions crates/src/jit_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ impl JitProxyClient {
drift_program: constants::PROGRAM_ID,
},
&[&params.taker, account_data],
&[],
writable_markets.as_slice(),
[].iter(),
writable_markets.iter(),
);

if let Some(referrer_info) = params.referrer_info {
Expand Down
Loading
Loading