1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-05-08 09:58:46 +00:00

feat(core/solana): implement diffable textual representation of supported programs

This commit is contained in:
matejcik 2025-04-25 14:36:46 +02:00 committed by matejcik
parent f9ee2f8a29
commit 4a3e2728ca
3 changed files with 725 additions and 1 deletions

View File

@ -0,0 +1,689 @@
_This file is generated by `programs.md.mako` via `make solana_templates`, do not edit manually._
## System Program
`11111111111111111111111111111111`
### (0) Create Account
| Label | Value | Type |
|-------|-------|------|
| Create account | `new_account` | `account` |
| Deposit | `lamports` | `lamports` |
| From | `funding_account` | `account` |
| _(not shown)_ | `space` | `u64` |
| _(not shown)_ | `owner` | `authority` |
### (1) Assign
| Label | Value | Type |
|-------|-------|------|
| Assign account | `assigned_account` | `account` |
| Assign account to program | `owner` | `authority` |
### (2) Transfer
| Label | Value | Type |
|-------|-------|------|
| Recipient | `recipient_account` | `account` |
| Amount | `lamports` | `lamports` |
| Sender | `funding_account` | `account` |
### (3) Create Account With Seed
| Label | Value | Type |
|-------|-------|------|
| Create account | `created_account` | `account` |
| Deposit | `lamports` | `lamports` |
| From | `funding_account` | `account` |
| _(not shown)_ | `base` | `pubkey` |
| _(not shown)_ | `seed` | `string` |
| _(not shown)_ | `space` | `u64` |
| _(not shown)_ | `owner` | `pubkey` |
| _(not shown)_ | `base_account` | `account` |
### (4) Advance Nonce Account
| Label | Value | Type |
|-------|-------|------|
| Advance nonce | `nonce_account` | `account` |
| Authorized by | `nonce_authority` | `account` |
| _(not shown)_ | `recent_blockhashes_sysvar` | `account` |
### (5) Withdraw Nonce Account
| Label | Value | Type |
|-------|-------|------|
| Nonce withdraw | `lamports` | `lamports` |
| From | `nonce_account` | `account` |
| To | `recipient_account` | `account` |
| Authorized by | `nonce_authority` | `account` |
| _(not shown)_ | `recent_blockhashes_sysvar` | `account` |
| _(not shown)_ | `rent_sysvar` | `account` |
### (6) Initialize Nonce Account
| Label | Value | Type |
|-------|-------|------|
| Initialize nonce account | `nonce_account` | `account` |
| New authority | `nonce_authority` | `authority` |
| _(not shown)_ | `recent_blockhashes_sysvar` | `account` |
| _(not shown)_ | `rent_sysvar` | `account` |
### (7) Authorize Nonce Account
| Label | Value | Type |
|-------|-------|------|
| Set nonce authority | `nonce_account` | `account` |
| New authority | `nonce_authority` | `authority` |
| Authorized by | `nonce_authority` | `account` |
### (8) Allocate
| Label | Value | Type |
|-------|-------|------|
| Allocate account | `new_account` | `account` |
| Data size | `space` | `u64` |
### (9) Allocate With Seed
| Label | Value | Type |
|-------|-------|------|
| Allocate data for account | `allocated_account` | `account` |
| Data size | `space` | `u64` |
| _(not shown)_ | `base` | `pubkey` |
| _(not shown)_ | `seed` | `string` |
| _(not shown)_ | `owner` | `pubkey` |
| _(not shown)_ | `base_account` | `account` |
### (10) Assign With Seed
| Label | Value | Type |
|-------|-------|------|
| Assign account | `assigned_account` | `account` |
| Assign account to program | `owner` | `pubkey` |
| _(not shown)_ | `base` | `pubkey` |
| _(not shown)_ | `seed` | `string` |
| _(not shown)_ | `base_account` | `account` |
### (11) Transfer With Seed
| Label | Value | Type |
|-------|-------|------|
| Recipient | `recipient_account` | `account` |
| Amount | `lamports` | `lamports` |
| Sender | `funding_account` | `account` |
| _(not shown)_ | `from_seed` | `string` |
| _(not shown)_ | `from_owner` | `pubkey` |
| _(not shown)_ | `base_account` | `account` |
### (12) Upgrade Nonce Account
| Label | Value | Type |
|-------|-------|------|
| Upgrade nonce account | `nonce_account` | `account` |
## Stake Program
`Stake11111111111111111111111111111111111111`
### (0) Initialize
| Label | Value | Type |
|-------|-------|------|
| Initialize stake account | `uninitialized_stake_account` | `account` |
| New stake authority | `staker` | `authority` |
| New withdraw authority | `withdrawer` | `authority` |
| Lockup time | `unix_timestamp` | `unix_timestamp` |
| Lockup epoch | `epoch` | `u64` |
| Lockup authority | `custodian` | `authority` |
| _(not shown)_ | `rent_sysvar` | `account` |
### (1) Authorize
| Label | Value | Type |
|-------|-------|------|
| Set authority for | `stake_account` | `account` |
| New authority | `pubkey` | `pubkey` |
| Authority type | `stake_authorize` | `StakeAuthorize` |
| Authorized by | `stake_or_withdraw_authority` | `account` |
| Custodian | `lockup_authority` | `account` |
| _(not shown)_ | `clock_sysvar` | `account` |
### (2) Delegate Stake
| Label | Value | Type |
|-------|-------|------|
| Delegate from | `initialized_stake_account` | `account` |
| Authorized by | `stake_authority` | `account` |
| Vote account | `vote_account` | `account` |
| _(not shown)_ | `clock_sysvar` | `account` |
| _(not shown)_ | `stake_history_sysvar` | `account` |
| _(not shown)_ | `config_account` | `account` |
### (3) Split
| Label | Value | Type |
|-------|-------|------|
| Split stake | `lamports` | `lamports` |
| From | `stake_account` | `account` |
| To | `uninitialized_stake_account` | `account` |
| Authorized by | `stake_authority` | `account` |
### (4) Withdraw
| Label | Value | Type |
|-------|-------|------|
| Withdraw stake | `lamports` | `lamports` |
| From | `stake_account` | `account` |
| To | `recipient_account` | `account` |
| Authorized by | `withdrawal_authority` | `account` |
| _(not shown)_ | `clock_sysvar` | `account` |
| _(not shown)_ | `stake_history_sysvar` | `account` |
| _(not shown)_ | `lockup_authority` | `account` |
### (5) Deactivate
| Label | Value | Type |
|-------|-------|------|
| Deactivate stake account | `delegated_stake_account` | `account` |
| Authorized by | `stake_authority` | `account` |
| _(not shown)_ | `clock_sysvar` | `account` |
### (6) Set Lockup
| Label | Value | Type |
|-------|-------|------|
| Set lockup for account | `initialized_stake_account` | `account` |
| Time | `unix_timestamp` | `unix_timestamp` |
| Epoch | `epoch` | `u64` |
| New lockup authority | `custodian` | `pubkey` |
| Authorized by | `lockup_or_withdraw_authority` | `account` |
### (7) Merge
| Label | Value | Type |
|-------|-------|------|
| Merge stake account | `source_stake_account` | `account` |
| Into | `destination_stake_account` | `account` |
| Authorized by | `stake_authority` | `account` |
| _(not shown)_ | `clock_sysvar` | `account` |
| _(not shown)_ | `stake_history_sysvar` | `account` |
### (8) Authorize With Seed
| Label | Value | Type |
|-------|-------|------|
| Set authority for | `stake_account` | `account` |
| New authority | `new_authorized_pubkey` | `pubkey` |
| Authority type | `stake_authorize` | `StakeAuthorize` |
| Authorized by | `stake_or_withdraw_authority` | `account` |
| Custodian | `lockup_authority` | `account` |
| _(not shown)_ | `authority_seed` | `string` |
| _(not shown)_ | `authority_owner` | `pubkey` |
| _(not shown)_ | `clock_sysvar` | `account` |
### (9) Initialize Checked
| Label | Value | Type |
|-------|-------|------|
| Uninitialized stake account | `uninitialized_stake_account` | `account` |
| New stake authority | `stake_authority` | `account` |
| New withdraw authority | `withdrawal_authority` | `account` |
| _(not shown)_ | `rent_sysvar` | `account` |
### (10) Authorize Checked
| Label | Value | Type |
|-------|-------|------|
| Set authority for | `stake_account` | `account` |
| New authority | `new_stake_or_withdraw_authority` | `account` |
| Authority type | `stake_authorize` | `StakeAuthorize` |
| Authorized by | `stake_or_withdraw_authority` | `account` |
| Custodian | `lockup_authority` | `account` |
| _(not shown)_ | `clock_sysvar` | `account` |
### (11) Authorize Checked With Seed
| Label | Value | Type |
|-------|-------|------|
| Set authority for | `stake_account` | `account` |
| New authority | `new_stake_or_withdraw_authority` | `account` |
| Authority type | `stake_authorize` | `StakeAuthorize` |
| Authorized by | `stake_or_withdraw_authority` | `account` |
| Custodian | `lockup_authority` | `account` |
| _(not shown)_ | `authority_seed` | `string` |
| _(not shown)_ | `authority_owner` | `pubkey` |
| _(not shown)_ | `clock_sysvar` | `account` |
### (12) Set Lockup Checked
| Label | Value | Type |
|-------|-------|------|
| Set lockup for stake account | `stake_account` | `account` |
| Time | `unix_timestamp` | `unix_timestamp` |
| Epoch | `epoch` | `u64` |
| New lockup authority | `new_lockup_authority` | `account` |
| Authorized by | `lockup_or_withdraw_authority` | `account` |
## Compute Budget Program
`ComputeBudget111111111111111111111111111111`
### (1) Request Heap Frame
| Label | Value | Type |
|-------|-------|------|
| Bytes | `bytes` | `u32` |
### (2) Set Compute Unit Limit
| Label | Value | Type |
|-------|-------|------|
| Units | `units` | `u32` |
### (3) Set Compute Unit Price
| Label | Value | Type |
|-------|-------|------|
| Compute unit price | `lamports` | `u64` |
## Token Program
`TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA`
### (1) Initialize Account
| Label | Value | Type |
|-------|-------|------|
| Initialize account | `account_to_initialize` | `account` |
| Owner | `owner` | `account` |
| For token | `mint_account` | `account` |
| _(not shown)_ | `rent_sysvar` | `account` |
### (2) Initialize Multisig
| Label | Value | Type |
|-------|-------|------|
| Initialize multisig | `multisig_account` | `account` |
| Required signers | `signer_accounts` | `account` |
| _(not shown)_ | `number_of_signers` | `u8` |
| _(not shown)_ | `rent_sysvar` | `account` |
### (3) Transfer
| Label | Value | Type |
|-------|-------|------|
| Recipient | `destination_account` | `account` |
| Amount | `amount` | `u64` |
| From | `source_account` | `account` |
| Owner | `owner` | `account` |
### (4) Approve
| Label | Value | Type |
|-------|-------|------|
| Approve delegate | `delegate_account` | `account` |
| Allowance | `amount` | `u64` |
| Owner | `owner` | `account` |
| _(not shown)_ | `source_account` | `account` |
### (5) Revoke
| Label | Value | Type |
|-------|-------|------|
| Revoke delegate | `source_account` | `account` |
| Owner | `owner` | `account` |
### (6) Set Authority
| Label | Value | Type |
|-------|-------|------|
| Set authority for | `mint_account` | `account` |
| New authority | `new_authority` | `authority` |
| Authority type | `authority_type` | `AuthorityType` |
| Current authority | `current_authority` | `account` |
### (7) Mint To
| Label | Value | Type |
|-------|-------|------|
| Mint tokens | `amount` | `u64` |
| To | `account_to_mint` | `account` |
| Mint authority | `minting_authority` | `account` |
| _(not shown)_ | `mint` | `account` |
### (8) Burn
| Label | Value | Type |
|-------|-------|------|
| Burn tokens | `amount` | `u64` |
| From | `account_to_burn_from` | `account` |
| Mint authority | `owner` | `account` |
| _(not shown)_ | `token_mint` | `account` |
### (9) Close Account
| Label | Value | Type |
|-------|-------|------|
| Close account | `account_to_close` | `account` |
| Withdraw to | `destination_account` | `account` |
| Owner | `owner` | `account` |
### (10) Freeze Account
| Label | Value | Type |
|-------|-------|------|
| Freeze account | `account_to_freeze` | `account` |
| Owner | `freeze_authority` | `account` |
| _(not shown)_ | `token_mint` | `account` |
### (11) Thaw Account
| Label | Value | Type |
|-------|-------|------|
| Thaw account | `account_to_freeze` | `account` |
| Owner | `freeze_authority` | `account` |
| _(not shown)_ | `token_mint` | `account` |
### (12) Transfer Checked
| Label | Value | Type |
|-------|-------|------|
| Token | `token_mint` | `account` |
| Recipient | `destination_account` | `account` |
| Amount | `amount` | `token_amount` |
| From | `source_account` | `account` |
| Owner | `owner` | `account` |
| _(not shown)_ | `decimals` | `u8` |
### (13) Approve Checked
| Label | Value | Type |
|-------|-------|------|
| Approve token | `token_mint` | `account` |
| Approve delegate | `delegate` | `account` |
| Allowance | `amount` | `token_amount` |
| From | `source_account` | `account` |
| Owner | `owner` | `account` |
| _(not shown)_ | `decimals` | `u8` |
### (14) Mint to Checked
| Label | Value | Type |
|-------|-------|------|
| Mint token | `mint` | `account` |
| Mint amount | `amount` | `token_amount` |
| To | `account_to_mint` | `account` |
| Owner | `minting_authority` | `account` |
| _(not shown)_ | `decimals` | `u8` |
### (15) Burn Checked
| Label | Value | Type |
|-------|-------|------|
| Burn token | `token_mint` | `account` |
| Burn amount | `amount` | `token_amount` |
| From | `account_to_burn_from` | `account` |
| Owner | `owner` | `account` |
| _(not shown)_ | `decimals` | `u8` |
### (16) Initialize Account 2
| Label | Value | Type |
|-------|-------|------|
| Initialize account | `account_to_initialize` | `account` |
| Owner | `owner` | `pubkey` |
| For token | `mint_account` | `account` |
| _(not shown)_ | `rent_sysvar` | `account` |
### (17) Sync Native
| Label | Value | Type |
|-------|-------|------|
| Sync native account | `token_account` | `account` |
### (18) Initialize Account 3
| Label | Value | Type |
|-------|-------|------|
| Initialize account | `account_to_initialize` | `account` |
| Owner | `owner` | `pubkey` |
| For token | `mint_account` | `account` |
### (22) Initialize Immutable Owner
| Label | Value | Type |
|-------|-------|------|
| Init account | `account_to_initialize` | `account` |
## Token 2022 Program
`TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb`
### (1) Initialize Account
| Label | Value | Type |
|-------|-------|------|
| Initialize account | `account_to_initialize` | `account` |
| Owner | `owner` | `account` |
| For token | `mint_account` | `account` |
| _(not shown)_ | `rent_sysvar` | `account` |
### (2) Initialize Multisig
| Label | Value | Type |
|-------|-------|------|
| Init multisig | `multisig_account` | `account` |
| Required signers | `signer_accounts` | `account` |
| _(not shown)_ | `number_of_signers` | `u8` |
| _(not shown)_ | `rent_sysvar` | `account` |
### (3) Transfer
| Label | Value | Type |
|-------|-------|------|
| Recipient | `destination_account` | `account` |
| Amount | `amount` | `u64` |
| From | `source_account` | `account` |
| Owner | `owner` | `account` |
### (4) Approve
| Label | Value | Type |
|-------|-------|------|
| Approve delegate | `delegate_account` | `account` |
| Allowance | `amount` | `u64` |
| Owner | `owner` | `account` |
| _(not shown)_ | `source_account` | `account` |
### (5) Revoke
| Label | Value | Type |
|-------|-------|------|
| Rewoke delegate | `source_account` | `account` |
| Owner | `owner` | `account` |
### (6) Set Authority
| Label | Value | Type |
|-------|-------|------|
| Set authority for | `mint_account` | `account` |
| New authority | `new_authority` | `authority` |
| Authority type | `authority_type` | `AuthorityType` |
| Current authority | `current_authority` | `account` |
### (7) Mint to
| Label | Value | Type |
|-------|-------|------|
| Mint tokens | `amount` | `u64` |
| To | `account_to_mint` | `account` |
| Mint authority | `minting_authority` | `account` |
| _(not shown)_ | `mint` | `account` |
### (8) Burn
| Label | Value | Type |
|-------|-------|------|
| Burn tokens | `amount` | `u64` |
| From | `account_to_burn_from` | `account` |
| Mint authority | `owner` | `account` |
| _(not shown)_ | `token_mint` | `account` |
### (9) Close Account
| Label | Value | Type |
|-------|-------|------|
| Close account | `account_to_close` | `account` |
| Withdraw to | `destination_account` | `account` |
| Owner | `owner` | `account` |
### (10) Freeze Account
| Label | Value | Type |
|-------|-------|------|
| Freeze account | `account_to_freeze` | `account` |
| Owner | `freeze_authority` | `account` |
| _(not shown)_ | `token_mint` | `account` |
### (11) Thaw Account
| Label | Value | Type |
|-------|-------|------|
| Thaw account | `account_to_freeze` | `account` |
| Owner | `freeze_authority` | `account` |
| _(not shown)_ | `token_mint` | `account` |
### (12) Transfer Checked
| Label | Value | Type |
|-------|-------|------|
| Token | `token_mint` | `account` |
| Recipient | `destination_account` | `account` |
| Amount | `amount` | `token_amount` |
| From | `source_account` | `account` |
| Owner | `owner` | `account` |
| _(not shown)_ | `decimals` | `u8` |
### (13) Approve Checked
| Label | Value | Type |
|-------|-------|------|
| Approve token | `token_mint` | `account` |
| Approve delegate | `delegate` | `account` |
| Allowance | `amount` | `token_amount` |
| From | `source_account` | `account` |
| Owner | `owner` | `account` |
| _(not shown)_ | `decimals` | `u8` |
### (14) Mint to Checked
| Label | Value | Type |
|-------|-------|------|
| Mint token | `mint` | `account` |
| Mint amount | `amount` | `token_amount` |
| To | `account_to_mint` | `account` |
| Owner | `minting_authority` | `account` |
| _(not shown)_ | `decimals` | `u8` |
### (15) Burn Checked
| Label | Value | Type |
|-------|-------|------|
| Burn token | `token_mint` | `account` |
| Burn amount | `amount` | `token_amount` |
| From | `account_to_burn_from` | `account` |
| Owner | `owner` | `account` |
| _(not shown)_ | `decimals` | `u8` |
### (16) Initialize Account 2
| Label | Value | Type |
|-------|-------|------|
| Initialize account | `account_to_initialize` | `account` |
| Owner | `owner` | `pubkey` |
| For token | `mint_account` | `account` |
| _(not shown)_ | `rent_sysvar` | `account` |
### (17) Sync Native
| Label | Value | Type |
|-------|-------|------|
| Sync native account | `token_account` | `account` |
### (18) Initialize Account 3
| Label | Value | Type |
|-------|-------|------|
| Initialize account | `account_to_initialize` | `account` |
| Owner | `owner` | `pubkey` |
| For token | `mint_account` | `account` |
### (22) Initialize Immutable Owner
| Label | Value | Type |
|-------|-------|------|
| Initialize immutable owner extension for account | `account_to_initialize` | `account` |
## Associated Token Account Program
`ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL`
### (None) Create
| Label | Value | Type |
|-------|-------|------|
| Create token account | `associated_token_account` | `account` |
| For token | `token_mint` | `account` |
| Owned by | `wallet_address` | `account` |
| Funded by | `funding_account` | `account` |
| _(not shown)_ | `system_program` | `account` |
| _(not shown)_ | `spl_token` | `account` |
| _(not shown)_ | `rent_sysvar` | `account` |
### (1) Create Idempotent
| Label | Value | Type |
|-------|-------|------|
| Create token account | `associated_token_account` | `account` |
| For token | `token_mint` | `account` |
| Owned by | `wallet_addr` | `account` |
| Funded by | `funding_account` | `account` |
| _(not shown)_ | `system_program` | `account` |
| _(not shown)_ | `spl_token` | `account` |
### (2) Recover Nested
| Label | Value | Type |
|-------|-------|------|
| Recover nested token account | `nested_account` | `account` |
| Transfer recovered tokens to | `associated_token_account` | `account` |
| Transfer recovered SOL to | `wallet_address` | `account` |
| _(not shown)_ | `token_mint_nested` | `account` |
| _(not shown)_ | `owner` | `account` |
| _(not shown)_ | `token_mint_owner` | `account` |
| _(not shown)_ | `spl_token` | `account` |
## Memo Program
`MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr`
### (None) Memo
| Label | Value | Type |
|-------|-------|------|
| Memo | `memo` | `memo` |
| Signer accounts | `signer_accounts` | `account` |
## Memo Legacy Program
`Memo1UhkJRfHyvLMcVucJwxXeuD728EqVDDwQDxFMNo`
### (None) Memo
| Label | Value | Type |
|-------|-------|------|
| Memo | `memo` | `memo` |
| Signer accounts | `signer_accounts` | `account` |

