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.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
payer | Keypair | yes | — | The fee payer; co-signs. |
mint | #to_s | yes | — | The mint being escrowed. |
depositor | Keypair | yes | — | The depositor; co-signs. |
id | #to_s | yes | — | Unique id keying the escrow PDA — typically a fresh pubkey. |
mediator | #to_s | yes | — | The mediator who decides the outcome. |
beneficiary | #to_s | yes | — | The party the mediator may release funds to. |
amount | Integer | yes | — | Amount to deposit (base units). |
rent_collector | #to_s | no | nil | Account that receives the closed-account rent on release (defaults on chain to the mediator). |
expires_at | Integer | no | nil | Unix timestamp after which the depositor may reclaim. Must be in the future. See Expiry & Reclaim. |
token_program_id | String | no | legacy SPL Token | Token program that owns the mint. |
Plus the shared sign: / execute: controls and Solace::Transaction return — see Conventions.
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.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
mint | #to_s | yes | — | The mint being escrowed. |
depositor | #to_s | yes | — | The depositor (writable signer). |
depositor_token_account | #to_s | yes | — | The depositor's source token account (ATA). |
mediated_escrow_deposit | #to_s | yes | — | The MediatedEscrowDeposit PDA — from get_mediated_escrow_deposit_address. |
program_token_account | #to_s | yes | — | The vault PDA — from get_vault_address. |
fee_payer | #to_s · Keypair | yes | — | Fee payer; writable signer. |
amount | Integer | yes | — | Amount to deposit (base units). |
id | #to_s | yes | — | Unique id keying the escrow PDA. |
mediator | #to_s | yes | — | The mediator. |
beneficiary | #to_s | yes | — | The beneficiary. |
rent_collector | #to_s | no | nil | Optional rent collector on close. |
expires_at | Integer | no | nil | Optional reclaim timestamp. |
program_id | #to_s | no | mainnet PROGRAM_ID | The escrow program id. |
token_program_id | #to_s | no | legacy SPL Token | Token program that owns the mint. |
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.
| Parameter | Type | Required | Description |
|---|---|---|---|
amount | Integer | yes | u64 amount to deposit. |
id | #to_s | yes | Unique id; encoded into data and keys the PDA. |
mediator | #to_s | yes | Mediator pubkey; encoded into data. |
beneficiary | #to_s | yes | Beneficiary pubkey; encoded into data. |
rent_collector | #to_s, nil | yes | Optional rent collector; Borsh Option<publicKey>. |
expires_at | Integer, nil | yes | Optional expiry; Borsh Option<i64>. |
mint_index | Integer | yes | Index of the mint. |
depositor_index | Integer | yes | Index of the depositor. |
depositor_token_account_index | Integer | yes | Index of the depositor's token account. |
mediated_escrow_deposit_index | Integer | yes | Index of the MediatedEscrowDeposit PDA. |
program_token_account_index | Integer | yes | Index of the vault. |
fee_payer_index | Integer | yes | Index of the fee payer. |
system_program_index | Integer | yes | Index of the System program. |
token_program_index | Integer | yes | Index of the token program. |
program_index | Integer | yes | Index of the escrow program. |