Skip to content

Commit 3aca251

Browse files
authored
add simulate_update_amm fn for local simulation of AMM position changes (#27)
1 parent dd3c170 commit 3aca251

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/exports.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use abi_stable::std_types::{
99
};
1010
use anchor_lang::prelude::{AccountInfo, AccountLoader};
1111
use drift_program::{
12-
controller::position::PositionDirection,
12+
controller::{position::PositionDirection, repeg::_update_amm},
1313
math::{self, amm::calculate_amm_available_liquidity, margin::MarginRequirementType},
1414
state::{
1515
oracle::{get_oracle_price as get_oracle_price_, OraclePriceData, OracleSource},
@@ -149,6 +149,26 @@ 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 simulate_update_amm(
154+
market: &mut PerpMarket,
155+
state: &State,
156+
mm_oracle_price_data: MMOraclePriceData,
157+
now: u64,
158+
slot: Slot,
159+
) -> FfiResult<compat::i128> {
160+
to_ffi_result(
161+
_update_amm(
162+
market,
163+
&unsafe { std::mem::transmute(mm_oracle_price_data) },
164+
state,
165+
now as i64,
166+
slot,
167+
)
168+
.map(|x| x.into()),
169+
)
170+
}
171+
152172
#[no_mangle]
153173
pub extern "C" fn math_calculate_base_asset_amount_for_amm_to_fulfill(
154174
order: &Order,

0 commit comments

Comments
 (0)