pub struct NamedEngine {
pub engine: RiskEngine,
pub accounts: BTreeMap<String, u16>,
pub current_slot: u64,
pub last_oracle_price: u64,
pub last_funding_rate: i64,
/* private fields */
}Expand description
Human-readable wrapper around the Percolator RiskEngine.
Maps string account names to u16 indices, tracks oracle/slot/funding state, and provides ergonomic methods for deposits, withdrawals, trades, and cranks.
Fields§
§engine: RiskEngine§accounts: BTreeMap<String, u16>§current_slot: u64§last_oracle_price: u64§last_funding_rate: i64Implementations§
Source§impl NamedEngine
impl NamedEngine
Sourcepub fn new(params: RiskParams, init_slot: u64, init_oracle_price: u64) -> Self
pub fn new(params: RiskParams, init_slot: u64, init_oracle_price: u64) -> Self
Create a new engine with the given risk parameters, slot, and oracle price.
Sourcepub fn resolve(&self, name: &str) -> Result<u16, EngineError>
pub fn resolve(&self, name: &str) -> Result<u16, EngineError>
Resolve an account name to its index. Returns error if not found.
Sourcepub fn deposit(&mut self, name: &str, amount: u128) -> Result<(), EngineError>
pub fn deposit(&mut self, name: &str, amount: u128) -> Result<(), EngineError>
Deposit collateral into an account. Creates the account if it doesn’t exist.
Sourcepub fn withdraw(&mut self, name: &str, amount: u128) -> Result<(), EngineError>
pub fn withdraw(&mut self, name: &str, amount: u128) -> Result<(), EngineError>
Withdraw collateral from an account. Fails if the account would breach margin.
Sourcepub fn trade(
&mut self,
long: &str,
short: &str,
size_q: i128,
exec_price: u64,
) -> Result<(), EngineError>
pub fn trade( &mut self, long: &str, short: &str, size_q: i128, exec_price: u64, ) -> Result<(), EngineError>
Execute a trade between two accounts. size_q is in POS_SCALE units.
Sourcepub fn crank(
&mut self,
oracle_price: u64,
slot: u64,
) -> Result<CrankOutcome, EngineError>
pub fn crank( &mut self, oracle_price: u64, slot: u64, ) -> Result<CrankOutcome, EngineError>
Run the keeper crank at the given oracle price and slot.
Sourcepub fn liquidate(&mut self, name: &str) -> Result<bool, EngineError>
pub fn liquidate(&mut self, name: &str) -> Result<bool, EngineError>
Attempt to liquidate an account. Returns true if liquidation occurred.
Sourcepub fn settle(&mut self, name: &str) -> Result<(), EngineError>
pub fn settle(&mut self, name: &str) -> Result<(), EngineError>
Settle an account’s PnL against the vault.
pub fn set_oracle(&mut self, oracle_price: u64) -> Result<(), EngineError>
pub fn set_slot(&mut self, slot: u64)
pub fn set_funding_rate(&mut self, rate: i64)
Sourcepub fn snapshot(&self) -> EngineSnapshot
pub fn snapshot(&self) -> EngineSnapshot
Capture a complete snapshot of the engine state.