Class: Solace::Composers::ZarTrustlessEscrowDepositComposer

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

Overview

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

Locks ‘amount` tokens from the depositor into a per-claim-authority EscrowDeposit PDA and the per-mint program vault. When a sponsor pays, the fee payer is the sponsor; otherwise the depositor pays.

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.
: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).
:amount                  [Integer] u64 amount to deposit.
:claim_authority         [#to_s] Authority that can claim the deposit.

Optional params:

:sponsor          [#to_s] Optional fee sponsor (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



71
72
73
# File 'lib/solace/zar_trustless_escrow/composers/deposit_composer.rb', line 71

def amount
  params[:amount]
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)


127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/solace/zar_trustless_escrow/composers/deposit_composer.rb', line 127

def build_instruction(context)
  Solace::ZarTrustlessEscrow::Instructions::DepositInstruction.build(
    amount:,
    claim_authority:,
    sponsor:,
    mint_index:                    context.index_of(mint),
    depositor_index:               context.index_of(depositor),
    depositor_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),
    program_index:                 context.index_of(program_id)
  )
end

#claim_authorityString

Extracts the claim authority from the params

Returns:

  • (String)

    The claim authority address



78
79
80
# File 'lib/solace/zar_trustless_escrow/composers/deposit_composer.rb', line 78

def claim_authority
  params[:claim_authority].to_s
end

#depositorString

Extracts the depositor address from the params

Returns:

  • (String)

    The depositor address



36
37
38
# File 'lib/solace/zar_trustless_escrow/composers/deposit_composer.rb', line 36

def depositor
  params[:depositor].to_s
end

#depositor_token_accountString

Extracts the depositor’s source token account address from the params

Returns:

  • (String)

    The depositor token account address



43
44
45
# File 'lib/solace/zar_trustless_escrow/composers/deposit_composer.rb', line 43

def 
  params[:depositor_token_account].to_s
end

#escrow_depositString

Extracts the EscrowDeposit PDA address from the params

Returns:

  • (String)

    The escrow deposit address



50
51
52
# File 'lib/solace/zar_trustless_escrow/composers/deposit_composer.rb', line 50

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



64
65
66
# File 'lib/solace/zar_trustless_escrow/composers/deposit_composer.rb', line 64

def fee_payer
  params[:fee_payer].to_s
end

#mintString

Extracts the mint address from the params

Returns:

  • (String)

    The mint address



29
30
31
# File 'lib/solace/zar_trustless_escrow/composers/deposit_composer.rb', line 29

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



92
93
94
# File 'lib/solace/zar_trustless_escrow/composers/deposit_composer.rb', line 92

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



57
58
59
# File 'lib/solace/zar_trustless_escrow/composers/deposit_composer.rb', line 57

def 
  params[:program_token_account].to_s
end

#setup_accountsObject

Declares all accounts required by this instruction.



111
112
113
114
115
116
117
118
119
120
121
# File 'lib/solace/zar_trustless_escrow/composers/deposit_composer.rb', line 111

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

Extracts the optional fee sponsor from the params

Returns:

  • (String, nil)

    The sponsor address, or nil



85
86
87
# File 'lib/solace/zar_trustless_escrow/composers/deposit_composer.rb', line 85

def sponsor
  params[:sponsor]&.to_s
end

#system_programString

Returns the System Program id

Returns:

  • (String)

    The System Program id



106
107
108
# File 'lib/solace/zar_trustless_escrow/composers/deposit_composer.rb', line 106

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



99
100
101
# File 'lib/solace/zar_trustless_escrow/composers/deposit_composer.rb', line 99

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