diff --git a/core/src/apps/solana/transaction/__init__.py b/core/src/apps/solana/transaction/__init__.py index b0f73cbc19..a1ff290fd6 100644 --- a/core/src/apps/solana/transaction/__init__.py +++ b/core/src/apps/solana/transaction/__init__.py @@ -309,39 +309,19 @@ class Transaction: SOLANA_TOKEN_ACCOUNT_SIZE, ) from ..transaction.instructions import ( - _ASSOCIATED_TOKEN_ACCOUNT_PROGRAM_ID, - _ASSOCIATED_TOKEN_ACCOUNT_PROGRAM_ID_INS_CREATE, - _ASSOCIATED_TOKEN_ACCOUNT_PROGRAM_ID_INS_CREATE_IDEMPOTENT, - _SYSTEM_PROGRAM_ID, - _SYSTEM_PROGRAM_ID_INS_ALLOCATE, - _SYSTEM_PROGRAM_ID_INS_ALLOCATE_WITH_SEED, - _SYSTEM_PROGRAM_ID_INS_CREATE_ACCOUNT, - _SYSTEM_PROGRAM_ID_INS_CREATE_ACCOUNT_WITH_SEED, + is_system_program_account_creation, + is_atap_account_creation, _TOKEN_2022_PROGRAM_ID, _TOKEN_PROGRAM_ID, ) allocation = 0 for instruction in self.instructions: - if instruction.program_id == _SYSTEM_PROGRAM_ID and ( - instruction.instruction_id - in ( - _SYSTEM_PROGRAM_ID_INS_CREATE_ACCOUNT, - _SYSTEM_PROGRAM_ID_INS_CREATE_ACCOUNT_WITH_SEED, - _SYSTEM_PROGRAM_ID_INS_ALLOCATE, - _SYSTEM_PROGRAM_ID_INS_ALLOCATE_WITH_SEED, - ) - ): + if is_system_program_account_creation(instruction): allocation += ( instruction.parsed_data["space"] + SOLANA_ACCOUNT_OVERHEAD_SIZE ) - elif instruction.program_id == _ASSOCIATED_TOKEN_ACCOUNT_PROGRAM_ID and ( - instruction.instruction_id - in ( - _ASSOCIATED_TOKEN_ACCOUNT_PROGRAM_ID_INS_CREATE, - _ASSOCIATED_TOKEN_ACCOUNT_PROGRAM_ID_INS_CREATE_IDEMPOTENT, - ) - ): + elif is_atap_account_creation(instruction): spl_token_account = self.get_account_address( instruction.parsed_accounts["spl_token"] ) diff --git a/core/src/apps/solana/transaction/instructions.py b/core/src/apps/solana/transaction/instructions.py index 76dab98317..5454b38e57 100644 --- a/core/src/apps/solana/transaction/instructions.py +++ b/core/src/apps/solana/transaction/instructions.py @@ -117,6 +117,30 @@ COMPUTE_BUDGET_PROGRAM_ID_INS_SET_COMPUTE_UNIT_PRICE = ( ) +def is_system_program_account_creation(instruction: Instruction) -> bool: + return ( + instruction.program_id == _SYSTEM_PROGRAM_ID + and instruction.instruction_id + in ( + _SYSTEM_PROGRAM_ID_INS_CREATE_ACCOUNT, + _SYSTEM_PROGRAM_ID_INS_CREATE_ACCOUNT_WITH_SEED, + _SYSTEM_PROGRAM_ID_INS_ALLOCATE, + _SYSTEM_PROGRAM_ID_INS_ALLOCATE_WITH_SEED, + ) + ) + + +def is_atap_account_creation(instruction: Instruction) -> bool: + return ( + instruction.program_id == _ASSOCIATED_TOKEN_ACCOUNT_PROGRAM_ID + and instruction.instruction_id + in ( + _ASSOCIATED_TOKEN_ACCOUNT_PROGRAM_ID_INS_CREATE, + _ASSOCIATED_TOKEN_ACCOUNT_PROGRAM_ID_INS_CREATE_IDEMPOTENT, + ) + ) + + def __getattr__(name: str) -> Type[Instruction]: def get_id(name: str) -> tuple[str, InstructionId]: if name == "SystemProgramCreateAccountInstruction": diff --git a/core/src/apps/solana/transaction/instructions.py.mako b/core/src/apps/solana/transaction/instructions.py.mako index 0e7069249e..237ddf2505 100644 --- a/core/src/apps/solana/transaction/instructions.py.mako +++ b/core/src/apps/solana/transaction/instructions.py.mako @@ -83,6 +83,29 @@ COMPUTE_BUDGET_PROGRAM_ID = _COMPUTE_BUDGET_PROGRAM_ID COMPUTE_BUDGET_PROGRAM_ID_INS_SET_COMPUTE_UNIT_LIMIT = _COMPUTE_BUDGET_PROGRAM_ID_INS_SET_COMPUTE_UNIT_LIMIT COMPUTE_BUDGET_PROGRAM_ID_INS_SET_COMPUTE_UNIT_PRICE = _COMPUTE_BUDGET_PROGRAM_ID_INS_SET_COMPUTE_UNIT_PRICE + +def is_system_program_account_creation(instruction: Instruction) -> bool: + return ( + instruction.program_id == _SYSTEM_PROGRAM_ID + and instruction.instruction_id in ( + _SYSTEM_PROGRAM_ID_INS_CREATE_ACCOUNT, + _SYSTEM_PROGRAM_ID_INS_CREATE_ACCOUNT_WITH_SEED, + _SYSTEM_PROGRAM_ID_INS_ALLOCATE, + _SYSTEM_PROGRAM_ID_INS_ALLOCATE_WITH_SEED, + ) + ) + + +def is_atap_account_creation(instruction: Instruction) -> bool: + return ( + instruction.program_id == _ASSOCIATED_TOKEN_ACCOUNT_PROGRAM_ID + and instruction.instruction_id in ( + _ASSOCIATED_TOKEN_ACCOUNT_PROGRAM_ID_INS_CREATE, + _ASSOCIATED_TOKEN_ACCOUNT_PROGRAM_ID_INS_CREATE_IDEMPOTENT, + ) + ) + + def __getattr__(name: str) -> Type[Instruction]: def get_id(name: str) -> tuple[str, InstructionId]: %for program in programs["programs"]: