Module 0x7::native_collateral_types

Types crossing the native_collateral Move ↔ native boundary. Field order/widths here pin the BCS encoding the Rust NativeCollateral must match once the primary balance's aggregator snapshot is materialized.

use 0x1::aggregator_v2;

Enum CollateralScope

Balance domain of a collateral entry: the account's cross-margin pool, or the collateral dedicated to one isolated market.

enum CollateralScope has copy, drop, store
Variants
Cross
Fields
Isolated
Fields
market: address

Struct SecondaryBalance

Balance of one secondary collateral asset, in its own units.

struct SecondaryBalance has copy, drop, store
Fields
asset: address
amount: u64

Enum Collateral

primary is the signed primary balance offset by 2^63, as a snapshot so writing it records no read of the aggregator it came from.

enum Collateral has drop, store
Variants
V1
Fields
primary: aggregator_v2::AggregatorSnapshot<u64>
secondaries: vector<native_collateral_types::SecondaryBalance>
reserved: u64

Constants

Offset applied to the signed primary balance so it fits a u64.

const SIGN_OFFSET: u64 = 9223372036854775808;

Function cross

public fun cross(): native_collateral_types::CollateralScope
Implementation
public fun cross(): CollateralScope {
    CollateralScope::Cross
}

Function isolated

public fun isolated(market: address): native_collateral_types::CollateralScope
Implementation
public fun isolated(market: address): CollateralScope {
    CollateralScope::Isolated { market }
}

Function new_secondary_balance

public fun new_secondary_balance(asset: address, amount: u64): native_collateral_types::SecondaryBalance
Implementation
public fun new_secondary_balance(asset: address, amount: u64): SecondaryBalance {
    SecondaryBalance { asset, amount }
}

Function new_collateral_v1

primary must hold the balance offset by 2^63.

public fun new_collateral_v1(primary: aggregator_v2::AggregatorSnapshot<u64>, secondaries: vector<native_collateral_types::SecondaryBalance>, reserved: u64): native_collateral_types::Collateral
Implementation
public fun new_collateral_v1(
    primary: AggregatorSnapshot<u64>,
    secondaries: vector<SecondaryBalance>,
    reserved: u64,
): Collateral {
    Collateral::V1 { primary, secondaries, reserved }
}

Function new_collateral_v1_from_balance

public fun new_collateral_v1_from_balance(primary: i64, secondaries: vector<native_collateral_types::SecondaryBalance>, reserved: u64): native_collateral_types::Collateral
Implementation
public fun new_collateral_v1_from_balance(
    primary: i64,
    secondaries: vector<SecondaryBalance>,
    reserved: u64,
): Collateral {
    let offset = ((primary as i128) + (SIGN_OFFSET as i128)) as u64;
    new_collateral_v1(aggregator_v2::create_snapshot(offset), secondaries, reserved)
}