Class: Solace::Composers::ZarTrustlessEscrowMediatedDepositComposer
- Inherits:
-
Base
- Object
- Base
- Solace::Composers::ZarTrustlessEscrowMediatedDepositComposer
- 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
-
#amount ⇒ Integer
Extracts the deposit amount from the params.
-
#beneficiary ⇒ String
Extracts the beneficiary from the params.
-
#build_instruction(context) ⇒ Solace::Instruction
Builds the instruction with resolved account indices.
-
#depositor ⇒ String
Extracts the depositor address from the params.
-
#depositor_token_account ⇒ String
Extracts the depositor’s source token account from the params.
-
#expires_at ⇒ Integer?
Extracts the optional expiry timestamp from the params.
-
#fee_payer ⇒ String
Extracts the fee payer address from the params.
-
#id ⇒ String
Extracts the unique escrow id from the params.
-
#mediated_escrow_deposit ⇒ String
Extracts the MediatedEscrowDeposit PDA address from the params.
-
#mediator ⇒ String
Extracts the mediator from the params.
-
#mint ⇒ String
Extracts the mint address from the params.
-
#program_id ⇒ String
Returns the escrow program id (defaults to the mainnet PROGRAM_ID).
-
#program_token_account ⇒ String
Extracts the per-mint program vault address from the params.
-
#rent_collector ⇒ String?
Extracts the optional rent collector from the params.
-
#setup_accounts ⇒ Object
Declares all accounts required by this instruction.
-
#system_program ⇒ String
Returns the System Program id.
-
#token_program_id ⇒ String
Returns the token program id (defaults to the legacy SPL Token program).
Instance Method Details
#amount ⇒ Integer
Extracts the deposit amount from the params
75 76 77 |
# File 'lib/solace/zar_trustless_escrow/composers/mediated_deposit_composer.rb', line 75 def amount params[:amount] end |
#beneficiary ⇒ String
Extracts the beneficiary from the params
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.
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(depositor_token_account), mediated_escrow_deposit_index: context.index_of(mediated_escrow_deposit), program_token_account_index: context.index_of(program_token_account), 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 |
#depositor ⇒ String
Extracts the depositor address from the params
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_account ⇒ String
Extracts the depositor’s source token account from the params
47 48 49 |
# File 'lib/solace/zar_trustless_escrow/composers/mediated_deposit_composer.rb', line 47 def depositor_token_account params[:depositor_token_account].to_s end |
#expires_at ⇒ Integer?
Extracts the optional expiry timestamp from the params
110 111 112 |
# File 'lib/solace/zar_trustless_escrow/composers/mediated_deposit_composer.rb', line 110 def expires_at params[:expires_at] end |
#fee_payer ⇒ String
Extracts the fee payer address from the params
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 |
#id ⇒ String
Extracts the unique escrow id from the params
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_deposit ⇒ String
Extracts the MediatedEscrowDeposit PDA address from the params
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 |
#mediator ⇒ String
Extracts the mediator from the params
89 90 91 |
# File 'lib/solace/zar_trustless_escrow/composers/mediated_deposit_composer.rb', line 89 def mediator params[:mediator].to_s end |
#mint ⇒ String
Extracts the mint address from the params
33 34 35 |
# File 'lib/solace/zar_trustless_escrow/composers/mediated_deposit_composer.rb', line 33 def mint params[:mint].to_s end |
#program_id ⇒ String
Returns the escrow program id (defaults to the mainnet 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_account ⇒ String
Extracts the per-mint program vault address from the params
61 62 63 |
# File 'lib/solace/zar_trustless_escrow/composers/mediated_deposit_composer.rb', line 61 def program_token_account params[:program_token_account].to_s end |
#rent_collector ⇒ String?
Extracts the optional rent collector from the params
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_accounts ⇒ Object
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 account_context.add_readonly_nonsigner(mint) account_context.add_writable_signer(depositor) account_context.add_writable_nonsigner(depositor_token_account) account_context.add_writable_nonsigner(mediated_escrow_deposit) account_context.add_writable_nonsigner(program_token_account) account_context.add_writable_signer(fee_payer) account_context.add_readonly_nonsigner(system_program) account_context.add_readonly_nonsigner(token_program_id) account_context.add_readonly_nonsigner(program_id) end |
#system_program ⇒ String
Returns 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_id ⇒ String
Returns the token program id (defaults to the legacy SPL Token program)
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 |