Class: Solace::ZarTrustlessEscrow::Instructions::MediatedDepositInstruction

Inherits:
Object
  • Object
show all
Defined in:
lib/solace/zar_trustless_escrow/instructions/mediated_deposit_instruction.rb

Overview

Encoder for the ‘mediated_deposit` instruction: locks `amount` tokens into a three-party MediatedEscrowDeposit PDA (keyed by `id`) and the per-mint program vault.

Constant Summary collapse

DISCRIMINATOR =

8-byte Anchor discriminator: SHA256(“global:mediated_deposit”).

[138, 97, 90, 177, 112, 255, 208, 193].freeze

Class Method Summary collapse

Class Method Details

.build(amount:, id:, mediator:, beneficiary:, rent_collector:, expires_at:, mint_index:, depositor_index:, depositor_token_account_index:, mediated_escrow_deposit_index:, program_token_account_index:, fee_payer_index:, system_program_index:, token_program_index:, program_index:) ⇒ Solace::Instruction

Builds a Solace::Instruction for ‘mediated_deposit`.

Account indices are in the on-chain order:

mint, depositor, depositor_token_account, mediated_escrow_deposit,
program_token_account, fee_payer, system_program, token_program.

Returns:

  • (Solace::Instruction)


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/solace/zar_trustless_escrow/instructions/mediated_deposit_instruction.rb', line 20

def self.build(
  amount:,
  id:,
  mediator:,
  beneficiary:,
  rent_collector:,
  expires_at:,
  mint_index:,
  depositor_index:,
  depositor_token_account_index:,
  mediated_escrow_deposit_index:,
  program_token_account_index:,
  fee_payer_index:,
  system_program_index:,
  token_program_index:,
  program_index:
)
  Solace::Instruction.new.tap do |ix|
    ix.program_index = program_index
    ix.accounts      = [
      mint_index,
      depositor_index,
      ,
      mediated_escrow_deposit_index,
      ,
      fee_payer_index,
      system_program_index,
      token_program_index
    ]
    ix.data = data(amount:, id:, mediator:, beneficiary:, rent_collector:, expires_at:)
  end
end

.data(amount:, id:, mediator:, beneficiary:, rent_collector:, expires_at:) ⇒ Array<Integer>

Encodes the MediatedDepositCreateArgs struct in Borsh format.

Parameters:

  • amount (Integer)

    u64 amount to deposit.

  • id (#to_s)

    base58 unique id used to derive the mediated escrow PDA.

  • mediator (#to_s)

    base58 mediator who decides the outcome.

  • beneficiary (#to_s)

    base58 beneficiary the mediator may release to.

  • rent_collector (#to_s, nil)

    optional base58 rent collector on close.

  • expires_at (Integer, nil)

    optional unix timestamp for depositor reclaim.

Returns:

  • (Array<Integer>)


62
63
64
65
66
67
68
69
70
# File 'lib/solace/zar_trustless_escrow/instructions/mediated_deposit_instruction.rb', line 62

def self.data(amount:, id:, mediator:, beneficiary:, rent_collector:, expires_at:)
  DISCRIMINATOR +
    Solace::Utils::Codecs.encode_le_u64(amount).bytes +
    Solace::Utils::Codecs.encode_pubkey(id) +
    Solace::Utils::Codecs.encode_pubkey(mediator) +
    Solace::Utils::Codecs.encode_pubkey(beneficiary) +
    Solace::Utils::Codecs.encode_option_pubkey(rent_collector) +
    Solace::Utils::Codecs.encode_option_i64(expires_at)
end