Module: Solace::ZarTrustlessEscrow::Errors

Extended by:
Errors
Included in:
Errors
Defined in:
lib/solace/zar_trustless_escrow/errors.rb,
lib/solace/zar_trustless_escrow/errors/program_error.rb

Overview

Lookup for the on-chain TrustlessEscrowError codes, translating a custom program error code (e.g. from a failed transaction) into a ProgramError.

The mapping is ported from the program’s source of truth, programs/trustless_escrow/src/errors.rs — NOT the TypeScript SDK’s errors file, which is stale (it omits DepositAmountInvalid, shifting every later code, and is missing all mediated-escrow errors). Anchor assigns each variant a code of FIRST_ERROR_CODE + its declaration index.

Examples:

Solace::ZarTrustlessEscrow::Errors.from_code(6019)
# => #<ProgramError code=6019 error_name="MediatedExpiryMustBeInFuture" ...>

Defined Under Namespace

Classes: ProgramError

Constant Summary collapse

FIRST_ERROR_CODE =

First on-chain custom error code (Anchor’s default offset); maps to the first TrustlessEscrowError variant.

6000
DEFINITIONS =

TrustlessEscrowError variants in declaration order — index N is code FIRST_ERROR_CODE + N. Each entry is [variant name, on-chain #[msg] text].

[
  ['MintInvalid',
   "MintInvalid: The mint provided does not match the escrow deposit's mint."],
  ['DepositorInvalid',
   'Depositor invalid'],
  ['DepositAmountInvalid',
   'DepositAmountInvalid: The deposit amount must be greater than 0.'],
  ['SubsidyMismatch',
   'Subsidy mismatch'],
  ['InvalidAuthority',
   'Either fee payer should be sponsor or depositor should be signer'],
  ['InvalidCloseAuthority',
   'InvalidCloseAuthority: When a sponsor is present, the fee payer must be the sponsor.'],
  ['ClaimAuthorityMustBeASigner',
   'ClaimAuthorityMustBeASigner: The claim authority must be a signer.'],
  ['ClaimAuthorityIsInvalid',
   "ClaimAuthorityIsInvalid: The claim authority provided does not match the escrow deposit's claim authority."],
  ['DepositorCannotBeClaimant',
   'DepositorCannotBeClaimant: The depositor cannot be the claimant (use reclaim instruction instead).'],
  ['ReclaimerMustBeDepositor',
   'ReclaimerMustBeDepositor: The reclaimer must be the depositor.'],
  ['InvalidReclaimSigner',
   'InvalidReclaimSigner: The reclaimer signer must be the depositor or the sponsor.'],
  ['MediatorCannotBeDepositorOrBeneficiary',
   'MediatorCannotBeDepositorOrBeneficiary: The mediator cannot be the depositor or the beneficiary.'],
  ['InvalidMediator',
   'InvalidMediator: The signer is not the mediator of the mediated escrow deposit.'],
  ['MediatedDepositorCannotBeBeneficiary',
   'MediatedDepositorCannotBeBeneficiary: The depositor and beneficiary cannot be the same account.'],
  ['InvalidReleaseRecipient',
   'InvalidReleaseRecipient: The recipient must be either the depositor or the beneficiary.'],
  ['MediatedReclaimNotExpirable',
   'MediatedReclaimNotExpirable: No expiry is set, so only the mediator can distribute the funds.'],
  ['MediatedReclaimNotYetExpired',
   'MediatedReclaimNotYetExpired: The mediated escrow deposit cannot be reclaimed before its expiry timestamp.'],
  ['MediatedReclaimerMustBeDepositor',
   'MediatedReclaimerMustBeDepositor: Only the depositor can reclaim the deposit after the expiry date.'],
  ['InvalidRentCollector',
   'InvalidRentCollector: The rent collector provided does not match the mediated escrow ' \
   "deposit's rent collector."],
  ['MediatedExpiryMustBeInFuture',
   'MediatedExpiryMustBeInFuture: The expiry timestamp, when provided, must be in the future.']
].freeze
BY_CODE =

code => [name, message], derived by offsetting each declaration index with FIRST_ERROR_CODE.

DEFINITIONS.each_with_index.to_h do |(name, message), index|
  [FIRST_ERROR_CODE + index, [name, message]]
end.freeze
CODE_BY_NAME =

name => code, for resolving an error by its variant name.

BY_CODE.to_h { |code, (name, _message)| [name, code] }.freeze

Instance Method Summary collapse

Instance Method Details

#from_code(code) ⇒ ProgramError?

Resolves a ProgramError from an on-chain custom error code.

Parameters:

  • code (Integer)

    The custom program error code (e.g. 6019).

Returns:

  • (ProgramError, nil)

    The typed error, or nil if the code is unknown.



85
86
87
88
89
90
# File 'lib/solace/zar_trustless_escrow/errors.rb', line 85

def from_code(code)
  name, message = BY_CODE[code]
  return nil unless name

  ProgramError.new(code:, error_name: name, message:)
end

#from_name(name) ⇒ ProgramError?

Resolves a ProgramError from a TrustlessEscrowError variant name.

Parameters:

  • name (String)

    The variant name (e.g. “InvalidMediator”).

Returns:

  • (ProgramError, nil)

    The typed error, or nil if the name is unknown.



96
97
98
99
100
101
# File 'lib/solace/zar_trustless_escrow/errors.rb', line 96

def from_name(name)
  code = CODE_BY_NAME[name]
  return nil unless code

  from_code(code)
end