pub struct EscrowSdk;Expand description
SDK for interacting with the Escrow program
Implementations§
Source§impl EscrowSdk
impl EscrowSdk
Sourcepub fn program_id() -> Pubkey
pub fn program_id() -> Pubkey
Get the program ID
Get the authority transfer PDA
Sourcepub fn config_pda() -> (Pubkey, u8)
pub fn config_pda() -> (Pubkey, u8)
Get the config PDA
Sourcepub fn escrow_pda(mint: Pubkey) -> (Pubkey, u8)
pub fn escrow_pda(mint: Pubkey) -> (Pubkey, u8)
Get an escrow PDA for a specific mint
Sourcepub fn payment_pda(payment_uid: &str, bank: Pubkey) -> (Pubkey, u8)
pub fn payment_pda(payment_uid: &str, bank: Pubkey) -> (Pubkey, u8)
Get a payment PDA for a specific payment UID
Sourcepub fn sol_storage_pda(
mint: Pubkey,
bank: Pubkey,
escrow: Pubkey,
) -> (Pubkey, u8)
pub fn sol_storage_pda( mint: Pubkey, bank: Pubkey, escrow: Pubkey, ) -> (Pubkey, u8)
Get a SOL storage PDA for a specific escrow
Sourcepub fn associated_token_account(wallet: Pubkey, mint: Pubkey) -> Pubkey
pub fn associated_token_account(wallet: Pubkey, mint: Pubkey) -> Pubkey
Get the associated token account for a wallet and mint
Sourcepub fn associated_token_account_with_program(
wallet: Pubkey,
mint: Pubkey,
token_program: Pubkey,
) -> Pubkey
pub fn associated_token_account_with_program( wallet: Pubkey, mint: Pubkey, token_program: Pubkey, ) -> Pubkey
Get the associated token account for a wallet and mint using the given token program.
Sourcepub fn escrow_token_account(mint: Pubkey) -> Pubkey
pub fn escrow_token_account(mint: Pubkey) -> Pubkey
Get the associated token account for an escrow
Sourcepub fn escrow_token_account_with_program(
mint: Pubkey,
token_program: Pubkey,
) -> Pubkey
pub fn escrow_token_account_with_program( mint: Pubkey, token_program: Pubkey, ) -> Pubkey
Get the associated token account for an escrow using the given token program.
Sourcepub fn calculate_gross_quote(
desired_net: u64,
fee_bps: u16,
min_fee_amount: u64,
oracle_fee_bps: u16,
) -> u64
pub fn calculate_gross_quote( desired_net: u64, fee_bps: u16, min_fee_amount: u64, oracle_fee_bps: u16, ) -> u64
Calculate the minimum gross amount to charge a Buyer in order to receive a specific net payout hitting the Seller’s wallet, taking into account protocol fees and oracle tips.
§Explanation of desired_net
desired_net is the final actual quantity of tokens deposited into the Seller’s wallet after
sla-escrow subtracts all protocol fees and oracle fees during ReleasePayment.
Example:
If you are an AI Image Generation Agent where a single generation costs you $0.80 in cloud GPU overhead,
and you want to make exactly $0.20 in profit, your desired_net must be $1.00 (which is $0.80 cost + $0.20 profit).
You pass $1.00 (in raw token decimals) as desired_net, and this function will return the inflated gross_quote (e.g. $1.15)
that you must charge the Buyer in order to mathematically satisfy the protocol fees and walk away with exactly $1.00.
Sourcepub fn initialize(signer: Pubkey, fee_bps: Option<u16>) -> Instruction
pub fn initialize(signer: Pubkey, fee_bps: Option<u16>) -> Instruction
Create an initialize instruction
Sourcepub fn open_escrow(
signer: Pubkey,
payer: Pubkey,
mint: Pubkey,
min_payment_amount: u64,
max_payment_amount: u64,
min_fee_amount: u64,
fee_bps: u16,
oracle_fee_bps: u16,
) -> Instruction
pub fn open_escrow( signer: Pubkey, payer: Pubkey, mint: Pubkey, min_payment_amount: u64, max_payment_amount: u64, min_fee_amount: u64, fee_bps: u16, oracle_fee_bps: u16, ) -> Instruction
Create an open escrow instruction signer: bank authority payer: funder mint: token mint min_payment_amount: minimum payment amount max_payment_amount: maximum payment amount fee_bps: fee basis points oracle_fee_bps: oracle tip basis points (0 = disabled)
Sourcepub fn open_escrow_with_token_program(
signer: Pubkey,
payer: Pubkey,
mint: Pubkey,
min_payment_amount: u64,
max_payment_amount: u64,
min_fee_amount: u64,
fee_bps: u16,
oracle_fee_bps: u16,
token_program: Pubkey,
) -> Instruction
pub fn open_escrow_with_token_program( signer: Pubkey, payer: Pubkey, mint: Pubkey, min_payment_amount: u64, max_payment_amount: u64, min_fee_amount: u64, fee_bps: u16, oracle_fee_bps: u16, token_program: Pubkey, ) -> Instruction
Create an open escrow instruction with an explicit token program.
Sourcepub fn fund_payment(
buyer: Pubkey,
buyer_tokens: Option<Pubkey>,
seller: Pubkey,
mint: Pubkey,
amount: u64,
ttl_seconds: i64,
payment_uid: &str,
sla_hash: [u8; 32],
oracle_authority: Pubkey,
) -> Instruction
pub fn fund_payment( buyer: Pubkey, buyer_tokens: Option<Pubkey>, seller: Pubkey, mint: Pubkey, amount: u64, ttl_seconds: i64, payment_uid: &str, sla_hash: [u8; 32], oracle_authority: Pubkey, ) -> Instruction
Create a fund payment instruction (supports both SOL and SPL tokens) For SOL: mint should be Pubkey::default() For SPL tokens: mint should be the actual token mint
Sourcepub fn fund_payment_with_token_program(
buyer: Pubkey,
buyer_tokens: Option<Pubkey>,
seller: Pubkey,
mint: Pubkey,
amount: u64,
ttl_seconds: i64,
payment_uid: &str,
sla_hash: [u8; 32],
oracle_authority: Pubkey,
token_program: Pubkey,
) -> Instruction
pub fn fund_payment_with_token_program( buyer: Pubkey, buyer_tokens: Option<Pubkey>, seller: Pubkey, mint: Pubkey, amount: u64, ttl_seconds: i64, payment_uid: &str, sla_hash: [u8; 32], oracle_authority: Pubkey, token_program: Pubkey, ) -> Instruction
Create a fund payment instruction with an explicit token program.
Sourcepub fn release_payment(
caller: Pubkey,
seller_tokens: Option<Pubkey>,
seller: Option<Pubkey>,
mint: Pubkey,
payment_uid: &str,
oracle_tokens: Option<Pubkey>,
oracle_authority: Option<Pubkey>,
) -> Instruction
pub fn release_payment( caller: Pubkey, seller_tokens: Option<Pubkey>, seller: Option<Pubkey>, mint: Pubkey, payment_uid: &str, oracle_tokens: Option<Pubkey>, oracle_authority: Option<Pubkey>, ) -> Instruction
Create a release payment instruction (supports both SOL and SPL tokens) For SOL: mint should be Pubkey::default() For SPL tokens: mint should be the actual token mint
Sourcepub fn release_payment_with_token_program(
caller: Pubkey,
seller_tokens: Option<Pubkey>,
seller: Option<Pubkey>,
mint: Pubkey,
payment_uid: &str,
oracle_tokens: Option<Pubkey>,
oracle_authority: Option<Pubkey>,
token_program: Pubkey,
) -> Instruction
pub fn release_payment_with_token_program( caller: Pubkey, seller_tokens: Option<Pubkey>, seller: Option<Pubkey>, mint: Pubkey, payment_uid: &str, oracle_tokens: Option<Pubkey>, oracle_authority: Option<Pubkey>, token_program: Pubkey, ) -> Instruction
Create a release payment instruction with an explicit token program.
Sourcepub fn refund_payment(
caller: Pubkey,
buyer_tokens: Option<Pubkey>,
mint: Pubkey,
payment_uid: &str,
oracle_tokens: Option<Pubkey>,
oracle_authority: Option<Pubkey>,
) -> Instruction
pub fn refund_payment( caller: Pubkey, buyer_tokens: Option<Pubkey>, mint: Pubkey, payment_uid: &str, oracle_tokens: Option<Pubkey>, oracle_authority: Option<Pubkey>, ) -> Instruction
Create a refund payment instruction (supports both SOL and SPL tokens) For SOL: mint should be Pubkey::default() For SPL tokens: mint should be the actual token mint
Sourcepub fn refund_payment_with_token_program(
caller: Pubkey,
buyer_tokens: Option<Pubkey>,
mint: Pubkey,
payment_uid: &str,
oracle_tokens: Option<Pubkey>,
oracle_authority: Option<Pubkey>,
token_program: Pubkey,
) -> Instruction
pub fn refund_payment_with_token_program( caller: Pubkey, buyer_tokens: Option<Pubkey>, mint: Pubkey, payment_uid: &str, oracle_tokens: Option<Pubkey>, oracle_authority: Option<Pubkey>, token_program: Pubkey, ) -> Instruction
Create a refund payment instruction with an explicit token program.
Sourcepub fn submit_delivery(
caller: Pubkey,
mint: Pubkey,
payment_uid: &str,
delivery_hash: [u8; 32],
) -> Instruction
pub fn submit_delivery( caller: Pubkey, mint: Pubkey, payment_uid: &str, delivery_hash: [u8; 32], ) -> Instruction
Create a submit delivery instruction
Sourcepub fn close_payment(
caller: Pubkey,
buyer: Pubkey,
mint: Pubkey,
payment_uid: &str,
) -> Instruction
pub fn close_payment( caller: Pubkey, buyer: Pubkey, mint: Pubkey, payment_uid: &str, ) -> Instruction
Create a close payment instruction
Sourcepub fn withdraw_fees(
authority: Pubkey,
beneficiary: Pubkey,
mint: Pubkey,
amount: u64,
) -> Instruction
pub fn withdraw_fees( authority: Pubkey, beneficiary: Pubkey, mint: Pubkey, amount: u64, ) -> Instruction
Create a withdraw fees instruction (supports both SOL and SPL tokens) For SOL: mint should be Pubkey::default() For SPL tokens: mint should be the actual token mint
Sourcepub fn withdraw_fees_with_token_program(
authority: Pubkey,
beneficiary: Pubkey,
mint: Pubkey,
amount: u64,
token_program: Pubkey,
) -> Instruction
pub fn withdraw_fees_with_token_program( authority: Pubkey, beneficiary: Pubkey, mint: Pubkey, amount: u64, token_program: Pubkey, ) -> Instruction
Create a withdraw fees instruction with an explicit token program.
Sourcepub fn extend_payment_ttl(
caller: Pubkey,
mint: Pubkey,
payment_uid: &str,
additional_seconds: i64,
) -> Instruction
pub fn extend_payment_ttl( caller: Pubkey, mint: Pubkey, payment_uid: &str, additional_seconds: i64, ) -> Instruction
Create an extend payment TTL instruction
Sourcepub fn close_escrow(
authority: Pubkey,
recipient: Pubkey,
mint: Pubkey,
) -> Instruction
pub fn close_escrow( authority: Pubkey, recipient: Pubkey, mint: Pubkey, ) -> Instruction
Create a close escrow instruction
Sourcepub fn close_escrow_with_token_program(
authority: Pubkey,
recipient: Pubkey,
mint: Pubkey,
token_program: Pubkey,
) -> Instruction
pub fn close_escrow_with_token_program( authority: Pubkey, recipient: Pubkey, mint: Pubkey, token_program: Pubkey, ) -> Instruction
Create a close escrow instruction with an explicit token program.
Sourcepub fn update_escrow_settings(
authority: Pubkey,
escrow: Pubkey,
fee_bps: u16,
min_payment_amount: u64,
max_payment_amount: u64,
min_fee_amount: u64,
oracle_fee_bps: u16,
) -> Instruction
pub fn update_escrow_settings( authority: Pubkey, escrow: Pubkey, fee_bps: u16, min_payment_amount: u64, max_payment_amount: u64, min_fee_amount: u64, oracle_fee_bps: u16, ) -> Instruction
Create an update escrow settings instruction
Sourcepub fn pause_escrow(authority: Pubkey, mint: Pubkey, pause: bool) -> Instruction
pub fn pause_escrow(authority: Pubkey, mint: Pubkey, pause: bool) -> Instruction
Create a pause escrow instruction
Create an update authority instruction (Step 1: Propose)
Create an accept authority instruction (Step 2: Accept)
Create a cancel authority proposal instruction
Sourcepub fn update_config(
admin: Pubkey,
closure_delay_seconds: i64,
refund_cooldown_seconds: i64,
delivery_cutoff_seconds: i64,
) -> Instruction
pub fn update_config( admin: Pubkey, closure_delay_seconds: i64, refund_cooldown_seconds: i64, delivery_cutoff_seconds: i64, ) -> Instruction
Create an update config instruction (admin only).
Tunes global, program-wide policy knobs that are snapshotted into every
newly funded Payment via EscrowSdk::fund_payment. Existing
payments retain the values captured at funding time.
Sourcepub fn confirm_oracle(
oracle_authority: Pubkey,
mint: Pubkey,
payment_uid: &str,
delivery_hash: [u8; 32],
resolution_hash: [u8; 32],
resolution_state: u8,
resolution_reason: u16,
) -> Instruction
pub fn confirm_oracle( oracle_authority: Pubkey, mint: Pubkey, payment_uid: &str, delivery_hash: [u8; 32], resolution_hash: [u8; 32], resolution_state: u8, resolution_reason: u16, ) -> Instruction
Create a confirm oracle instruction (oracle confirms fulfillment)
Build a ConfirmOracle instruction.
resolution_hash is an opaque 32-byte attestation digest chosen by the
oracle (e.g. SHA-256 of the oracle’s signed evidence bundle). It is
stored on the Payment and emitted in [PaymentOracleConfirmedEvent]
for auditors / multi-oracle aggregators / insurance consumers. Pass
[0u8; 32] when no attestation digest is available.
Sourcepub fn validate_payment_for_funding(
payment: &Payment,
) -> Result<(), EscrowError>
pub fn validate_payment_for_funding( payment: &Payment, ) -> Result<(), EscrowError>
Validate that a payment is in the correct state for funding
Sourcepub fn validate_payment_for_release(
payment: &Payment,
) -> Result<(), EscrowError>
pub fn validate_payment_for_release( payment: &Payment, ) -> Result<(), EscrowError>
Validate that a payment is in the correct state for release
Sourcepub fn validate_payment_for_refund(payment: &Payment) -> Result<(), EscrowError>
pub fn validate_payment_for_refund(payment: &Payment) -> Result<(), EscrowError>
Validate that a payment is in the correct state for refund
Sourcepub fn calculate_fee(amount: u64, fee_bps: u16, min_fee_amount: u64) -> u64
pub fn calculate_fee(amount: u64, fee_bps: u16, min_fee_amount: u64) -> u64
Calculate fee amount based on payment amount, fee basis points, and minimum fee
Sourcepub fn calculate_payout(amount: u64, fee_bps: u16, min_fee_amount: u64) -> u64
pub fn calculate_payout(amount: u64, fee_bps: u16, min_fee_amount: u64) -> u64
Calculate payout amount after deducting fees
Sourcepub fn is_payment_expired(payment: &Payment) -> bool
pub fn is_payment_expired(payment: &Payment) -> bool
Check if a payment has expired
Sourcepub fn get_payment_state_string(state: u8) -> &'static str
pub fn get_payment_state_string(state: u8) -> &'static str
Get payment state as string
Sourcepub fn get_escrow_state_string(paused: u8) -> &'static str
pub fn get_escrow_state_string(paused: u8) -> &'static str
Get escrow state as string
Sourcepub fn get_payment_accounts(
buyer: Pubkey,
seller: Pubkey,
mint: Pubkey,
payment_uid: &str,
) -> PaymentAccounts
pub fn get_payment_accounts( buyer: Pubkey, seller: Pubkey, mint: Pubkey, payment_uid: &str, ) -> PaymentAccounts
Get all required accounts for a payment operation
Sourcepub fn get_payment_accounts_with_token_program(
buyer: Pubkey,
seller: Pubkey,
mint: Pubkey,
payment_uid: &str,
token_program: Pubkey,
) -> PaymentAccounts
pub fn get_payment_accounts_with_token_program( buyer: Pubkey, seller: Pubkey, mint: Pubkey, payment_uid: &str, token_program: Pubkey, ) -> PaymentAccounts
Get all required accounts for a payment operation with an explicit token program.
Sourcepub fn get_escrow_accounts(mint: Pubkey) -> EscrowAccounts
pub fn get_escrow_accounts(mint: Pubkey) -> EscrowAccounts
Get all required accounts for an escrow operation
Sourcepub fn get_escrow_accounts_with_token_program(
mint: Pubkey,
token_program: Pubkey,
) -> EscrowAccounts
pub fn get_escrow_accounts_with_token_program( mint: Pubkey, token_program: Pubkey, ) -> EscrowAccounts
Get all required accounts for an escrow operation with an explicit token program.
Auto Trait Implementations§
impl Freeze for EscrowSdk
impl RefUnwindSafe for EscrowSdk
impl Send for EscrowSdk
impl Sync for EscrowSdk
impl Unpin for EscrowSdk
impl UnsafeUnpin for EscrowSdk
impl UnwindSafe for EscrowSdk
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CheckedAs for T
impl<T> CheckedAs for T
Source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
Source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
Source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more