Module: Solace::Programs::ZarTrustlessEscrow::MediatedEscrowDepositOperations
- Included in:
- Solace::Programs::ZarTrustlessEscrow
- Defined in:
- lib/solace/zar_trustless_escrow/programs/zar_trustless_escrow/mediated_escrow_deposit_operations.rb
Overview
Three-party mediated escrow operations for Solace::Programs::ZarTrustlessEscrow: deposit, release, and reclaim against the MediatedEscrowDeposit 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
-
#compose_mediated_deposit(mint:, depositor:, id:, mediator:, beneficiary:, amount:, fee_payer:, rent_collector: nil, expires_at: nil, token_program_id: Solace::Constants::TOKEN_PROGRAM_ID) ⇒ Solace::TransactionComposer
Prepares a mediated-deposit transaction.
-
#compose_mediated_reclaim(mint:, depositor:, id:, fee_payer:, token_program_id: Solace::Constants::TOKEN_PROGRAM_ID) ⇒ Solace::TransactionComposer
Prepares a mediated-reclaim transaction.
-
#compose_mediated_release(mint:, mediator:, recipient:, rent_collector:, id:, fee_payer:, token_program_id: Solace::Constants::TOKEN_PROGRAM_ID) ⇒ Solace::TransactionComposer
Prepares a mediated-release transaction.
-
#fetch_mediated_escrow_deposit(address:) ⇒ Solace::ZarTrustlessEscrow::MediatedEscrowDeposit
Fetches and deserializes the MediatedEscrowDeposit account at the given address.
-
#mediated_deposit(payer:, depositor:, sign: true, execute: true, **composer_opts) {|composer| ... } ⇒ Solace::Transaction
Deposits funds into a three-party mediated escrow, signs, and (optionally) sends it.
-
#mediated_escrow_deposit_exists?(address:) ⇒ Boolean
Returns whether a MediatedEscrowDeposit account exists at the given address.
-
#mediated_reclaim(payer:, depositor:, sign: true, execute: true, **composer_opts) {|composer| ... } ⇒ Solace::Transaction
Reclaims an expired mediated escrow as the depositor, signs, and (optionally) sends it.
-
#mediated_release(payer:, mediator:, sign: true, execute: true, **composer_opts) {|composer| ... } ⇒ Solace::Transaction
Releases a mediated escrow on behalf of the mediator, signs, and (optionally) sends it.
Instance Method Details
#compose_mediated_deposit(mint:, depositor:, id:, mediator:, beneficiary:, amount:, fee_payer:, rent_collector: nil, expires_at: nil, token_program_id: Solace::Constants::TOKEN_PROGRAM_ID) ⇒ Solace::TransactionComposer
Prepares a mediated-deposit transaction. Derives the MediatedEscrowDeposit PDA, the program vault, and the depositor’s associated token account.
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 109 110 111 112 113 114 115 116 117 |
# File 'lib/solace/zar_trustless_escrow/programs/zar_trustless_escrow/mediated_escrow_deposit_operations.rb', line 79 def compose_mediated_deposit( mint:, depositor:, id:, mediator:, beneficiary:, amount:, fee_payer:, rent_collector: nil, expires_at: nil, token_program_id: Solace::Constants::TOKEN_PROGRAM_ID ) mediated_escrow_deposit, = get_mediated_escrow_deposit_address(id:) program_token_account, = get_vault_address(mint:) depositor_token_account, = Solace::Programs::AssociatedTokenAccount.get_address( owner: depositor, mint:, token_program_id: ) ix = Composers::ZarTrustlessEscrowMediatedDepositComposer.new( mint:, depositor:, depositor_token_account:, mediated_escrow_deposit:, program_token_account:, fee_payer:, amount:, id:, mediator:, beneficiary:, rent_collector:, expires_at:, program_id:, token_program_id: ) TransactionComposer.new(connection:).add_instruction(ix) end |
#compose_mediated_reclaim(mint:, depositor:, id:, fee_payer:, token_program_id: Solace::Constants::TOKEN_PROGRAM_ID) ⇒ Solace::TransactionComposer
Prepares a mediated-reclaim transaction. Derives the MediatedEscrowDeposit PDA, the program vault, and the depositor’s associated token account.
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 |
# File 'lib/solace/zar_trustless_escrow/programs/zar_trustless_escrow/mediated_escrow_deposit_operations.rb', line 227 def compose_mediated_reclaim( mint:, depositor:, id:, fee_payer:, token_program_id: Solace::Constants::TOKEN_PROGRAM_ID ) mediated_escrow_deposit, = get_mediated_escrow_deposit_address(id:) program_token_account, = get_vault_address(mint:) depositor_token_account, = Solace::Programs::AssociatedTokenAccount.get_address( owner: depositor, mint:, token_program_id: ) ix = Composers::ZarTrustlessEscrowMediatedReclaimComposer.new( mint:, depositor:, depositor_token_account:, mediated_escrow_deposit:, program_token_account:, fee_payer:, id:, program_id:, token_program_id: ) TransactionComposer.new(connection:).add_instruction(ix) end |
#compose_mediated_release(mint:, mediator:, recipient:, rent_collector:, id:, fee_payer:, token_program_id: Solace::Constants::TOKEN_PROGRAM_ID) ⇒ Solace::TransactionComposer
Prepares a mediated-release transaction. Derives the MediatedEscrowDeposit PDA, the program vault, and the recipient’s associated token account.
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
# File 'lib/solace/zar_trustless_escrow/programs/zar_trustless_escrow/mediated_escrow_deposit_operations.rb', line 157 def compose_mediated_release( mint:, mediator:, recipient:, rent_collector:, id:, fee_payer:, token_program_id: Solace::Constants::TOKEN_PROGRAM_ID ) mediated_escrow_deposit, = get_mediated_escrow_deposit_address(id:) program_token_account, = get_vault_address(mint:) recipient_token_account, = Solace::Programs::AssociatedTokenAccount.get_address( owner: recipient, mint:, token_program_id: ) ix = Composers::ZarTrustlessEscrowMediatedReleaseComposer.new( mint:, mediator:, recipient:, recipient_token_account:, mediated_escrow_deposit:, program_token_account:, rent_collector:, fee_payer:, id:, program_id:, token_program_id: ) TransactionComposer.new(connection:).add_instruction(ix) end |
#fetch_mediated_escrow_deposit(address:) ⇒ Solace::ZarTrustlessEscrow::MediatedEscrowDeposit
Fetches and deserializes the MediatedEscrowDeposit account at the given address. Derive the address first with Solace::Programs::ZarTrustlessEscrow#get_mediated_escrow_deposit_address.
20 21 22 23 24 25 26 27 |
# File 'lib/solace/zar_trustless_escrow/programs/zar_trustless_escrow/mediated_escrow_deposit_operations.rb', line 20 def fetch_mediated_escrow_deposit(address:) account = connection.get_account_info(address.to_s) raise "MediatedEscrowDeposit account not found at #{address}" unless account Solace::ZarTrustlessEscrow::MediatedEscrowDeposit.deserialize( Solace::Utils::Codecs.base64_to_bytestream(account['data'][0]) ) end |
#mediated_deposit(payer:, depositor:, sign: true, execute: true, **composer_opts) {|composer| ... } ⇒ Solace::Transaction
Deposits funds into a three-party mediated escrow, signs, and (optionally) sends it. The depositor and fee payer sign.
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/mediated_escrow_deposit_operations.rb', line 47 def mediated_deposit(payer:, depositor:, sign: true, execute: true, **composer_opts) composer = compose_mediated_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 |
#mediated_escrow_deposit_exists?(address:) ⇒ Boolean
Returns whether a MediatedEscrowDeposit account exists at the given address. Derive the address first with Solace::Programs::ZarTrustlessEscrow#get_mediated_escrow_deposit_address.
34 35 36 |
# File 'lib/solace/zar_trustless_escrow/programs/zar_trustless_escrow/mediated_escrow_deposit_operations.rb', line 34 def mediated_escrow_deposit_exists?(address:) !connection.get_account_info(address.to_s).nil? end |
#mediated_reclaim(payer:, depositor:, sign: true, execute: true, **composer_opts) {|composer| ... } ⇒ Solace::Transaction
Reclaims an expired mediated escrow as the depositor, signs, and (optionally) sends it. The depositor and fee payer sign.
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
# File 'lib/solace/zar_trustless_escrow/programs/zar_trustless_escrow/mediated_escrow_deposit_operations.rb', line 200 def mediated_reclaim(payer:, depositor:, sign: true, execute: true, **composer_opts) composer = compose_mediated_reclaim(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 |
#mediated_release(payer:, mediator:, sign: true, execute: true, **composer_opts) {|composer| ... } ⇒ Solace::Transaction
Releases a mediated escrow on behalf of the mediator, signs, and (optionally) sends it. The mediator and fee payer sign.
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/solace/zar_trustless_escrow/programs/zar_trustless_escrow/mediated_escrow_deposit_operations.rb', line 128 def mediated_release(payer:, mediator:, sign: true, execute: true, **composer_opts) composer = compose_mediated_release(fee_payer: payer, mediator:, **composer_opts) yield composer if block_given? tx = composer .set_fee_payer(payer) .compose_transaction if sign tx.sign(payer, mediator) connection.send_transaction(tx.serialize) if execute end tx end |