Class: Solace::Composers::ZarTrustlessEscrowMediatedReleaseComposer
- Inherits:
-
Base
- Object
- Base
- Solace::Composers::ZarTrustlessEscrowMediatedReleaseComposer
- 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
-
#associated_token_program ⇒ String
Returns the Associated Token Account Program id.
-
#build_instruction(context) ⇒ Solace::Instruction
Builds the instruction with resolved account indices.
-
#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.
-
#recipient ⇒ String
Extracts the recipient from the params.
-
#recipient_token_account ⇒ String
Extracts the recipient’s destination token account from the params.
-
#rent_collector ⇒ String
Extracts the 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
#associated_token_program ⇒ String
Returns 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.
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(recipient_token_account), mediated_escrow_deposit_index: context.index_of(mediated_escrow_deposit), program_token_account_index: context.index_of(program_token_account), 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_payer ⇒ String
Extracts the fee payer address from the params
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 |
#id ⇒ String
Extracts the unique escrow id from the params
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_deposit ⇒ String
Extracts the MediatedEscrowDeposit PDA address from the params
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 |
#mediator ⇒ String
Extracts the mediator from the params
37 38 39 |
# File 'lib/solace/zar_trustless_escrow/composers/mediated_release_composer.rb', line 37 def mediator params[:mediator].to_s end |
#mint ⇒ String
Extracts the mint address from the params
30 31 32 |
# File 'lib/solace/zar_trustless_escrow/composers/mediated_release_composer.rb', line 30 def mint params[:mint].to_s end |
#program_id ⇒ String
Returns the escrow program id (defaults to the mainnet 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_account ⇒ String
Extracts the per-mint program vault address from the params
65 66 67 |
# File 'lib/solace/zar_trustless_escrow/composers/mediated_release_composer.rb', line 65 def program_token_account params[:program_token_account].to_s end |
#recipient ⇒ String
Extracts the recipient from the params
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_account ⇒ String
Extracts the recipient’s destination token account from the params
51 52 53 |
# File 'lib/solace/zar_trustless_escrow/composers/mediated_release_composer.rb', line 51 def recipient_token_account params[:recipient_token_account].to_s end |
#rent_collector ⇒ String
Extracts the rent collector from the params
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_accounts ⇒ Object
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 account_context.add_readonly_nonsigner(mint) account_context.add_readonly_signer(mediator) account_context.add_readonly_nonsigner(recipient) account_context.add_writable_nonsigner(recipient_token_account) account_context.add_writable_nonsigner(mediated_escrow_deposit) account_context.add_writable_nonsigner(program_token_account) account_context.add_writable_nonsigner(rent_collector) 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
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_id ⇒ String
Returns the token program id (defaults to the legacy SPL Token program)
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 |