View File

@ -0,0 +1,33 @@
_This file is generated by `programs.md.mako` via `make solana_templates`, do not edit manually._
% for program in programs.programs:
${'##'} ${program.name}
`${program.id}`
% for instruction in program.instructions:
${'###'} (${instruction.id}) ${instruction.name}
<%
all_params = { param.name: param for param in instruction.parameters }
all_accounts = [ref.name for ref in instruction.references]
%>
| Label | Value | Type |
|-------|-------|------|
% for prop in instruction.ui_properties:
% if "account" in prop:
| ${prop.display_name} | `${prop.account}` | `account` |
<% all_accounts.remove(prop.account) %>\
% else:
| ${prop.display_name} | `${prop.parameter}` | `${all_params[prop.parameter].type}` |
<% del all_params[prop.parameter] %>\
% endif
% endfor
% for param in all_params.values():
| _(not shown)_ | `${param.name}` | `${param.type}` |
% endfor
% for account in all_accounts:
| _(not shown)_ | `${account}` | `account` |
% endfor
% endfor
% endfor

View File

@ -13,6 +13,7 @@ HERE = Path(__file__).parent
ROOT = HERE.parent.resolve()
TEMPLATES = (
ROOT / "common" / "defs" / "solana" / "programs.md.mako",
ROOT / "core" / "src" / "apps" / "solana" / "transaction" / "instructions.py.mako",
ROOT / "tests" / "device_tests" / "solana" / "construct" / "instructions.py.mako",
ROOT / "core" / "tests" / "test_apps.solana.predefined_transaction.py.mako",
@ -38,7 +39,8 @@ def render_single(template_path: Path, programs: Munch) -> str:
f.flush()
# after flushing the contents, on-disk file will be formatted...
format(Path(f.name))
if ".py" in template_path.suffixes:
format(Path(f.name))
# ...and we need to explicitly open it again to get the updated contents,
# otherwise we get cached results?
with open(f.name, "r") as new_f: