Skip to content

Deposit

Locks tokens into a two-party escrow. The depositor moves amount tokens into the per-mint vault and creates an EscrowDeposit keyed by the claim authority — the account that can later claim the funds for a claimant. If never claimed, the depositor (or sponsor) can reclaim.

The deposit creates the per-mint vault on demand if it doesn't exist yet, so no setup is required — though you can pre-create it with token_account_init.

Program method — deposit

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

ParameterTypeRequiredDefaultDescription
payerKeypairyesThe fee payer (the depositor, or a sponsor); co-signs.
mint#to_syesThe mint being escrowed.
depositorKeypairyesThe depositor; co-signs. Source tokens come from its associated token account.
claim_authority#to_syesThe authority allowed to claim the deposit; keys the escrow PDA.
amountIntegeryesAmount to deposit (base units).
sponsor#to_snonilOptional fee sponsor recorded on the deposit. When set, payer must be the sponsor — see Sponsors & Fee Payers.
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.deposit(
  payer:           depositor,
  mint:            mint_address,
  depositor:       depositor,
  claim_authority: claim_authority.address,
  amount:          1_000_000
)
connection.wait_for_confirmed_signature { tx.signature }

Composer — ZarTrustlessEscrowDepositComposer

Use the composer for a custom fee payer/signing or to batch instructions. The escrow PDA, vault, and depositor token account must be resolved first (the program method does this via get_escrow_deposit_address, get_vault_address, and AssociatedTokenAccount.get_address).

ParameterTypeRequiredDefaultDescription
mint#to_syesThe mint being escrowed.
depositor#to_syesThe depositor (writable signer).
depositor_token_account#to_syesThe depositor's source token account (ATA).
escrow_deposit#to_syesThe EscrowDeposit PDA — from get_escrow_deposit_address.
program_token_account#to_syesThe vault PDA — from get_vault_address.
fee_payer#to_s · KeypairyesPays fee + rent; writable signer.
amountIntegeryesAmount to deposit (base units).
claim_authority#to_syesThe authority allowed to claim.
sponsor#to_snonilOptional fee sponsor recorded on the deposit.
program_id#to_snomainnet PROGRAM_IDThe escrow program id.
token_program_id#to_snolegacy SPL TokenToken program that owns the mint.
ruby
escrow_deposit, = program.get_escrow_deposit_address(claim_authority: claim_authority.address)
vault,          = program.get_vault_address(mint: mint_address)
depositor_ata,  = Solace::Programs::AssociatedTokenAccount.get_address(
  owner: depositor.address, mint: mint_address
)

composer = Solace::Composers::ZarTrustlessEscrowDepositComposer.new(
  mint:                    mint_address,
  depositor:               depositor.address,
  depositor_token_account: depositor_ata,
  escrow_deposit:          escrow_deposit,
  program_token_account:   vault,
  fee_payer:               depositor.address,
  amount:                  1_000_000,
  claim_authority:         claim_authority.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)

DepositInstruction.build encodes the raw instruction. Account positions are indices into the compiled message's AccountContext.

  • Discriminator: [242, 35, 198, 137, 82, 225, 242, 182]
  • Encodes (data): le_u64(amount) + pubkey(claim_authority) + option_pubkey(sponsor)
  • Accounts (in order): mint · depositor (writable signer) · depositor_token_account (writable) · escrow_deposit (writable) · program_token_account (writable) · fee_payer (writable signer) · system_program · token_program.
ParameterTypeRequiredDescription
amountIntegeryesu64 amount to deposit.
claim_authority#to_syesAuthority that can claim; encoded into data.
sponsor#to_s, nilyesOptional sponsor; encoded as a Borsh Option<publicKey>.
mint_indexIntegeryesIndex of the mint.
depositor_indexIntegeryesIndex of the depositor.
depositor_token_account_indexIntegeryesIndex of the depositor's token account.
escrow_deposit_indexIntegeryesIndex of the EscrowDeposit 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