Class: Solace::Composers::ZarTrustlessEscrowDepositComposer
- Inherits:
-
Base
- Object
- Base
- Solace::Composers::ZarTrustlessEscrowDepositComposer
- 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
-
#amount ⇒ Integer
Extracts the deposit amount from the params.
-
#build_instruction(context) ⇒ Solace::Instruction
Builds the instruction with resolved account indices.
-
#claim_authority ⇒ String
Extracts the claim authority from the params.
-
#depositor ⇒ String
Extracts the depositor address from the params.
-
#depositor_token_account ⇒ String
Extracts the depositor’s source token account address from the params.
-
#escrow_deposit ⇒ String
Extracts the EscrowDeposit PDA address from the params.
-
#fee_payer ⇒ String
Extracts the fee payer 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.
-
#sponsor ⇒ String?
Extracts the optional fee sponsor from the params.
-
#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
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.
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(depositor_token_account), escrow_deposit_index: context.index_of(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 |
#claim_authority ⇒ String
Extracts the claim authority from the params
78 79 80 |
# File 'lib/solace/zar_trustless_escrow/composers/deposit_composer.rb', line 78 def params[:claim_authority].to_s end |
#depositor ⇒ String
Extracts the depositor address from the params
36 37 38 |
# File 'lib/solace/zar_trustless_escrow/composers/deposit_composer.rb', line 36 def depositor params[:depositor].to_s end |
#depositor_token_account ⇒ String
Extracts the depositor’s source token account address from the params
43 44 45 |
# File 'lib/solace/zar_trustless_escrow/composers/deposit_composer.rb', line 43 def depositor_token_account params[:depositor_token_account].to_s end |
#escrow_deposit ⇒ String
Extracts the EscrowDeposit PDA address from the params
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_payer ⇒ String
Extracts the fee payer address from the params
64 65 66 |
# File 'lib/solace/zar_trustless_escrow/composers/deposit_composer.rb', line 64 def fee_payer params[:fee_payer].to_s end |
#mint ⇒ String
Extracts the mint address from the params
29 30 31 |
# File 'lib/solace/zar_trustless_escrow/composers/deposit_composer.rb', line 29 def mint params[:mint].to_s end |
#program_id ⇒ String
Returns the escrow program id (defaults to the mainnet 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_account ⇒ String
Extracts the per-mint program vault address from the params
57 58 59 |
# File 'lib/solace/zar_trustless_escrow/composers/deposit_composer.rb', line 57 def program_token_account params[:program_token_account].to_s end |
#setup_accounts ⇒ Object
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 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(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 |
#sponsor ⇒ String?
Extracts the optional fee sponsor from the params
85 86 87 |
# File 'lib/solace/zar_trustless_escrow/composers/deposit_composer.rb', line 85 def sponsor params[:sponsor]&.to_s end |
#system_program ⇒ String
Returns 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_id ⇒ String
Returns the token program id (defaults to the legacy SPL Token program)
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 |