REVOKE = 5 SET_AUTHORITY = 6 MINT_TO = 7 BURN = 8 CLOSE_ACCOUNT = 9 FREEZE_ACCOUNT = 10 THAW_ACCOUNT = 11 TRANSFER2 = 12 APPROVE2 = 13 MINT_TO2 = 14 BURN2 = 15 _INITIALIZE_MINT_LAYOUT = cStruct( "decimals" / Int8ul, "mint_authority" / PUBLIC_KEY_LAYOUT, "freeze_authority_option" / Int8ul, "freeze_authority" / PUBLIC_KEY_LAYOUT, ) _INITIALIZE_MULTISIG_LAYOUT = cStruct("m" / Int8ul) _AMOUNT_LAYOUT = cStruct("amount" / Int64ul) _SET_AUTHORITY_LAYOUT = cStruct("authority_type" / Int8ul, "new_authority_option" / Int8ul, "new_authority" / PUBLIC_KEY_LAYOUT) _AMOUNT2_LAYOUT = cStruct("amount" / Int64ul, "decimals" / Int8ul) INSTRUCTIONS_LAYOUT = cStruct( "instruction_type" / Int8ul,
Assign = 1 Transfer = 2 CreateAccountWithSeed = 3 AdvanceNonceAccount = 4 WithdrawNonceAccount = 5 InitializeNonceAccount = 6 AuthorizeNonceAccount = 7 Allocate = 8 AllocateWithSeed = 9 AssignWithSeed = 10 TransferWithSeed = 11 _CREATE_ACCOUNT_LAYOUT = cStruct( "lamports" / Int64ul, "space" / Int64ul, "program_id" / PUBLIC_KEY_LAYOUT, ) _ASSIGN_LAYOUT = cStruct("program_id" / PUBLIC_KEY_LAYOUT) _TRANFER_LAYOUT = cStruct("lamports" / Int64ul) _CREATE_ACCOUNT_WTIH_SEED_LAYOUT = cStruct( "base" / PUBLIC_KEY_LAYOUT, "seed" / RUST_STRING_LAYOUT, "lamports" / Int64ul, "space" / Int64ul, "program_id" / PUBLIC_KEY_LAYOUT, )
class InstructionType(IntEnum): InitializeMarket = 0 NewOrder = 1 MatchOrder = 2 ConsumeEvents = 3 CancelOrder = 4 SettleFunds = 5 CancelOrderByClientID = 6 _VERSION = 0 _INITIALIZE_MARKET = cStruct( "base_lot_size" / Int64ul, "quote_lot_size" / Int64ul, "fee_rate_bps" / Int16ul, "vault_signer_nonce" / Int64ul, "quote_dust_threshold" / Int64ul, ) _NEW_ORDER = cStruct( "side" / Int32ul, # Enum "limit_price" / Int64ul, "max_quantity" / Int64ul, "order_type" / Int32ul, # Enum "client_id" / Int64ul, ) _MATCH_ORDERS = cStruct("limit" / Int16ul) _CONSUME_EVENTS = cStruct("limit" / Int16ul)
from construct import Bytes, Int64ul, Padding # type: ignore from construct import Struct as cStruct from .account_flags import ACCOUNT_FLAGS_LAYOUT OPEN_ORDERS_LAYOUT = cStruct( Padding(5), "account_flags" / ACCOUNT_FLAGS_LAYOUT, "market" / Bytes(32), "owner" / Bytes(32), "base_token_free" / Int64ul, "base_token_total" / Int64ul, "quote_token_free" / Int64ul, "quote_token_total" / Int64ul, "free_slot_bits" / Bytes(16), "is_bid_bits" / Bytes(16), "orders" / Bytes(16)[128], "client_ids" / Int64ul[128], "referrer_rebate_accrued" / Int64ul, Padding(7), )
"""Shared layouts.""" from construct import Bytes, Int32ul, Int64ul, PaddedString, Padding # type: ignore from construct import Struct as cStruct FEE_CALCULATOR_LAYOUT = cStruct("lamports_per_signature" / Int64ul) HASH_LAYOUT = Bytes(32) PUBLIC_KEY_LAYOUT = Bytes(32) RUST_STRING_LAYOUT = cStruct( "length" / Int32ul, Padding(4), "chars" / PaddedString(lambda this: this.length, "utf-8"), )
from enum import IntEnum from construct import Switch # type: ignore from construct import Bytes, Int8ul, Int32ul, Int64ul, Padding from construct import Struct as cStruct from .account_flags import ACCOUNT_FLAGS_LAYOUT KEY = Bytes(16) SLAB_HEADER_LAYOUT = cStruct( "bump_index" / Int32ul, Padding(4), "free_list_length" / Int32ul, Padding(4), "free_list_head" / Int32ul, "root" / Int32ul, "leaf_count" / Int32ul, Padding(4), ) class NodeType(IntEnum): UNINTIALIZED = 0 INNER_NODE = 1 LEAF_NODE = 2 FREE_NODE = 3 LAST_FREE_NODE = 4 # Different node types, we pad it all to size of 68 bytes.
from construct import Struct as cStruct # type: ignore from .account_flags import ACCOUNT_FLAGS_LAYOUT MARKET_LAYOUT = cStruct( Padding(5), "account_flags" / ACCOUNT_FLAGS_LAYOUT, "own_address" / Bytes(32), "vault_signer_nonce" / Int64ul, "base_mint" / Bytes(32), "quote_mint" / Bytes(32), "base_vault" / Bytes(32), "base_deposits_total" / Int64ul, "base_fees_accrued" / Int64ul, "quote_vault" / Bytes(32), "quote_deposits_total" / Int64ul, "quote_fees_accrued" / Int64ul, "quote_dust_threshold" / Int64ul, "request_queue" / Bytes(32), "event_queue" / Bytes(32), "bids" / Bytes(32), "asks" / Bytes(32), "base_lot_size" / Int64ul, "quote_lot_size" / Int64ul, "fee_rate_bps" / Int64ul, "referrer_rebate_accrued" / Int64ul, Padding(7), ) MINT_LAYOUT = cStruct(Padding(44), "decimals" / Int8ul, Padding(37))
"""Shared layouts.""" from construct import Bytes, Int32ul, PaddedString, Padding # type: ignore from construct import Struct as cStruct PUBLIC_KEY_LAYOUT = Bytes(32) RUST_STRING_LAYOUT = cStruct( "length" / Int32ul, Padding(4), "chars" / PaddedString(lambda this: this.length, "utf-8"), )
ASSIGN = 1 TRANSFER = 2 CREATE_ACCOUNT_WITH_SEED = 3 ADVANCE_NONCE_ACCOUNT = 4 WITHDRAW_NONCE_ACCOUNT = 5 INITIALIZE_NONCE_ACCOUNT = 6 AUTHORIZE_NONCE_ACCOUNT = 7 ALLOCATE = 8 ALLOCATE_WITH_SEED = 9 ASSIGN_WITH_SEED = 10 TRANSFER_WITH_SEED = 11 _CREATE_ACCOUNT_LAYOUT = cStruct( "lamports" / Int64ul, "space" / Int64ul, "program_id" / PUBLIC_KEY_LAYOUT, ) _ASSIGN_LAYOUT = cStruct("program_id" / PUBLIC_KEY_LAYOUT) _TRANFER_LAYOUT = cStruct("lamports" / Int64ul) _CREATE_ACCOUNT_WTIH_SEED_LAYOUT = cStruct( "base" / PUBLIC_KEY_LAYOUT, "seed" / RUST_STRING_LAYOUT, "lamports" / Int64ul, "space" / Int64ul, "program_id" / PUBLIC_KEY_LAYOUT, )
from construct import BitStruct # type: ignore from construct import BitsInteger, BitsSwapped, Bytes, Const, Flag, Int8ul, Int32ul, Int64ul, Padding from construct import Struct as cStruct # type: ignore from .account_flags import ACCOUNT_FLAGS_LAYOUT QUEUE_HEADER_LAYOUT = cStruct( Padding(5), "account_flags" / ACCOUNT_FLAGS_LAYOUT, "head" / Int32ul, Padding(4), "count" / Int32ul, Padding(4), "next_seq_num" / Int32ul, Padding(4), ) REQUEST_FLAGS_LAYOUT = BitsSwapped( # Swap to little endian BitStruct( "new_order" / Flag, "cancel_order" / Flag, "bid" / Flag, "post_only" / Flag, "ioc" / Flag, Const(0, BitsInteger(3)), # Padding )) REQUEST_LAYOUT = cStruct( "request_flags" / REQUEST_FLAGS_LAYOUT, "open_order_slot" / Int8ul, "fee_tier" / Int8ul,
class StateType(IntEnum): """State type for nonce accounts.""" UNINITIALIZED = 0 INITIALIZED = 1 class VersionsType(IntEnum): """Versions type for nonce accounts.""" CURRENT = 0 _DATA_LAYOUT = cStruct( "authority" / PUBLIC_KEY_LAYOUT, "blockhash" / HASH_LAYOUT, "fee_calculator" / FEE_CALCULATOR_LAYOUT, ) _STATE_LAYOUT = cStruct( "state_type" / Int32ul, "data" / Switch( lambda this: this.state_type, { StateType.UNINITIALIZED: Pass, StateType.INITIALIZED: _DATA_LAYOUT, }, ), ) VERSIONS_LAYOUT = cStruct(
"""Byte layouts for vote program instructions.""" from enum import IntEnum from construct import Switch # type: ignore from construct import Int32ul, Int64ul from construct import Struct as cStruct class InstructionType(IntEnum): """Instruction types for vote program.""" WITHDRAW_FROM_VOTE_ACCOUNT = 3 _WITHDRAW_FROM_VOTE_ACCOUNT_LAYOUT = cStruct("lamports" / Int64ul) VOTE_INSTRUCTIONS_LAYOUT = cStruct( "instruction_type" / Int32ul, "args" / Switch( lambda this: this.instruction_type, { InstructionType.WITHDRAW_FROM_VOTE_ACCOUNT: _WITHDRAW_FROM_VOTE_ACCOUNT_LAYOUT, }, ), )
Revoke = 5 SetAuthority = 6 MintTo = 7 Burn = 8 CloseAccount = 9 FreezeAccount = 10 ThawAccount = 11 Transfer2 = 12 Approve2 = 13 MintTo2 = 14 Burn2 = 15 _INITIALIZE_MINT_LAYOUT = cStruct( "decimals" / Int8ul, "mint_authority" / PUBLIC_KEY_LAYOUT, "freeze_authority_option" / Int8ul, "freeze_authority" / PUBLIC_KEY_LAYOUT, ) _INITIALIZE_MULTISIG_LAYOUT = cStruct("m" / Int8ul) _AMOUNT_LAYOUT = cStruct("amount" / Int64ul) _SET_AUTHORITY_LAYOUT = cStruct("authority_type" / Int8ul, "new_authority_option" / Int8ul, "new_authority" / PUBLIC_KEY_LAYOUT) _AMOUNT2_LAYOUT = cStruct("amount" / Int64ul, "decimals" / Int8ul) INSTRUCTIONS_LAYOUT = cStruct( "instruction_type" / Int8ul,