Class: Solace::Composers::ZarTrustlessEscrowMediatedReclaimComposer
- Inherits:
-
Base
- Object
- Base
- Solace::Composers::ZarTrustlessEscrowMediatedReclaimComposer
- 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
-
#associated_token_program ⇒ String
Returns the Associated Token Account Program id.
-
#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 destination token account 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.
-
#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.
-
#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
#associated_token_program ⇒ String
Returns 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.
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(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), associated_token_program_index: context.index_of(associated_token_program), program_index: context.index_of(program_id) ) end |
#depositor ⇒ String
Extracts the depositor address from the params
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_account ⇒ String
Extracts the depositor’s destination token account from the params
42 43 44 |
# File 'lib/solace/zar_trustless_escrow/composers/mediated_reclaim_composer.rb', line 42 def depositor_token_account params[:depositor_token_account].to_s end |
#fee_payer ⇒ String
Extracts the fee payer address from the params
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 |
#id ⇒ String
Extracts the unique escrow id from the params
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_deposit ⇒ String
Extracts the MediatedEscrowDeposit PDA address from the params
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 |
#mint ⇒ String
Extracts the mint address from the params
28 29 30 |
# File 'lib/solace/zar_trustless_escrow/composers/mediated_reclaim_composer.rb', line 28 def mint params[:mint].to_s end |
#program_id ⇒ String
Returns the escrow program id (defaults to the mainnet 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_account ⇒ String
Extracts the per-mint program vault address from the params
56 57 58 |
# File 'lib/solace/zar_trustless_escrow/composers/mediated_reclaim_composer.rb', line 56 def program_token_account params[:program_token_account].to_s end |
#setup_accounts ⇒ Object
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 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(associated_token_program) account_context.add_readonly_nonsigner(program_id) end |
#system_program ⇒ String
Returns 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_id ⇒ String
Returns the token program id (defaults to the legacy SPL Token program)
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 |