Revamp svm::send_token#417
Conversation
Greptile SummaryThis PR revamps
Confidence Score: 5/5The change is safe to merge — the logic is correct, the token-2022 upgrade path is handled cleanly, and the helper functions are well-tested. The revamp is straightforward: the program-id is derived from the on-chain mint account so there is no risk of sending a token-2022 mint through the wrong program, No files require special attention; Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[check_signed_executability] --> B{Resolve mint address}
B -->|symbol e.g. 'usdc'| C[get_mainnet_token_by_name]
B -->|raw pubkey string| D[Pubkey::from_str]
C --> E[Fetch mint account via RPC]
D --> E
E --> F[Extract token_program_id + mint_data]
F --> G[derive_send_token_associated_accounts\nsender_ata + recipient_ata]
G --> H{Check recipient_ata on-chain}
H -->|AccountNotFound or lamports==0| I[recipient_needs_funding = true]
H -->|Account exists| J[recipient_needs_funding = false]
I --> K[unpack_mint_decimals from mint_data]
J --> K
K --> L[build_send_token_instructions]
L --> M{recipient_needs_funding?}
M -->|No| N[VecDeque: transfer_checked only]
M -->|Yes, fund_recipient=true| O[VecDeque: create_ata + transfer_checked]
M -->|Yes, fund_recipient=false| P[Error: recipient unfunded]
N --> Q[Build + sign Transaction]
O --> Q
Q --> R[insert_send_token_outputs]
R --> S[run_signed_execution]
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
A[check_signed_executability] --> B{Resolve mint address}
B -->|symbol e.g. 'usdc'| C[get_mainnet_token_by_name]
B -->|raw pubkey string| D[Pubkey::from_str]
C --> E[Fetch mint account via RPC]
D --> E
E --> F[Extract token_program_id + mint_data]
F --> G[derive_send_token_associated_accounts\nsender_ata + recipient_ata]
G --> H{Check recipient_ata on-chain}
H -->|AccountNotFound or lamports==0| I[recipient_needs_funding = true]
H -->|Account exists| J[recipient_needs_funding = false]
I --> K[unpack_mint_decimals from mint_data]
J --> K
K --> L[build_send_token_instructions]
L --> M{recipient_needs_funding?}
M -->|No| N[VecDeque: transfer_checked only]
M -->|Yes, fund_recipient=true| O[VecDeque: create_ata + transfer_checked]
M -->|Yes, fund_recipient=false| P[Error: recipient unfunded]
N --> Q[Build + sign Transaction]
O --> Q
Q --> R[insert_send_token_outputs]
R --> S[run_signed_execution]
Reviews (3): Last reviewed commit: "feat: add get_mainnet_token_by_name" | Re-trigger Greptile |
|
Want your agent to iterate on Greptile's feedback? Try greploops. |
|
@MicaiahReid just tagging you for visibility 👀 |
Closes #324
Besides what was requested in issue 324, few notes:
Add support for token2022 (sending, deriving ATAs). We can use both for spl and t22:
spl_token_2022_interface::instruction::transfer_checked(requires decimal arg, which is obtained decoding the mint account. Base layout is shared between both programs)Added tests for some functions and helpers.
For the funding ata recipient case: we could use the idempotent ix to create the ATA to save 1 RPC call to check if the ATA exists, but then in the output we can't know for sure if the ATA was actually created or not.
.txfile I used for e2e testing: