Skip to content

Commit 2744106

Browse files
authored
Merge pull request #28 from drift-labs/ahzam/add-get-claimable-pnl
expose claimable PNL calculation functions
2 parents 3aca251 + b97b227 commit 2744106

File tree

3 files changed

+39
-4
lines changed

3 files changed

+39
-4
lines changed

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.

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-ffi-sys"
3-
version = "2.154.0"
3+
version = "2.154.2"
44
edition = "2021"
55
description = "FFI bindings to drift program"
66

src/exports.rs

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ use drift_program::{
1515
oracle::{get_oracle_price as get_oracle_price_, OraclePriceData, OracleSource},
1616
oracle_map::OracleMap,
1717
order_params::PlaceOrderOptions,
18-
perp_market::{ContractType, PerpMarket},
18+
perp_market::{ContractType, PerpMarket, AMM},
1919
perp_market_map::PerpMarketMap,
2020
protected_maker_mode_config::ProtectedMakerParams,
2121
revenue_share::RevenueShareOrder,
22-
spot_market::SpotMarket,
22+
spot_market::{SpotBalanceType, SpotMarket},
2323
spot_market_map::SpotMarketMap,
2424
state::{FeeTier, State, ValidityGuardRails},
2525
user::{Order, PerpPosition, SpotPosition, User},
@@ -149,6 +149,16 @@ pub extern "C" fn math_calculate_margin_requirement_and_total_collateral_and_lia
149149
to_ffi_result(m)
150150
}
151151

152+
#[no_mangle]
153+
pub extern "C" fn math_calculate_net_user_pnl(
154+
amm: &AMM,
155+
oracle_price: i64,
156+
) -> FfiResult<compat::i128> {
157+
to_ffi_result(
158+
drift_program::math::amm::calculate_net_user_pnl(amm, oracle_price).map(compat::i128),
159+
)
160+
}
161+
152162
#[no_mangle]
153163
pub extern "C" fn simulate_update_amm(
154164
market: &mut PerpMarket,
@@ -413,6 +423,19 @@ pub extern "C" fn perp_position_get_unrealized_pnl(
413423
to_ffi_result(position.get_unrealized_pnl(oracle_price).map(compat::i128))
414424
}
415425

426+
#[no_mangle]
427+
pub extern "C" fn perp_position_get_claimable_pnl(
428+
position: &PerpPosition,
429+
oracle_price: i64,
430+
pnl_pool_excess: compat::i128,
431+
) -> FfiResult<compat::i128> {
432+
to_ffi_result(
433+
position
434+
.get_claimable_pnl(oracle_price, pnl_pool_excess.0)
435+
.map(compat::i128),
436+
)
437+
}
438+
416439
#[no_mangle]
417440
pub extern "C" fn perp_position_is_available(position: &PerpPosition) -> bool {
418441
position.is_available()
@@ -481,6 +504,18 @@ pub extern "C" fn spot_position_get_token_amount(
481504
to_ffi_result(position.get_token_amount(market).map(compat::u128))
482505
}
483506

507+
#[no_mangle]
508+
pub extern "C" fn spot_balance_get_token_amount(
509+
balance: compat::u128,
510+
spot_market: &SpotMarket,
511+
balance_type: &SpotBalanceType,
512+
) -> FfiResult<compat::u128> {
513+
to_ffi_result(
514+
drift_program::math::spot_balance::get_token_amount(balance.0, spot_market, balance_type)
515+
.map(compat::u128),
516+
)
517+
}
518+
484519
#[no_mangle]
485520
pub extern "C" fn user_get_spot_position(
486521
user: &User,

0 commit comments

Comments
 (0)