Class: Solace::Composers::AssociatedTokenAccountProgramCreateAccountComposer

Inherits:
Base
  • Object
show all
Defined in:
lib/solace/composers/associated_token_account_program_create_account_composer.rb

Overview

Composer for creating an associated token account program create account instruction

This composer resolves and orders the required accounts for a ‘CreateAssociatedTokenAccount` instruction, sets up their access permissions, and delegates construction to the appropriate instruction builder (`Instructions::AssociatedTokenAccount::CreateAssociatedTokenAccountInstruction`).

Required accounts:

  • Funder: the account that will pay for fees and rent.

  • Owner: the account that will own the new ATA.

  • ATA: the address of the new ATA.

  • Mint: the mint address of the token.

  • **System Program**: the system program id.

  • **Token Program**: the token program id.

  • **Associated Token Account Program**: the associated token account program id.

Examples:

Compose and build a create account instruction

composer = AssociatedTokenAccountProgramCreateAccountComposer.new(
  funder: funder_address,
  owner: owner_address,
  ata_address: ata_address,
  mint: mint_address
)

See Also:

Since:

  • 0.0.7

Instance Attribute Summary

Attributes inherited from Base

#account_context, #params

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Solace::Composers::Base

Instance Method Details

#associated_token_account_program_idString

Extracts the associated token account program id from the constants

Returns:

  • (String)

    The associated token account program id

Since:

  • 0.0.7



76
77
78
# File 'lib/solace/composers/associated_token_account_program_create_account_composer.rb', line 76

def 
  Constants::.to_s
end

#ata_addressString

Extracts the ata_address from the params

Returns:

  • (String)

    The ata_address

Since:

  • 0.0.7



48
49
50
# File 'lib/solace/composers/associated_token_account_program_create_account_composer.rb', line 48

def ata_address
  params[:ata_address].to_s
end

#build_instruction(account_context) ⇒ Solace::Instruction

Builds the instruction for the associated token account program create account instruction

Parameters:

Returns:

Since:

  • 0.0.7



98
99
100
101
102
103
104
105
106
107
108
# File 'lib/solace/composers/associated_token_account_program_create_account_composer.rb', line 98

def build_instruction()
  Instructions::AssociatedTokenAccount::CreateAssociatedTokenAccountInstruction.build(
    funder_index: .index_of(funder),
    owner_index: .index_of(owner),
    mint_index: .index_of(mint),
    associated_token_account_index: .index_of(ata_address),
    system_program_index: .index_of(system_program_id),
    token_program_index: .index_of(token_program_id),
    program_index: .index_of()
  )
end

#funderString

Extracts the funder address from the params

Returns:

  • (String)

    The funder address

Since:

  • 0.0.7



55
56
57
# File 'lib/solace/composers/associated_token_account_program_create_account_composer.rb', line 55

def funder
  params[:funder].to_s
end

#mintString

Extracts the mint address from the params

Returns:

  • (String)

    The mint address

Since:

  • 0.0.7



41
42
43
# File 'lib/solace/composers/associated_token_account_program_create_account_composer.rb', line 41

def mint
  params[:mint].to_s
end

#ownerString

Extracts the owner address from the params

Returns:

  • (String)

    The owner address

Since:

  • 0.0.7



34
35
36
# File 'lib/solace/composers/associated_token_account_program_create_account_composer.rb', line 34

def owner
  params[:owner].to_s
end

#setup_accountsvoid

This method returns an undefined value.

Setup accounts required for associated token account program create account instruction Called automatically during initialization

Since:

  • 0.0.7



84
85
86
87
88
89
90
91
92
# File 'lib/solace/composers/associated_token_account_program_create_account_composer.rb', line 84

def setup_accounts # rubocop:disable Metrics/AbcSize
  .add_writable_signer(funder)
  .add_writable_nonsigner(ata_address)
  .add_readonly_nonsigner(owner)
  .add_readonly_nonsigner(mint)
  .add_readonly_nonsigner(system_program_id)
  .add_readonly_nonsigner(token_program_id)
  .add_readonly_nonsigner()
end

#system_program_idString

Extracts the system program id from the constants

Returns:

  • (String)

    The system program id

Since:

  • 0.0.7



62
63
64
# File 'lib/solace/composers/associated_token_account_program_create_account_composer.rb', line 62

def system_program_id
  Constants::SYSTEM_PROGRAM_ID.to_s
end

#token_program_idString

Extracts the token program id from the constants

Returns:

  • (String)

    The token program id

Since:

  • 0.0.7



69
70
71
# File 'lib/solace/composers/associated_token_account_program_create_account_composer.rb', line 69

def token_program_id
  Constants::TOKEN_PROGRAM_ID.to_s
end