Class: Solace::Composers::ZarTrustlessEscrowTokenAccountInitComposer

Inherits:
Base
  • Object
show all
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

Instance Method Details

#build_instruction(context) ⇒ Solace::Instruction

Builds the instruction with resolved account indices.

Parameters:

  • context (Solace::Utils::AccountContext)

    Merged context from TransactionComposer.

Returns:

  • (Solace::Instruction)


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(),
    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_payerString

Extracts the fee payer address from the params

Returns:

  • (String)

    The fee payer address



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

#mintString

Extracts the mint address from the params

Returns:

  • (String)

    The mint address



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_idString

Returns the escrow program id (defaults to the mainnet PROGRAM_ID)

Returns:

  • (String)

    The escrow 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_accountString

Extracts the per-mint program vault address from the params

Returns:

  • (String)

    The program token account address



30
31
32
# File 'lib/solace/zar_trustless_escrow/composers/token_account_init_composer.rb', line 30

def 
  params[:program_token_account].to_s
end

#setup_accountsObject

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
  .add_writable_nonsigner(mint)
  .add_writable_nonsigner()
  .add_writable_signer(fee_payer)
  .add_readonly_nonsigner(system_program)
  .add_readonly_nonsigner(token_program_id)
  .add_readonly_nonsigner(program_id)
end

#system_programString

Returns the System Program id

Returns:

  • (String)

    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_idString

Returns the token program id (defaults to the legacy SPL Token program)

Returns:

  • (String)

    The token program id



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