Class: Solace::Composers::ZarTrustlessEscrowMediatedReleaseComposer

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

Overview

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

The mediator releases a MediatedEscrowDeposit to the recipient (the depositor or the beneficiary) and closes the deposit, sending rent to the rent collector (which defaults to the mediator when none was set at deposit time).

Required params:

:mint                    [#to_s] Mint of the escrowed tokens.
:mediator                [#to_s, Keypair] Mediator (readonly signer).
:recipient               [#to_s] Depositor or beneficiary receiving tokens.
:recipient_token_account [#to_s] Recipient's destination token account (ATA).
:mediated_escrow_deposit [#to_s] MediatedEscrowDeposit PDA.
:program_token_account   [#to_s] Per-mint program vault PDA.
:rent_collector          [#to_s] Account that receives the closed-account rent.
: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



114
115
116
# File 'lib/solace/zar_trustless_escrow/composers/mediated_release_composer.rb', line 114

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)


138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/solace/zar_trustless_escrow/composers/mediated_release_composer.rb', line 138

def build_instruction(context)
  Solace::ZarTrustlessEscrow::Instructions::MediatedReleaseInstruction.build(
    id:,
    mint_index:                     context.index_of(mint),
    mediator_index:                 context.index_of(mediator),
    recipient_index:                context.index_of(recipient),
    recipient_token_account_index:  context.index_of(),
    mediated_escrow_deposit_index:  context.index_of(mediated_escrow_deposit),
    program_token_account_index:    context.index_of(),
    rent_collector_index:           context.index_of(rent_collector),
    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

#fee_payerString

Extracts the fee payer address from the params

Returns:

  • (String)

    The fee payer address



79
80
81
# File 'lib/solace/zar_trustless_escrow/composers/mediated_release_composer.rb', line 79

def fee_payer
  params[:fee_payer].to_s
end

#idString

Extracts the unique escrow id from the params

Returns:

  • (String)

    The escrow id



86
87
88
# File 'lib/solace/zar_trustless_escrow/composers/mediated_release_composer.rb', line 86

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



58
59
60
# File 'lib/solace/zar_trustless_escrow/composers/mediated_release_composer.rb', line 58

def mediated_escrow_deposit
  params[:mediated_escrow_deposit].to_s
end

#mediatorString

Extracts the mediator from the params

Returns:

  • (String)

    The mediator address



37
38
39
# File 'lib/solace/zar_trustless_escrow/composers/mediated_release_composer.rb', line 37

def mediator
  params[:mediator].to_s
end

#mintString

Extracts the mint address from the params

Returns:

  • (String)

    The mint address



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

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



93
94
95
# File 'lib/solace/zar_trustless_escrow/composers/mediated_release_composer.rb', line 93

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



65
66
67
# File 'lib/solace/zar_trustless_escrow/composers/mediated_release_composer.rb', line 65

def 
  params[:program_token_account].to_s
end

#recipientString

Extracts the recipient from the params

Returns:

  • (String)

    The recipient address



44
45
46
# File 'lib/solace/zar_trustless_escrow/composers/mediated_release_composer.rb', line 44

def recipient
  params[:recipient].to_s
end

#recipient_token_accountString

Extracts the recipient’s destination token account from the params

Returns:

  • (String)

    The recipient token account address



51
52
53
# File 'lib/solace/zar_trustless_escrow/composers/mediated_release_composer.rb', line 51

def 
  params[:recipient_token_account].to_s
end

#rent_collectorString

Extracts the rent collector from the params

Returns:

  • (String)

    The rent collector address



72
73
74
# File 'lib/solace/zar_trustless_escrow/composers/mediated_release_composer.rb', line 72

def rent_collector
  params[:rent_collector].to_s
end

#setup_accountsObject

Declares all accounts required by this instruction.



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

def setup_accounts
  .add_readonly_nonsigner(mint)
  .add_readonly_signer(mediator)
  .add_readonly_nonsigner(recipient)
  .add_writable_nonsigner()
  .add_writable_nonsigner(mediated_escrow_deposit)
  .add_writable_nonsigner()
  .add_writable_nonsigner(rent_collector)
  .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



107
108
109
# File 'lib/solace/zar_trustless_escrow/composers/mediated_release_composer.rb', line 107

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



100
101
102
# File 'lib/solace/zar_trustless_escrow/composers/mediated_release_composer.rb', line 100

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