Class: Solace::Composers::ZarTrustlessEscrowClaimComposer

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

Overview

Composes a ‘claim` instruction for the ZAR Trustless Escrow program.

The claim authority releases an EscrowDeposit to the claimant and closes the deposit account (rent returns to the fee payer).

Required params:

:mint                   [#to_s] Mint of the escrowed tokens.
:claim_authority        [#to_s, Keypair] Claim authority (readonly signer).
:claimant               [#to_s] Recipient of the released tokens.
:claimant_token_account [#to_s] Claimant's destination token account (ATA).
:escrow_deposit         [#to_s] EscrowDeposit PDA.
: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

#associated_token_programString

Returns the Associated Token Account Program id

Returns:

  • (String)

    The Associated Token Account Program id



96
97
98
# File 'lib/solace/zar_trustless_escrow/composers/claim_composer.rb', line 96

def associated_token_program
  Solace::Constants::ASSOCIATED_TOKEN_ACCOUNT_PROGRAM_ID
end

#build_instruction(context) ⇒ Solace::Instruction

Builds the instruction with resolved account indices.

Parameters:

  • context (Solace::Utils::AccountContext)

    Merged context from TransactionComposer.

Returns:

  • (Solace::Instruction)


119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/solace/zar_trustless_escrow/composers/claim_composer.rb', line 119

def build_instruction(context)
  Solace::ZarTrustlessEscrow::Instructions::ClaimInstruction.build(
    mint_index:                     context.index_of(mint),
    claim_authority_index:          context.index_of(claim_authority),
    claimant_index:                 context.index_of(claimant),
    claimant_token_account_index:   context.index_of(),
    escrow_deposit_index:           context.index_of(escrow_deposit),
    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),
    associated_token_program_index: context.index_of(associated_token_program),
    program_index:                  context.index_of(program_id)
  )
end

#claim_authorityString

Extracts the claim authority from the params

Returns:

  • (String)

    The claim authority address



33
34
35
# File 'lib/solace/zar_trustless_escrow/composers/claim_composer.rb', line 33

def claim_authority
  params[:claim_authority].to_s
end

#claimantString

Extracts the claimant address from the params

Returns:

  • (String)

    The claimant address



40
41
42
# File 'lib/solace/zar_trustless_escrow/composers/claim_composer.rb', line 40

def claimant
  params[:claimant].to_s
end

#claimant_token_accountString

Extracts the claimant’s destination token account from the params

Returns:

  • (String)

    The claimant token account address



47
48
49
# File 'lib/solace/zar_trustless_escrow/composers/claim_composer.rb', line 47

def 
  params[:claimant_token_account].to_s
end

#escrow_depositString

Extracts the EscrowDeposit PDA address from the params

Returns:

  • (String)

    The escrow deposit address



54
55
56
# File 'lib/solace/zar_trustless_escrow/composers/claim_composer.rb', line 54

def escrow_deposit
  params[:escrow_deposit].to_s
end

#fee_payerString

Extracts the fee payer address from the params

Returns:

  • (String)

    The fee payer address



68
69
70
# File 'lib/solace/zar_trustless_escrow/composers/claim_composer.rb', line 68

def fee_payer
  params[:fee_payer].to_s
end

#mintString

Extracts the mint address from the params

Returns:

  • (String)

    The mint address



26
27
28
# File 'lib/solace/zar_trustless_escrow/composers/claim_composer.rb', line 26

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



75
76
77
# File 'lib/solace/zar_trustless_escrow/composers/claim_composer.rb', line 75

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



61
62
63
# File 'lib/solace/zar_trustless_escrow/composers/claim_composer.rb', line 61

def 
  params[:program_token_account].to_s
end

#setup_accountsObject

Declares all accounts required by this instruction.



101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/solace/zar_trustless_escrow/composers/claim_composer.rb', line 101

def setup_accounts
  .add_readonly_nonsigner(mint)
  .add_readonly_signer(claim_authority)
  .add_readonly_nonsigner(claimant)
  .add_writable_nonsigner()
  .add_writable_nonsigner(escrow_deposit)
  .add_writable_nonsigner()
  .add_writable_signer(fee_payer)
  .add_readonly_nonsigner(system_program)
  .add_readonly_nonsigner(token_program_id)
  .add_readonly_nonsigner(associated_token_program)
  .add_readonly_nonsigner(program_id)
end

#system_programString

Returns the System Program id

Returns:

  • (String)

    The System Program id



89
90
91
# File 'lib/solace/zar_trustless_escrow/composers/claim_composer.rb', line 89

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



82
83
84
# File 'lib/solace/zar_trustless_escrow/composers/claim_composer.rb', line 82

def token_program_id
  (params[:token_program_id] || Solace::Constants::TOKEN_PROGRAM_ID).to_s
end