pub struct VaultState {
pub total_assets: u128,
pub total_shares: u128,
pub idle_assets: u128,
pub external_assets: u128,
pub fee_anchor: FeeAccrualAnchor,
pub op_state: OpState,
pub withdraw_queue: WithdrawQueue,
pub next_op_id: u64,
}Expand description
Core kernel vault state.
This struct contains all the state managed by the kernel. Chain-specific executors are responsible for:
- Persisting this state to storage
- Handling share/asset token balances
§Invariants
total_assets == idle_assets + external_assetswithdraw_queue.check_invariants()next_op_idis monotonically increasing- Operations can only proceed when
op_stateallows them
Fields§
§total_assets: u128§idle_assets: u128§external_assets: u128§fee_anchor: FeeAccrualAnchor§op_state: OpState§withdraw_queue: WithdrawQueue§next_op_id: u64Implementations§
Source§impl VaultState
impl VaultState
pub fn new() -> Self
pub fn with_initial( total_assets: u128, total_shares: u128, idle_assets: u128, external_assets: u128, timestamp_ns: TimestampNs, ) -> Self
Sourcepub fn check_invariant(&self) -> bool
pub fn check_invariant(&self) -> bool
Check the fundamental accounting invariant.
Returns true if total_assets == idle_assets + external_assets.
Sourcepub fn allocate_op_id(&mut self) -> u64
pub fn allocate_op_id(&mut self) -> u64
Allocate and return the next operation ID.
Increments next_op_id and returns the previous value.
Sourcepub fn current_op_id(&self) -> Option<u64>
pub fn current_op_id(&self) -> Option<u64>
Get the current operation ID if an operation is in progress.
Sourcepub fn sync_total_assets(&mut self)
pub fn sync_total_assets(&mut self)
Recompute total_assets from idle_assets + external_assets.
Call this after any mutation of idle_assets or external_assets
to restore the fundamental accounting invariant.
Sourcepub fn restore_to_idle(&mut self, amount: u128)
pub fn restore_to_idle(&mut self, amount: u128)
Add amount back to idle assets and recompute totals.
Common pattern during abort / emergency-reset paths where in-flight assets are returned to idle.
Trait Implementations§
Source§impl BorshDeserialize for VaultState
impl BorshDeserialize for VaultState
fn deserialize_reader<__R: Read>(reader: &mut __R) -> Result<Self, Error>
§fn deserialize(buf: &mut &[u8]) -> Result<Self, Error>
fn deserialize(buf: &mut &[u8]) -> Result<Self, Error>
Deserializes this instance from a given slice of bytes.
Updates the buffer to point at the remaining bytes.
§fn try_from_slice(v: &[u8]) -> Result<Self, Error>
fn try_from_slice(v: &[u8]) -> Result<Self, Error>
Deserialize this instance from a slice of bytes.
fn try_from_reader<R>(reader: &mut R) -> Result<Self, Error>where
R: Read,
Source§impl BorshSerialize for VaultState
impl BorshSerialize for VaultState
Source§impl Clone for VaultState
impl Clone for VaultState
Source§fn clone(&self) -> VaultState
fn clone(&self) -> VaultState
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for VaultState
impl Debug for VaultState
Source§impl Default for VaultState
impl Default for VaultState
Source§impl<'de> Deserialize<'de> for VaultState
impl<'de> Deserialize<'de> for VaultState
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl PartialEq for VaultState
impl PartialEq for VaultState
Source§impl Serialize for VaultState
impl Serialize for VaultState
impl Eq for VaultState
impl StructuralPartialEq for VaultState
Auto Trait Implementations§
impl Freeze for VaultState
impl RefUnwindSafe for VaultState
impl Send for VaultState
impl Sync for VaultState
impl Unpin for VaultState
impl UnwindSafe for VaultState
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more