Skip to content

Mediated Release

Releases a mediated escrow to a recipient — either the depositor or the beneficiary. The mediator (a required signer) authorizes the transfer; the program moves the escrowed tokens from the vault to the recipient's associated token account, closes the MediatedEscrowDeposit, and sends its rent to the rent collector.

The recipient must be either the deposit's depositor or its beneficiary — the program rejects any other account.

Program method — mediated_release

Derives the mediated escrow PDA, the vault, and the recipient's associated token account, then builds, signs (payer + mediator), and sends.

ParameterTypeRequiredDefaultDescription
payerKeypairyesThe fee payer; co-signs.
mint#to_syesThe escrowed mint.
mediatorKeypairyesThe deposit's mediator; co-signs.
recipient#to_syesThe depositor or beneficiary receiving the tokens (its ATA is derived).
rent_collector#to_syesAccount that receives the closed-account rent. Must match the deposit's rent collector (the mediator, if none was set).
id#to_syesThe unique id the escrow was created with.
token_program_idStringnolegacy SPL TokenToken program that owns the mint.

Plus the shared sign: / execute: controls and Solace::Transaction return — see Conventions.

ruby
tx = program.mediated_release(
  payer:          mediator,
  mint:           mint_address,
  mediator:       mediator,
  recipient:      beneficiary.address,
  rent_collector: mediator.address,
  id:
)
connection.wait_for_confirmed_signature { tx.signature }

TIP

The deposit records who the rent collector is (defaulting to the mediator). To fill it from chain, fetch the deposit first: program.fetch_mediated_escrow_deposit(address:).rent_collector — see PDA Derivation & Fetchers.

Composer — ZarTrustlessEscrowMediatedReleaseComposer

The mediated escrow PDA, vault, and recipient token account must be resolved first.

ParameterTypeRequiredDefaultDescription
mint#to_syesThe escrowed mint.
mediator#to_syesThe mediator (readonly signer).
recipient#to_syesDepositor or beneficiary receiving the tokens.
recipient_token_account#to_syesThe recipient's destination token account (ATA).
mediated_escrow_deposit#to_syesThe MediatedEscrowDeposit PDA.
program_token_account#to_syesThe vault PDA.
rent_collector#to_syesReceives the closed-account rent.
fee_payer#to_s · KeypairyesFee payer; writable signer.
id#to_syesThe unique id the escrow was created with.
program_id#to_snomainnet PROGRAM_IDThe escrow program id.
token_program_id#to_snolegacy SPL TokenToken program that owns the mint.
ruby
mediated_escrow, = program.get_mediated_escrow_deposit_address(id:)
vault,           = program.get_vault_address(mint: mint_address)
recipient_ata,   = Solace::Programs::AssociatedTokenAccount.get_address(
  owner: beneficiary.address, mint: mint_address
)

composer = Solace::Composers::ZarTrustlessEscrowMediatedReleaseComposer.new(
  mint:                    mint_address,
  mediator:                mediator.address,
  recipient:               beneficiary.address,
  recipient_token_account: recipient_ata,
  mediated_escrow_deposit: mediated_escrow,
  program_token_account:   vault,
  rent_collector:          mediator.address,
  fee_payer:               mediator.address,
  id:
)

tx = Solace::TransactionComposer.new(connection:)
                                .add_instruction(composer)
                                .set_fee_payer(mediator)
                                .compose_transaction

tx.sign(mediator)
connection.send_transaction(tx.serialize)

Low-level instruction (advanced)

MediatedReleaseInstruction.build encodes the raw instruction.

  • Discriminator: [154, 204, 22, 195, 162, 179, 197, 181]
  • Encodes (data): pubkey(id)
  • Accounts (in order): mint · mediator (readonly signer) · recipient · recipient_token_account (writable) · mediated_escrow_deposit (writable) · program_token_account (writable) · rent_collector (writable) · fee_payer (writable signer) · system_program · token_program · associated_token_program.
ParameterTypeRequiredDescription
id#to_syesUnique id; encoded into data.
mint_indexIntegeryesIndex of the mint.
mediator_indexIntegeryesIndex of the mediator.
recipient_indexIntegeryesIndex of the recipient.
recipient_token_account_indexIntegeryesIndex of the recipient's token account.
mediated_escrow_deposit_indexIntegeryesIndex of the MediatedEscrowDeposit PDA.
program_token_account_indexIntegeryesIndex of the vault.
rent_collector_indexIntegeryesIndex of the rent collector.
fee_payer_indexIntegeryesIndex of the fee payer.
system_program_indexIntegeryesIndex of the System program.
token_program_indexIntegeryesIndex of the token program.
associated_token_program_indexIntegeryesIndex of the Associated Token Account program.
program_indexIntegeryesIndex of the escrow program.

Built on Solace