MovePosition Ticket
Last updated
Last updated
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 .
Core ticket struct containing operation details and portfolio state.
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.
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
deserialize(data: vector<u8>): BasicTicket
: Deserializes binary data into a BasicTicket struct.
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.
get_amount(ticket: &BasicTicket): u64
: Returns the ticket amount.
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.
The ticket binary format follows this structure:
Operation string
User address
Coin type string
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)
Amount (u64)