Skip to main content

EscrowSdk

Struct EscrowSdk 

Source
pub struct EscrowSdk;
Expand description

SDK for interacting with the Escrow program

Implementations§

Source§

impl EscrowSdk

Source

pub fn program_id() -> Pubkey

Get the program ID

Source

pub fn bank_pda() -> (Pubkey, u8)

Get the bank PDA

Source

pub fn authority_transfer_pda(bank: Pubkey) -> (Pubkey, u8)

Get the authority transfer PDA

Source

pub fn config_pda() -> (Pubkey, u8)

Get the config PDA

Source

pub fn escrow_pda(mint: Pubkey) -> (Pubkey, u8)

Get an escrow PDA for a specific mint

Source

pub fn payment_pda(payment_uid: &str, bank: Pubkey) -> (Pubkey, u8)

Get a payment PDA for a specific payment UID

Source

pub fn sol_storage_pda( mint: Pubkey, bank: Pubkey, escrow: Pubkey, ) -> (Pubkey, u8)

Get a SOL storage PDA for a specific escrow

Source

pub fn associated_token_account(wallet: Pubkey, mint: Pubkey) -> Pubkey

Get the associated token account for a wallet and mint

Source

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.

Source

pub fn escrow_token_account(mint: Pubkey) -> Pubkey

Get the associated token account for an escrow

Source

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.

Source

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.

Source

pub fn initialize(signer: Pubkey, fee_bps: Option<u16>) -> Instruction

Create an initialize instruction

Source

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)

Source

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.

Source

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

Source

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.

Source

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

Source

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.

Source

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

Source

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.

Source

pub fn submit_delivery( caller: Pubkey, mint: Pubkey, payment_uid: &str, delivery_hash: [u8; 32], ) -> Instruction

Create a submit delivery instruction

Source

pub fn close_payment( caller: Pubkey, buyer: Pubkey, mint: Pubkey, payment_uid: &str, ) -> Instruction

Create a close payment instruction

Source

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

Source

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.

Source

pub fn extend_payment_ttl( caller: Pubkey, mint: Pubkey, payment_uid: &str, additional_seconds: i64, ) -> Instruction

Create an extend payment TTL instruction

Source

pub fn close_escrow( authority: Pubkey, recipient: Pubkey, mint: Pubkey, ) -> Instruction

Create a close escrow instruction

Source

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.

Source

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

Source

pub fn pause_escrow(authority: Pubkey, mint: Pubkey, pause: bool) -> Instruction

Create a pause escrow instruction

Source

pub fn update_authority( current_authority: Pubkey, new_authority: Pubkey, ) -> Instruction

Create an update authority instruction (Step 1: Propose)

Source

pub fn accept_authority(new_authority: Pubkey) -> Instruction

Create an accept authority instruction (Step 2: Accept)

Source

pub fn cancel_authority_proposal(current_authority: Pubkey) -> Instruction

Create a cancel authority proposal instruction

Source

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.

Source

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.

Source

pub fn validate_payment_for_funding( payment: &Payment, ) -> Result<(), EscrowError>

Validate that a payment is in the correct state for funding

Source

pub fn validate_payment_for_release( payment: &Payment, ) -> Result<(), EscrowError>

Validate that a payment is in the correct state for release

Source

pub fn validate_payment_for_refund(payment: &Payment) -> Result<(), EscrowError>

Validate that a payment is in the correct state for refund

Source

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

Source

pub fn calculate_payout(amount: u64, fee_bps: u16, min_fee_amount: u64) -> u64

Calculate payout amount after deducting fees

Source

pub fn is_payment_expired(payment: &Payment) -> bool

Check if a payment has expired

Source

pub fn get_payment_state_string(state: u8) -> &'static str

Get payment state as string

Source

pub fn get_escrow_state_string(paused: u8) -> &'static str

Get escrow state as string

Source

pub fn get_payment_accounts( buyer: Pubkey, seller: Pubkey, mint: Pubkey, payment_uid: &str, ) -> PaymentAccounts

Get all required accounts for a payment operation

Source

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.

Source

pub fn get_escrow_accounts(mint: Pubkey) -> EscrowAccounts

Get all required accounts for an escrow operation

Source

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§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Az for T

Source§

fn az<Dst>(self) -> Dst
where T: Cast<Dst>,

Casts the value.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<Src, Dst> CastFrom<Src> for Dst
where Src: Cast<Dst>,

Source§

fn cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> CheckedAs for T

Source§

fn checked_as<Dst>(self) -> Option<Dst>
where T: CheckedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> CheckedCastFrom<Src> for Dst
where Src: CheckedCast<Dst>,

Source§

fn checked_cast_from(src: Src) -> Option<Dst>

Casts the value.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<Src, Dst> LosslessTryInto<Dst> for Src
where Dst: LosslessTryFrom<Src>,

Source§

fn lossless_try_into(self) -> Option<Dst>

Performs the conversion.
Source§

impl<Src, Dst> LossyInto<Dst> for Src
where Dst: LossyFrom<Src>,

Source§

fn lossy_into(self) -> Dst

Performs the conversion.
Source§

impl<T> OverflowingAs for T

Source§

fn overflowing_as<Dst>(self) -> (Dst, bool)
where T: OverflowingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> OverflowingCastFrom<Src> for Dst
where Src: OverflowingCast<Dst>,

Source§

fn overflowing_cast_from(src: Src) -> (Dst, bool)

Casts the value.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> SaturatingAs for T

Source§

fn saturating_as<Dst>(self) -> Dst
where T: SaturatingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> SaturatingCastFrom<Src> for Dst
where Src: SaturatingCast<Dst>,

Source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> UnwrappedAs for T

Source§

fn unwrapped_as<Dst>(self) -> Dst
where T: UnwrappedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> UnwrappedCastFrom<Src> for Dst
where Src: UnwrappedCast<Dst>,

Source§

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WrappingAs for T

Source§

fn wrapping_as<Dst>(self) -> Dst
where T: WrappingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> WrappingCastFrom<Src> for Dst
where Src: WrappingCast<Dst>,

Source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.