Class: Solace::Composers::ZarTrustlessEscrowMediatedDepositComposer

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

Overview

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

Locks ‘amount` tokens into a three-party MediatedEscrowDeposit PDA (keyed by `id`) and the per-mint program vault. The mediator decides the outcome; an optional expiry lets the depositor reclaim after the timestamp passes.

Required params:

:mint                    [#to_s] Mint of the escrowed tokens.
:depositor               [#to_s, Keypair] Depositor (writable signer).
:depositor_token_account [#to_s] Depositor's source token account.
: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).
:amount                  [Integer] u64 amount to deposit.
:id                      [#to_s] Unique id used to derive the escrow PDA.
:mediator                [#to_s] Mediator who decides the outcome.
:beneficiary             [#to_s] Beneficiary the mediator may release to.

Optional params:

:rent_collector   [#to_s] Optional rent collector on close (default: nil).
:expires_at       [Integer] Optional unix timestamp for reclaim (default: nil).
: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

#amountInteger

Extracts the deposit amount from the params

Returns:

  • (Integer)

    The u64 amount to deposit



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

def amount
  params[:amount]
end

#beneficiaryString

Extracts the beneficiary from the params

Returns:

  • (String)

    The beneficiary address



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

def beneficiary
  params[:beneficiary].to_s
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)


152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# File 'lib/solace/zar_trustless_escrow/composers/mediated_deposit_composer.rb', line 152

def build_instruction(context)
  Solace::ZarTrustlessEscrow::Instructions::MediatedDepositInstruction.build(
    amount:,
    id:,
    mediator:,
    beneficiary:,
    rent_collector:,
    expires_at:,
    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),
    program_index:                 context.index_of(program_id)
  )
end

#depositorString

Extracts the depositor address from the params

Returns:

  • (String)

    The depositor address



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

def depositor
  params[:depositor].to_s
end

#depositor_token_accountString

Extracts the depositor’s source token account from the params

Returns:

  • (String)

    The depositor token account address



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

def 
  params[:depositor_token_account].to_s
end

#expires_atInteger?

Extracts the optional expiry timestamp from the params

Returns:

  • (Integer, nil)

    The unix expiry timestamp, or nil



110
111
112
# File 'lib/solace/zar_trustless_escrow/composers/mediated_deposit_composer.rb', line 110

def expires_at
  params[:expires_at]
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/mediated_deposit_composer.rb', line 68

def fee_payer
  params[:fee_payer].to_s
end

#idString

Extracts the unique escrow id from the params

Returns:

  • (String)

    The escrow id



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

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



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

def mediated_escrow_deposit
  params[:mediated_escrow_deposit].to_s
end

#mediatorString

Extracts the mediator from the params

Returns:

  • (String)

    The mediator address



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

def mediator
  params[:mediator].to_s
end

#mintString

Extracts the mint address from the params

Returns:

  • (String)

    The mint address



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

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



117
118
119
# File 'lib/solace/zar_trustless_escrow/composers/mediated_deposit_composer.rb', line 117

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/mediated_deposit_composer.rb', line 61

def 
  params[:program_token_account].to_s
end

#rent_collectorString?

Extracts the optional rent collector from the params

Returns:

  • (String, nil)

    The rent collector address, or nil



103
104
105
# File 'lib/solace/zar_trustless_escrow/composers/mediated_deposit_composer.rb', line 103

def rent_collector
  params[:rent_collector]&.to_s
end

#setup_accountsObject

Declares all accounts required by this instruction.



136
137
138
139
140
141
142
143
144
145
146
# File 'lib/solace/zar_trustless_escrow/composers/mediated_deposit_composer.rb', line 136

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(program_id)
end

#system_programString

Returns the System Program id

Returns:

  • (String)

    The System Program id



131
132
133
# File 'lib/solace/zar_trustless_escrow/composers/mediated_deposit_composer.rb', line 131

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



124
125
126
# File 'lib/solace/zar_trustless_escrow/composers/mediated_deposit_composer.rb', line 124

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