Skip to content

Mediated Deposit

Locks tokens into a three-party mediated escrow. The depositor moves amount tokens into the per-mint vault and creates a MediatedEscrowDeposit keyed by a caller-chosen id, naming a mediator and a beneficiary. The mediator later releases the funds; with an expires_at set, the depositor can reclaim after expiry.

This instruction initializes the vault on demand, so no separate token_account_init call is required.

Program method — mediated_deposit

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

ParameterTypeRequiredDefaultDescription
payerKeypairyesThe fee payer; co-signs.
mint#to_syesThe mint being escrowed.
depositorKeypairyesThe depositor; co-signs.
id#to_syesUnique id keying the escrow PDA — typically a fresh pubkey.
mediator#to_syesThe mediator who decides the outcome.
beneficiary#to_syesThe party the mediator may release funds to.
amountIntegeryesAmount to deposit (base units).
rent_collector#to_snonilAccount that receives the closed-account rent on release (defaults on chain to the mediator).
expires_atIntegernonilUnix timestamp after which the depositor may reclaim. Must be in the future. See Expiry & Reclaim.
token_program_idStringnolegacy SPL TokenToken program that owns the mint.

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

ruby
id = Solace::Keypair.generate.address

tx = program.mediated_deposit(
  payer:       depositor,
  mint:        mint_address,
  depositor:   depositor,
  id:,
  mediator:    mediator.address,
  beneficiary: beneficiary.address,
  amount:      1_000_000
)
connection.wait_for_confirmed_signature { tx.signature }

Composer — ZarTrustlessEscrowMediatedDepositComposer

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

ParameterTypeRequiredDefaultDescription
mint#to_syesThe mint being escrowed.
depositor#to_syesThe depositor (writable signer).
depositor_token_account#to_syesThe depositor's source token account (ATA).
mediated_escrow_deposit#to_syesThe MediatedEscrowDeposit PDA — from get_mediated_escrow_deposit_address.
program_token_account#to_syesThe vault PDA — from get_vault_address.
fee_payer#to_s · KeypairyesFee payer; writable signer.
amountIntegeryesAmount to deposit (base units).
id#to_syesUnique id keying the escrow PDA.
mediator#to_syesThe mediator.
beneficiary#to_syesThe beneficiary.
rent_collector#to_snonilOptional rent collector on close.
expires_atIntegernonilOptional reclaim timestamp.
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)
depositor_ata,   = Solace::Programs::AssociatedTokenAccount.get_address(
  owner: depositor.address, mint: mint_address
)

composer = Solace::Composers::ZarTrustlessEscrowMediatedDepositComposer.new(
  mint:                    mint_address,
  depositor:               depositor.address,
  depositor_token_account: depositor_ata,
  mediated_escrow_deposit: mediated_escrow,
  program_token_account:   vault,
  fee_payer:               depositor.address,
  amount:                  1_000_000,
  id:,
  mediator:                mediator.address,
  beneficiary:             beneficiary.address
)

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

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

Low-level instruction (advanced)

MediatedDepositInstruction.build encodes the raw instruction.

  • Discriminator: [138, 97, 90, 177, 112, 255, 208, 193]
  • Encodes (data): le_u64(amount) + pubkey(id) + pubkey(mediator) + pubkey(beneficiary) + option_pubkey(rent_collector) + option_i64(expires_at)
  • Accounts (in order): mint · depositor (writable signer) · depositor_token_account (writable) · mediated_escrow_deposit (writable) · program_token_account (writable) · fee_payer (writable signer) · system_program · token_program.
ParameterTypeRequiredDescription
amountIntegeryesu64 amount to deposit.
id#to_syesUnique id; encoded into data and keys the PDA.
mediator#to_syesMediator pubkey; encoded into data.
beneficiary#to_syesBeneficiary pubkey; encoded into data.
rent_collector#to_s, nilyesOptional rent collector; Borsh Option<publicKey>.
expires_atInteger, nilyesOptional expiry; Borsh Option<i64>.
mint_indexIntegeryesIndex of the mint.
depositor_indexIntegeryesIndex of the depositor.
depositor_token_account_indexIntegeryesIndex of the depositor's token account.
mediated_escrow_deposit_indexIntegeryesIndex of the MediatedEscrowDeposit PDA.
program_token_account_indexIntegeryesIndex of the vault.
fee_payer_indexIntegeryesIndex of the fee payer.
system_program_indexIntegeryesIndex of the System program.
token_program_indexIntegeryesIndex of the token program.
program_indexIntegeryesIndex of the escrow program.

Built on Solace