1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-04-04 17:36:02 +00:00

hotfix(core): duplicate Solana ATAP Create instruction info

so that empty data and 0x00 data do the same thing, before we figure out
whether this is an always thing, or a sometimes thing, and implement a
little saner solution
This commit is contained in:
matejcik 2024-11-26 15:03:49 +01:00
parent 00f947d35a
commit d36055208b
5 changed files with 186 additions and 2 deletions

View File

@ -3003,6 +3003,68 @@
}
]
},
{
"id": 0,
"name": "Create1",
"is_multisig": false,
"parameters": [],
"references": [
{
"name": "funding_account",
"is_authority": true,
"optional": false
},
{
"name": "associated_token_account",
"is_authority": false,
"optional": false
},
{
"name": "wallet_address",
"is_authority": false,
"optional": false
},
{
"name": "token_mint",
"is_authority": false,
"optional": false
},
{
"name": "system_program",
"is_authority": false,
"optional": false
},
{
"name": "spl_token",
"is_authority": false,
"optional": false
},
{
"//": "Some dApps still include the rent sysvar although it's not officially required anymore.",
"name": "rent_sysvar",
"is_authority": false,
"optional": true
}
],
"ui_properties": [
{
"account": "associated_token_account",
"display_name": "Create token account"
},
{
"account": "token_mint",
"display_name": "For token"
},
{
"account": "wallet_address",
"display_name": "Owned by"
},
{
"account": "funding_account",
"display_name": "Funded by"
}
]
},
{
"id": 1,
"name": "Create Idempotent",

View File

@ -5,6 +5,7 @@ from trezor.crypto import base58
from .transaction import Transaction
from .transaction.instructions import (
AssociatedTokenAccountProgramCreateInstruction,
AssociatedTokenAccountProgramCreate1Instruction,
Instruction,
Token2022ProgramTransferCheckedInstruction,
TokenProgramTransferCheckedInstruction,
@ -32,11 +33,14 @@ def get_token_transfer_instructions(
def get_create_associated_token_account_instructions(
instructions: list[Instruction],
) -> list[AssociatedTokenAccountProgramCreateInstruction]:
) -> list[AssociatedTokenAccountProgramCreateInstruction | AssociatedTokenAccountProgramCreate1Instruction]:
return [
instruction
for instruction in instructions
if AssociatedTokenAccountProgramCreateInstruction.is_type_of(instruction)
if (
AssociatedTokenAccountProgramCreateInstruction.is_type_of(instruction)
or AssociatedTokenAccountProgramCreate1Instruction.is_type_of(instruction)
)
]

View File

@ -101,6 +101,7 @@ _TOKEN_2022_PROGRAM_ID_INS_SYNC_NATIVE = const(17)
_TOKEN_2022_PROGRAM_ID_INS_INITIALIZE_ACCOUNT_3 = const(18)
_TOKEN_2022_PROGRAM_ID_INS_INITIALIZE_IMMUTABLE_OWNER = const(22)
_ASSOCIATED_TOKEN_ACCOUNT_PROGRAM_ID_INS_CREATE = None
_ASSOCIATED_TOKEN_ACCOUNT_PROGRAM_ID_INS_CREATE1 = const(0)
_ASSOCIATED_TOKEN_ACCOUNT_PROGRAM_ID_INS_CREATE_IDEMPOTENT = const(1)
_ASSOCIATED_TOKEN_ACCOUNT_PROGRAM_ID_INS_RECOVER_NESTED = const(2)
_MEMO_PROGRAM_ID_INS_MEMO = None
@ -283,6 +284,11 @@ def __getattr__(name: str) -> Type[Instruction]:
_ASSOCIATED_TOKEN_ACCOUNT_PROGRAM_ID,
_ASSOCIATED_TOKEN_ACCOUNT_PROGRAM_ID_INS_CREATE,
)
if name == "AssociatedTokenAccountProgramCreate1Instruction":
return (
_ASSOCIATED_TOKEN_ACCOUNT_PROGRAM_ID,
_ASSOCIATED_TOKEN_ACCOUNT_PROGRAM_ID_INS_CREATE1,
)
if name == "AssociatedTokenAccountProgramCreateIdempotentInstruction":
return (
_ASSOCIATED_TOKEN_ACCOUNT_PROGRAM_ID,
@ -790,6 +796,16 @@ if TYPE_CHECKING:
spl_token: Account
rent_sysvar: Account | None
class AssociatedTokenAccountProgramCreate1Instruction(Instruction):
funding_account: Account
associated_token_account: Account
wallet_address: Account
token_mint: Account
system_program: Account
spl_token: Account
rent_sysvar: Account | None
class AssociatedTokenAccountProgramCreateIdempotentInstruction(Instruction):
funding_account: Account
@ -5223,6 +5239,87 @@ def get_instruction(
False,
None,
)
if instruction_id == _ASSOCIATED_TOKEN_ACCOUNT_PROGRAM_ID_INS_CREATE1:
return Instruction(
instruction_data,
program_id,
instruction_accounts,
_ASSOCIATED_TOKEN_ACCOUNT_PROGRAM_ID_INS_CREATE1,
[],
[
AccountTemplate(
"funding_account",
True,
False,
),
AccountTemplate(
"associated_token_account",
False,
False,
),
AccountTemplate(
"wallet_address",
False,
False,
),
AccountTemplate(
"token_mint",
False,
False,
),
AccountTemplate(
"system_program",
False,
False,
),
AccountTemplate(
"spl_token",
False,
False,
),
AccountTemplate(
"rent_sysvar",
False,
True,
),
],
[
UIProperty(
None,
"associated_token_account",
"Create token account",
False,
None,
),
UIProperty(
None,
"token_mint",
"For token",
False,
None,
),
UIProperty(
None,
"wallet_address",
"Owned by",
False,
None,
),
UIProperty(
None,
"funding_account",
"Funded by",
False,
None,
),
],
"Associated Token Account Program: Create1",
True,
True,
False,
False,
None,
)
if instruction_id == _ASSOCIATED_TOKEN_ACCOUNT_PROGRAM_ID_INS_CREATE_IDEMPOTENT:
return Instruction(
instruction_data,

View File

@ -84,6 +84,7 @@ TOKEN_2022_PROGRAM_ID_INS_SYNC_NATIVE = 17
TOKEN_2022_PROGRAM_ID_INS_INITIALIZE_ACCOUNT_3 = 18
TOKEN_2022_PROGRAM_ID_INS_INITIALIZE_IMMUTABLE_OWNER = 22
ASSOCIATED_TOKEN_ACCOUNT_PROGRAM_ID_INS_CREATE = None
ASSOCIATED_TOKEN_ACCOUNT_PROGRAM_ID_INS_CREATE1 = 0
ASSOCIATED_TOKEN_ACCOUNT_PROGRAM_ID_INS_CREATE_IDEMPOTENT = 1
ASSOCIATED_TOKEN_ACCOUNT_PROGRAM_ID_INS_RECOVER_NESTED = 2
MEMO_PROGRAM_ID_INS_MEMO = None

View File

@ -1267,6 +1267,7 @@ Token2022Program_Instruction = Select(
class AssociatedTokenAccountProgramInstruction(Enum):
CREATE = None
CREATE1 = 0
CREATE_IDEMPOTENT = 1
RECOVER_NESTED = 2
@ -1289,6 +1290,24 @@ AssociatedTokenAccountProgram_Create = Struct(
),
)
AssociatedTokenAccountProgram_Create1 = Struct(
"program_index" / Byte,
"accounts"
/ CompactStruct(
"funding_account" / Byte,
"associated_token_account" / Byte,
"wallet_address" / Byte,
"token_mint" / Byte,
"system_program" / Byte,
"spl_token" / Byte,
"rent_sysvar" / Optional(Byte),
),
"data"
/ CompactStruct(
"instruction_id" / Const(0, Byte),
),
)
AssociatedTokenAccountProgram_CreateIdempotent = Struct(
"program_index" / Byte,
"accounts"
@ -1327,6 +1346,7 @@ AssociatedTokenAccountProgram_RecoverNested = Struct(
AssociatedTokenAccountProgram_Instruction = Select(
AssociatedTokenAccountProgram_Create,
AssociatedTokenAccountProgram_Create1,
AssociatedTokenAccountProgram_CreateIdempotent,
AssociatedTokenAccountProgram_RecoverNested,
)