MovePosition Ticket

Overview

The moveposition_simple::ticket module implements ticket-based validation used by MovePosition protocol operations. It handles serialization, deserialization, and validation of operation tickets that ensure secure market interactions. This module is based on basic_ticket_v2.move.

Structs

BasicTicket

Core ticket struct containing operation details and portfolio state.

struct BasicTicket has drop {
    operation: String,
    user: address,
    coin_type: String,
    portfolio_snapshot: PortfolioSnapshot,
    amount: u64,
}

PortfolioSnapshot

Represents the state of user's portfolio at ticket creation time. Listing both the liabilities and collaterals as a mapping of the amounts by coin_type.

struct PortfolioSnapshot has drop {
    liabilities: SimpleMap<String, u64>,
    collaterals: SimpleMap<String, u64>,
}

Error Codes

  • EINVALID_TICKET_OPERATION: Operation doesn't match expected value

  • EINVALID_TICKET_USER: User address doesn't match expected value

  • EINVALID_TICKET_COIN_TYPE: Coin type doesn't match expected value

  • EINVALID_TICKET_AMOUNT: Amount doesn't match expected value

  • EINVALID_TICKET_PORTFOLIO_COLLATERALS: Collateral state mismatch

  • EINVALID_TICKET_PORTFOLIO_LIABILITIES: Liability state mismatch

Public Functions

Deserialization

  • deserialize(data: vector<u8>): BasicTicket: Deserializes binary data into a BasicTicket struct.

Validation Functions

  • validate_operation(ticket: &BasicTicket, operation: String): Validates ticket operation matches expected value.

  • validate_user(ticket: &BasicTicket, u_addr: address): Validates ticket user matches expected address.

  • validate_coin_type<TCoin>(ticket: &BasicTicket): Validates ticket coin type matches generic type.

  • validate_amount(ticket: &BasicTicket, amount: u64): Validates ticket amount matches expected value.

  • validate_portfolio_collaterals(ticket: &BasicTicket, collaterals: &SimpleMap<String, u64>): Validates portfolio collaterals matches expected collaterals.

  • validate_portfolio_liabilities(ticket: &BasicTicket, liabilities: &SimpleMap<String, u64>): Validates portfolio liability matches expected liabilities.

Getters

  • get_amount(ticket: &BasicTicket): u64: Returns the ticket amount.

Internal Functions

  • deserialize_portfolio(cursor: &mut Cursor): PortfolioSnapshot: Deserializes portfolio data from binary format. Helper function for public deserialize function.

  • portfolio_maps_equal(map1: &SimpleMap<String, u64>, map2: &SimpleMap<String, u64>): bool: Compares the keys in two portfolio maps, return true if they match. The order of keys does not need to be identical for this function to return true.

Binary Format Specification

The ticket binary format follows this structure:

  1. Operation string

  2. User address

  3. Coin type string

  4. Portfolio snapshot:

    • Number of collaterals (u64)

    • For each collateral:

      • Coin type string

      • Balance (u64)

    • Number of liabilities (u64)

    • For each liability:

      • Coin type string

      • Balance (u64)

  5. Amount (u64)

Last updated