Module: Solace::Programs::ZarTrustlessEscrow::EscrowDepositOperations
- Included in:
- Solace::Programs::ZarTrustlessEscrow
- Defined in:
- lib/solace/zar_trustless_escrow/programs/zar_trustless_escrow/escrow_deposit_operations.rb
Overview
Two-party escrow operations for Solace::Programs::ZarTrustlessEscrow: deposit, claim, and reclaim against the EscrowDeposit account. Mixed into the program client; methods run in the client’s instance context (connection, program_id, and the get_*_address derivations are available). The per-mint vault setup (token_account_init) is shared across escrow types and lives on the client itself, not here.
Instance Method Summary collapse
-
#claim(payer:, claim_authority:, sign: true, execute: true, **composer_opts) {|composer| ... } ⇒ Solace::Transaction
Claims a two-party escrow on behalf of the claim authority, signs, and (optionally) sends it.
-
#compose_claim(mint:, claim_authority:, claimant:, fee_payer:, token_program_id: Solace::Constants::TOKEN_PROGRAM_ID) ⇒ Solace::TransactionComposer
Prepares a claim transaction.
-
#compose_deposit(mint:, depositor:, claim_authority:, amount:, fee_payer:, sponsor: nil, token_program_id: Solace::Constants::TOKEN_PROGRAM_ID) ⇒ Solace::TransactionComposer
Prepares a deposit transaction.
-
#compose_reclaim(mint:, depositor:, claim_authority:, fee_payer:, token_program_id: Solace::Constants::TOKEN_PROGRAM_ID) ⇒ Solace::TransactionComposer
Prepares a reclaim transaction.
-
#deposit(payer:, depositor:, sign: true, execute: true, **composer_opts) {|composer| ... } ⇒ Solace::Transaction
Deposits funds into a two-party escrow, signs, and (optionally) sends it.
-
#escrow_deposit_exists?(address:) ⇒ Boolean
Returns whether an EscrowDeposit account exists at the given address.
-
#fetch_escrow_deposit(address:) ⇒ Solace::ZarTrustlessEscrow::EscrowDeposit
Fetches and deserializes the EscrowDeposit account at the given address.
-
#reclaim(payer:, sign: true, execute: true, **composer_opts) {|composer| ... } ⇒ Solace::Transaction
Reclaims an unclaimed two-party escrow, signs, and (optionally) sends it.
Instance Method Details
#claim(payer:, claim_authority:, sign: true, execute: true, **composer_opts) {|composer| ... } ⇒ Solace::Transaction
Claims a two-party escrow on behalf of the claim authority, signs, and (optionally) sends it. The claim authority and fee payer sign.
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/solace/zar_trustless_escrow/programs/zar_trustless_escrow/escrow_deposit_operations.rb', line 119 def claim(payer:, claim_authority:, sign: true, execute: true, **composer_opts) composer = compose_claim(fee_payer: payer, claim_authority:, **composer_opts) yield composer if block_given? tx = composer .set_fee_payer(payer) .compose_transaction if sign tx.sign(payer, ) connection.send_transaction(tx.serialize) if execute end tx end |
#compose_claim(mint:, claim_authority:, claimant:, fee_payer:, token_program_id: Solace::Constants::TOKEN_PROGRAM_ID) ⇒ Solace::TransactionComposer
Prepares a claim transaction. Derives the EscrowDeposit PDA, the program vault, and the claimant’s associated token account.
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/solace/zar_trustless_escrow/programs/zar_trustless_escrow/escrow_deposit_operations.rb', line 146 def compose_claim( mint:, claim_authority:, claimant:, fee_payer:, token_program_id: Solace::Constants::TOKEN_PROGRAM_ID ) escrow_deposit, = get_escrow_deposit_address(claim_authority:) program_token_account, = get_vault_address(mint:) claimant_token_account, = Solace::Programs::AssociatedTokenAccount.get_address( owner: claimant, mint:, token_program_id: ) ix = Composers::ZarTrustlessEscrowClaimComposer.new( mint:, claim_authority:, claimant:, claimant_token_account:, escrow_deposit:, program_token_account:, fee_payer:, program_id:, token_program_id: ) TransactionComposer.new(connection:).add_instruction(ix) end |
#compose_deposit(mint:, depositor:, claim_authority:, amount:, fee_payer:, sponsor: nil, token_program_id: Solace::Constants::TOKEN_PROGRAM_ID) ⇒ Solace::TransactionComposer
Prepares a deposit transaction. Derives the EscrowDeposit PDA, the program vault, and the depositor’s associated token account.
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/solace/zar_trustless_escrow/programs/zar_trustless_escrow/escrow_deposit_operations.rb', line 76 def compose_deposit( mint:, depositor:, claim_authority:, amount:, fee_payer:, sponsor: nil, token_program_id: Solace::Constants::TOKEN_PROGRAM_ID ) escrow_deposit, = get_escrow_deposit_address(claim_authority:) program_token_account, = get_vault_address(mint:) depositor_token_account, = Solace::Programs::AssociatedTokenAccount.get_address( owner: depositor, mint:, token_program_id: ) ix = Composers::ZarTrustlessEscrowDepositComposer.new( mint:, depositor:, depositor_token_account:, escrow_deposit:, program_token_account:, fee_payer:, amount:, claim_authority:, sponsor:, program_id:, token_program_id: ) TransactionComposer.new(connection:).add_instruction(ix) end |
#compose_reclaim(mint:, depositor:, claim_authority:, fee_payer:, token_program_id: Solace::Constants::TOKEN_PROGRAM_ID) ⇒ Solace::TransactionComposer
Prepares a reclaim transaction. Derives the EscrowDeposit PDA, the program vault, and the depositor’s associated token account.
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 |
# File 'lib/solace/zar_trustless_escrow/programs/zar_trustless_escrow/escrow_deposit_operations.rb', line 211 def compose_reclaim( mint:, depositor:, claim_authority:, fee_payer:, token_program_id: Solace::Constants::TOKEN_PROGRAM_ID ) escrow_deposit, = get_escrow_deposit_address(claim_authority:) program_token_account, = get_vault_address(mint:) depositor_token_account, = Solace::Programs::AssociatedTokenAccount.get_address( owner: depositor, mint:, token_program_id: ) ix = Composers::ZarTrustlessEscrowReclaimComposer.new( mint:, depositor:, depositor_token_account:, escrow_deposit:, program_token_account:, fee_payer:, claim_authority:, program_id:, token_program_id: ) TransactionComposer.new(connection:).add_instruction(ix) end |
#deposit(payer:, depositor:, sign: true, execute: true, **composer_opts) {|composer| ... } ⇒ Solace::Transaction
Deposits funds into a two-party escrow, signs, and (optionally) sends it. The depositor and fee payer sign; when a sponsor pays, pass the sponsor keypair as payer and its address as sponsor.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/solace/zar_trustless_escrow/programs/zar_trustless_escrow/escrow_deposit_operations.rb', line 47 def deposit(payer:, depositor:, sign: true, execute: true, **composer_opts) composer = compose_deposit(fee_payer: payer, depositor:, **composer_opts) yield composer if block_given? tx = composer .set_fee_payer(payer) .compose_transaction if sign tx.sign(payer, depositor) connection.send_transaction(tx.serialize) if execute end tx end |
#escrow_deposit_exists?(address:) ⇒ Boolean
Returns whether an EscrowDeposit account exists at the given address. Derive the address first with Solace::Programs::ZarTrustlessEscrow#get_escrow_deposit_address.
33 34 35 |
# File 'lib/solace/zar_trustless_escrow/programs/zar_trustless_escrow/escrow_deposit_operations.rb', line 33 def escrow_deposit_exists?(address:) !connection.get_account_info(address.to_s).nil? end |
#fetch_escrow_deposit(address:) ⇒ Solace::ZarTrustlessEscrow::EscrowDeposit
Fetches and deserializes the EscrowDeposit account at the given address. Derive the address first with Solace::Programs::ZarTrustlessEscrow#get_escrow_deposit_address.
19 20 21 22 23 24 25 26 |
# File 'lib/solace/zar_trustless_escrow/programs/zar_trustless_escrow/escrow_deposit_operations.rb', line 19 def fetch_escrow_deposit(address:) account = connection.get_account_info(address.to_s) raise "EscrowDeposit account not found at #{address}" unless account Solace::ZarTrustlessEscrow::EscrowDeposit.deserialize( Solace::Utils::Codecs.base64_to_bytestream(account['data'][0]) ) end |
#reclaim(payer:, sign: true, execute: true, **composer_opts) {|composer| ... } ⇒ Solace::Transaction
Reclaims an unclaimed two-party escrow, signs, and (optionally) sends it. The fee payer (the depositor or the sponsor) is the only signer.
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/solace/zar_trustless_escrow/programs/zar_trustless_escrow/escrow_deposit_operations.rb', line 184 def reclaim(payer:, sign: true, execute: true, **composer_opts) composer = compose_reclaim(fee_payer: payer, **composer_opts) yield composer if block_given? tx = composer .set_fee_payer(payer) .compose_transaction if sign tx.sign(payer) connection.send_transaction(tx.serialize) if execute end tx end |