Module 0x7::native_position_types

Types crossing the native_position Move ↔ native boundary. Field order/widths here pin the BCS encoding the Rust NativePosition must match.

Struct AccumulativeIndex

Signed accumulative index (funding, premium, ...). Wrapping a raw i128 avoids passing the wrong value where an index is expected.

struct AccumulativeIndex has copy, drop, store
Fields
index: i128

Enum Position

All numeric fields are at producer-defined precision; the chain is precision-agnostic.

enum Position has copy, drop, store
Variants
PerpV1
Fields
size: u64
is_long: bool
entry_px_times_size_sum: u128
avg_acquire_entry_px: u64
user_leverage: u8
is_isolated: bool
funding_index_at_last_update: native_position_types::AccumulativeIndex
unrealized_funding_amount_before_last_update: i64
timestamp: u64

Function new_accumulative_index

public fun new_accumulative_index(index: i128): native_position_types::AccumulativeIndex
Implementation
public fun new_accumulative_index(index: i128): AccumulativeIndex {
    AccumulativeIndex { index }
}

Function accumulative_index_value

public fun accumulative_index_value(idx: &native_position_types::AccumulativeIndex): i128
Implementation
public fun accumulative_index_value(idx: &AccumulativeIndex): i128 {
    idx.index
}

Function new_perp_v1

public fun new_perp_v1(size: u64, is_long: bool, entry_px_times_size_sum: u128, avg_acquire_entry_px: u64, user_leverage: u8, is_isolated: bool, funding_index_at_last_update: native_position_types::AccumulativeIndex, unrealized_funding_amount_before_last_update: i64, timestamp: u64): native_position_types::Position
Implementation
public fun new_perp_v1(
    size: u64,
    is_long: bool,
    entry_px_times_size_sum: u128,
    avg_acquire_entry_px: u64,
    user_leverage: u8,
    is_isolated: bool,
    funding_index_at_last_update: AccumulativeIndex,
    unrealized_funding_amount_before_last_update: i64,
    timestamp: u64,
): Position {
    Position::PerpV1 {
        size,
        is_long,
        entry_px_times_size_sum,
        avg_acquire_entry_px,
        user_leverage,
        is_isolated,
        funding_index_at_last_update,
        unrealized_funding_amount_before_last_update,
        timestamp,
    }
}

Function unpack_perp_v1

public fun unpack_perp_v1(pos: native_position_types::Position): (u64, bool, u128, u64, u8, bool, native_position_types::AccumulativeIndex, i64, u64)
Implementation
public fun unpack_perp_v1(
    pos: Position,
): (u64, bool, u128, u64, u8, bool, AccumulativeIndex, i64, u64) {
    let Position::PerpV1 {
        size,
        is_long,
        entry_px_times_size_sum,
        avg_acquire_entry_px,
        user_leverage,
        is_isolated,
        funding_index_at_last_update,
        unrealized_funding_amount_before_last_update,
        timestamp,
    } = pos;
    (
        size,
        is_long,
        entry_px_times_size_sum,
        avg_acquire_entry_px,
        user_leverage,
        is_isolated,
        funding_index_at_last_update,
        unrealized_funding_amount_before_last_update,
        timestamp,
    )
}