Class: Solace::Composers::ZarTrustlessEscrowTokenAccountInitComposer
- Inherits:
-
Base
- Object
- Base
- Solace::Composers::ZarTrustlessEscrowTokenAccountInitComposer
- Defined in:
- lib/solace/zar_trustless_escrow/composers/token_account_init_composer.rb
Overview
Composes a ‘token_account_init` instruction for the ZAR Trustless Escrow program.
Initializes the per-mint program vault token account if it does not already exist. A single vault is shared across all deposits for a given mint.
Required params:
:mint [#to_s] Mint the vault holds.
:program_token_account [#to_s] Per-mint program vault PDA.
:fee_payer [#to_s, Keypair] Fee payer (writable signer).
Optional params:
:program_id [#to_s] Escrow program id (default: PROGRAM_ID, mainnet).
:token_program_id [#to_s] Token program (default: legacy SPL Token).
Instance Method Summary collapse
-
#build_instruction(context) ⇒ Solace::Instruction
Builds the instruction with resolved account indices.
-
#fee_payer ⇒ String
Extracts the fee payer address from the params.
-
#mint ⇒ String
Extracts the mint address from the params.
-
#program_id ⇒ String
Returns the escrow program id (defaults to the mainnet PROGRAM_ID).
-
#program_token_account ⇒ String
Extracts the per-mint program vault address from the params.
-
#setup_accounts ⇒ Object
Declares all accounts required by this instruction.
-
#system_program ⇒ String
Returns the System Program id.
-
#token_program_id ⇒ String
Returns the token program id (defaults to the legacy SPL Token program).
Instance Method Details
#build_instruction(context) ⇒ Solace::Instruction
Builds the instruction with resolved account indices.
76 77 78 79 80 81 82 83 84 85 |
# File 'lib/solace/zar_trustless_escrow/composers/token_account_init_composer.rb', line 76 def build_instruction(context) Solace::ZarTrustlessEscrow::Instructions::TokenAccountInitInstruction.build( mint_index: context.index_of(mint), program_token_account_index: context.index_of(program_token_account), fee_payer_index: context.index_of(fee_payer), system_program_index: context.index_of(system_program), token_program_index: context.index_of(token_program_id), program_index: context.index_of(program_id) ) end |
#fee_payer ⇒ String
Extracts the fee payer address from the params
37 38 39 |
# File 'lib/solace/zar_trustless_escrow/composers/token_account_init_composer.rb', line 37 def fee_payer params[:fee_payer].to_s end |
#mint ⇒ String
Extracts the mint address from the params
23 24 25 |
# File 'lib/solace/zar_trustless_escrow/composers/token_account_init_composer.rb', line 23 def mint params[:mint].to_s end |
#program_id ⇒ String
Returns the escrow program id (defaults to the mainnet PROGRAM_ID)
44 45 46 |
# File 'lib/solace/zar_trustless_escrow/composers/token_account_init_composer.rb', line 44 def program_id (params[:program_id] || Solace::ZarTrustlessEscrow::PROGRAM_ID).to_s end |
#program_token_account ⇒ String
Extracts the per-mint program vault address from the params
30 31 32 |
# File 'lib/solace/zar_trustless_escrow/composers/token_account_init_composer.rb', line 30 def program_token_account params[:program_token_account].to_s end |
#setup_accounts ⇒ Object
Declares all accounts required by this instruction.
63 64 65 66 67 68 69 70 |
# File 'lib/solace/zar_trustless_escrow/composers/token_account_init_composer.rb', line 63 def setup_accounts account_context.add_writable_nonsigner(mint) account_context.add_writable_nonsigner(program_token_account) account_context.add_writable_signer(fee_payer) account_context.add_readonly_nonsigner(system_program) account_context.add_readonly_nonsigner(token_program_id) account_context.add_readonly_nonsigner(program_id) end |
#system_program ⇒ String
Returns the System Program id
58 59 60 |
# File 'lib/solace/zar_trustless_escrow/composers/token_account_init_composer.rb', line 58 def system_program Solace::Constants::SYSTEM_PROGRAM_ID end |
#token_program_id ⇒ String
Returns the token program id (defaults to the legacy SPL Token program)
51 52 53 |
# File 'lib/solace/zar_trustless_escrow/composers/token_account_init_composer.rb', line 51 def token_program_id (params[:token_program_id] || Solace::Constants::TOKEN_PROGRAM_ID).to_s end |