Class: Solace::Composers::ZarTrustlessEscrowMediatedReclaimComposer

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

Overview

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

After the escrow’s expiry passes, the original depositor reclaims a MediatedEscrowDeposit and closes the deposit account (rent returns to the depositor). Requires the escrow to have been created with an expiry.

Required params:

:mint                    [#to_s] Mint of the escrowed tokens.
:depositor               [#to_s, Keypair] Depositor (writable signer, receives rent).
:depositor_token_account [#to_s] Depositor's destination token account (ATA).
:mediated_escrow_deposit [#to_s] MediatedEscrowDeposit PDA.
:program_token_account   [#to_s] Per-mint program vault PDA.
:fee_payer               [#to_s, Keypair] Fee payer (writable signer).
:id                      [#to_s] Unique id used to derive the escrow PDA.

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



98
99
100
# File 'lib/solace/zar_trustless_escrow/composers/mediated_reclaim_composer.rb', line 98

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)


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

def build_instruction(context)
  Solace::ZarTrustlessEscrow::Instructions::MediatedReclaimInstruction.build(
    id:,
    mint_index:                     context.index_of(mint),
    depositor_index:                context.index_of(depositor),
    depositor_token_account_index:  context.index_of(),
    mediated_escrow_deposit_index:  context.index_of(mediated_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

#depositorString

Extracts the depositor address from the params

Returns:

  • (String)

    The depositor address



35
36
37
# File 'lib/solace/zar_trustless_escrow/composers/mediated_reclaim_composer.rb', line 35

def depositor
  params[:depositor].to_s
end

#depositor_token_accountString

Extracts the depositor’s destination token account from the params

Returns:

  • (String)

    The depositor token account address



42
43
44
# File 'lib/solace/zar_trustless_escrow/composers/mediated_reclaim_composer.rb', line 42

def 
  params[:depositor_token_account].to_s
end

#fee_payerString

Extracts the fee payer address from the params

Returns:

  • (String)

    The fee payer address



63
64
65
# File 'lib/solace/zar_trustless_escrow/composers/mediated_reclaim_composer.rb', line 63

def fee_payer
  params[:fee_payer].to_s
end

#idString

Extracts the unique escrow id from the params

Returns:

  • (String)

    The escrow id



70
71
72
# File 'lib/solace/zar_trustless_escrow/composers/mediated_reclaim_composer.rb', line 70

def id
  params[:id].to_s
end

#mediated_escrow_depositString

Extracts the MediatedEscrowDeposit PDA address from the params

Returns:

  • (String)

    The mediated escrow deposit address



49
50
51
# File 'lib/solace/zar_trustless_escrow/composers/mediated_reclaim_composer.rb', line 49

def mediated_escrow_deposit
  params[:mediated_escrow_deposit].to_s
end

#mintString

Extracts the mint address from the params

Returns:

  • (String)

    The mint address



28
29
30
# File 'lib/solace/zar_trustless_escrow/composers/mediated_reclaim_composer.rb', line 28

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



77
78
79
# File 'lib/solace/zar_trustless_escrow/composers/mediated_reclaim_composer.rb', line 77

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



56
57
58
# File 'lib/solace/zar_trustless_escrow/composers/mediated_reclaim_composer.rb', line 56

def 
  params[:program_token_account].to_s
end

#setup_accountsObject

Declares all accounts required by this instruction.



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

def setup_accounts
  .add_readonly_nonsigner(mint)
  .add_writable_signer(depositor)
  .add_writable_nonsigner()
  .add_writable_nonsigner(mediated_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



91
92
93
# File 'lib/solace/zar_trustless_escrow/composers/mediated_reclaim_composer.rb', line 91

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



84
85
86
# File 'lib/solace/zar_trustless_escrow/composers/mediated_reclaim_composer.rb', line 84

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