Class: Solace::Programs::ZarTrustlessEscrow
- Inherits:
-
Base
- Object
- Base
- Solace::Programs::ZarTrustlessEscrow
- Defined in:
- lib/solace/zar_trustless_escrow/programs/zar_trustless_escrow.rb,
lib/solace/zar_trustless_escrow/programs/zar_trustless_escrow/escrow_deposit_operations.rb,
lib/solace/zar_trustless_escrow/programs/zar_trustless_escrow/mediated_escrow_deposit_operations.rb
Overview
High-level client for the ZAR Trustless Escrow program.
Provides PDA derivation (class methods), account fetching, the shared vault setup, and a compose/send pair per instruction. The instruction operations live in two mixins included below, split by escrow type:
- {EscrowDepositOperations} — two-party escrow (deposit/claim/reclaim).
- {MediatedEscrowDepositOperations} — three-party mediated escrow.
Defined Under Namespace
Modules: EscrowDepositOperations, MediatedEscrowDepositOperations
Class Method Summary collapse
-
.get_escrow_deposit_address(claim_authority:, program_id: Solace::ZarTrustlessEscrow::PROGRAM_ID) ⇒ Array<String, Integer>
Derives the EscrowDeposit PDA for a claim authority, from the on-chain seeds [“escrow_deposit”, claim_authority].
-
.get_mediated_escrow_deposit_address(id:, program_id: Solace::ZarTrustlessEscrow::PROGRAM_ID) ⇒ Array<String, Integer>
Derives the MediatedEscrowDeposit PDA for an id, from the on-chain seeds [“mediated_escrow_deposit”, id].
-
.get_vault_address(mint:, program_id: Solace::ZarTrustlessEscrow::PROGRAM_ID) ⇒ Array<String, Integer>
Derives the per-mint program vault PDA, from the on-chain seeds [“vault”, mint].
Instance Method Summary collapse
-
#compose_token_account_init(mint:, fee_payer:, token_program_id: Solace::Constants::TOKEN_PROGRAM_ID) ⇒ Solace::TransactionComposer
Prepares a token-account-init transaction.
-
#get_escrow_deposit_address(**options) ⇒ Array<String, Integer>
Alias for the class method, defaulting to this client’s program id.
-
#get_mediated_escrow_deposit_address(**options) ⇒ Array<String, Integer>
Alias for the class method, defaulting to this client’s program id.
-
#get_vault_address(**options) ⇒ Array<String, Integer>
Alias for the class method, defaulting to this client’s program id.
-
#initialize(connection:, program_id: Solace::ZarTrustlessEscrow::PROGRAM_ID) ⇒ ZarTrustlessEscrow
constructor
Initializes a new ZAR Trustless Escrow client.
-
#token_account_init(payer:, sign: true, execute: true, **composer_opts) {|composer| ... } ⇒ Solace::Transaction
Initializes the per-mint program vault, signs, and (optionally) sends it.
Methods included from MediatedEscrowDepositOperations
#compose_mediated_deposit, #compose_mediated_reclaim, #compose_mediated_release, #fetch_mediated_escrow_deposit, #mediated_deposit, #mediated_escrow_deposit_exists?, #mediated_reclaim, #mediated_release
Methods included from EscrowDepositOperations
#claim, #compose_claim, #compose_deposit, #compose_reclaim, #deposit, #escrow_deposit_exists?, #fetch_escrow_deposit, #reclaim
Constructor Details
#initialize(connection:, program_id: Solace::ZarTrustlessEscrow::PROGRAM_ID) ⇒ ZarTrustlessEscrow
Initializes a new ZAR Trustless Escrow client.
68 69 70 |
# File 'lib/solace/zar_trustless_escrow/programs/zar_trustless_escrow.rb', line 68 def initialize(connection:, program_id: Solace::ZarTrustlessEscrow::PROGRAM_ID) super end |
Class Method Details
.get_escrow_deposit_address(claim_authority:, program_id: Solace::ZarTrustlessEscrow::PROGRAM_ID) ⇒ Array<String, Integer>
Derives the EscrowDeposit PDA for a claim authority, from the on-chain seeds [“escrow_deposit”, claim_authority].
30 31 32 33 34 35 |
# File 'lib/solace/zar_trustless_escrow/programs/zar_trustless_escrow.rb', line 30 def get_escrow_deposit_address(claim_authority:, program_id: Solace::ZarTrustlessEscrow::PROGRAM_ID) Solace::Utils::PDA.find_program_address( [Solace::ZarTrustlessEscrow::ESCROW_DEPOSIT_SEED, .to_s], program_id.to_s ) end |
.get_mediated_escrow_deposit_address(id:, program_id: Solace::ZarTrustlessEscrow::PROGRAM_ID) ⇒ Array<String, Integer>
Derives the MediatedEscrowDeposit PDA for an id, from the on-chain seeds [“mediated_escrow_deposit”, id].
43 44 45 46 47 48 |
# File 'lib/solace/zar_trustless_escrow/programs/zar_trustless_escrow.rb', line 43 def get_mediated_escrow_deposit_address(id:, program_id: Solace::ZarTrustlessEscrow::PROGRAM_ID) Solace::Utils::PDA.find_program_address( [Solace::ZarTrustlessEscrow::MEDIATED_ESCROW_DEPOSIT_SEED, id.to_s], program_id.to_s ) end |
.get_vault_address(mint:, program_id: Solace::ZarTrustlessEscrow::PROGRAM_ID) ⇒ Array<String, Integer>
Derives the per-mint program vault PDA, from the on-chain seeds [“vault”, mint]. A single vault is shared across all deposits for a mint.
56 57 58 59 60 61 |
# File 'lib/solace/zar_trustless_escrow/programs/zar_trustless_escrow.rb', line 56 def get_vault_address(mint:, program_id: Solace::ZarTrustlessEscrow::PROGRAM_ID) Solace::Utils::PDA.find_program_address( [Solace::ZarTrustlessEscrow::VAULT_SEED, mint.to_s], program_id.to_s ) end |
Instance Method Details
#compose_token_account_init(mint:, fee_payer:, token_program_id: Solace::Constants::TOKEN_PROGRAM_ID) ⇒ Solace::TransactionComposer
Prepares a token-account-init transaction. Derives the program vault PDA.
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/solace/zar_trustless_escrow/programs/zar_trustless_escrow.rb', line 129 def compose_token_account_init( mint:, fee_payer:, token_program_id: Solace::Constants::TOKEN_PROGRAM_ID ) program_token_account, = get_vault_address(mint:) ix = Composers::ZarTrustlessEscrowTokenAccountInitComposer.new( mint:, program_token_account:, fee_payer:, program_id:, token_program_id: ) TransactionComposer.new(connection:).add_instruction(ix) end |
#get_escrow_deposit_address(**options) ⇒ Array<String, Integer>
Alias for the class method, defaulting to this client’s program id.
76 77 78 |
# File 'lib/solace/zar_trustless_escrow/programs/zar_trustless_escrow.rb', line 76 def get_escrow_deposit_address(**) self.class.get_escrow_deposit_address(program_id:, **) end |
#get_mediated_escrow_deposit_address(**options) ⇒ Array<String, Integer>
Alias for the class method, defaulting to this client’s program id.
84 85 86 |
# File 'lib/solace/zar_trustless_escrow/programs/zar_trustless_escrow.rb', line 84 def get_mediated_escrow_deposit_address(**) self.class.get_mediated_escrow_deposit_address(program_id:, **) end |
#get_vault_address(**options) ⇒ Array<String, Integer>
Alias for the class method, defaulting to this client’s program id.
92 93 94 |
# File 'lib/solace/zar_trustless_escrow/programs/zar_trustless_escrow.rb', line 92 def get_vault_address(**) self.class.get_vault_address(program_id:, **) end |
#token_account_init(payer:, sign: true, execute: true, **composer_opts) {|composer| ... } ⇒ Solace::Transaction
Initializes the per-mint program vault, signs, and (optionally) sends it. The vault is shared across both escrow types, so this lives on the client itself rather than in an escrow-type mixin. The fee payer is the only signer.
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/solace/zar_trustless_escrow/programs/zar_trustless_escrow.rb', line 105 def token_account_init(payer:, sign: true, execute: true, **composer_opts) composer = compose_token_account_init(fee_payer: payer, **composer_opts) yield composer if block_given? tx = composer .set_fee_payer(payer) .compose_transaction if sign tx.sign(payer) connection.send_transaction(tx.serialize) if execute end tx end |