Class: Solace::ZarTrustlessEscrow::Instructions::DepositInstruction

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

Overview

Encoder for the ‘deposit` instruction: locks `amount` tokens from the depositor into a per-claim-authority EscrowDeposit PDA and the per-mint program vault.

Constant Summary collapse

DISCRIMINATOR =

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

[242, 35, 198, 137, 82, 225, 242, 182].freeze

Class Method Summary collapse

Class Method Details

.build(amount:, claim_authority:, sponsor:, mint_index:, depositor_index:, depositor_token_account_index:, 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 ‘deposit`.

Account indices are in the on-chain order:

mint, depositor, depositor_token_account, 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
# File 'lib/solace/zar_trustless_escrow/instructions/deposit_instruction.rb', line 20

def self.build(
  amount:,
  claim_authority:,
  sponsor:,
  mint_index:,
  depositor_index:,
  depositor_token_account_index:,
  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,
      ,
      escrow_deposit_index,
      ,
      fee_payer_index,
      system_program_index,
      token_program_index
    ]
    ix.data = data(amount:, claim_authority:, sponsor:)
  end
end

.data(amount:, claim_authority:, sponsor:) ⇒ Array<Integer>

Encodes the DepositCreateArgs struct in Borsh format.

Parameters:

  • amount (Integer)

    u64 amount to deposit.

  • claim_authority (#to_s)

    base58 authority that can claim the deposit.

  • sponsor (#to_s, nil)

    optional base58 fee sponsor.

Returns:

  • (Array<Integer>)


56
57
58
59
60
61
# File 'lib/solace/zar_trustless_escrow/instructions/deposit_instruction.rb', line 56

def self.data(amount:, claim_authority:, sponsor:)
  DISCRIMINATOR +
    Solace::Utils::Codecs.encode_le_u64(amount).bytes +
    Solace::Utils::Codecs.encode_pubkey(claim_authority) +
    Solace::Utils::Codecs.encode_option_pubkey(sponsor)
end