Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hotfix(core): duplicate Solana ATAP Create instruction info #4389

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions common/defs/solana/programs.json
Original file line number Diff line number Diff line change
@@ -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",
8 changes: 6 additions & 2 deletions core/src/apps/solana/predefined_transaction.py
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@
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)
)
]


97 changes: 97 additions & 0 deletions core/src/apps/solana/transaction/instructions.py
Original file line number Diff line number Diff line change
@@ -101,6 +101,7 @@
_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 get_id(name: str) -> tuple[str, InstructionId]:
_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 @@ class AssociatedTokenAccountProgramCreateInstruction(Instruction):
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,
1 change: 1 addition & 0 deletions core/tests/test_apps.solana.predefined_transaction.py
Original file line number Diff line number Diff line change
@@ -84,6 +84,7 @@
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
20 changes: 20 additions & 0 deletions tests/device_tests/solana/construct/instructions.py
Original file line number Diff line number Diff line change
@@ -1267,6 +1267,7 @@ class Token2022ProgramInstruction(Enum):

class AssociatedTokenAccountProgramInstruction(Enum):
CREATE = None
CREATE1 = 0
CREATE_IDEMPOTENT = 1
RECOVER_NESTED = 2

@@ -1289,6 +1290,24 @@ class AssociatedTokenAccountProgramInstruction(Enum):
),
)

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 @@ class AssociatedTokenAccountProgramInstruction(Enum):

AssociatedTokenAccountProgram_Instruction = Select(
AssociatedTokenAccountProgram_Create,
AssociatedTokenAccountProgram_Create1,
AssociatedTokenAccountProgram_CreateIdempotent,
AssociatedTokenAccountProgram_RecoverNested,
)