sla-escrow-api 0.2.6

SLA-Escrow: Service Level Agreement Enforcer for AI Agents
Documentation
mod bank;
mod config;
mod escrow;
mod payment;

pub use bank::*;
pub use config::*;
pub use escrow::*;
pub use payment::*;

use steel::*;

use crate::consts::*;

#[repr(u8)]
#[derive(Clone, Copy, Debug, Eq, PartialEq, IntoPrimitive, TryFromPrimitive)]
pub enum EscrowAccount {
    Bank = 100,
    Config = 101,
    Escrow = 102,
    Payment = 103,
}

/// Derive the PDA of the bank account.
pub fn bank_pda() -> (Pubkey, u8) {
    Pubkey::find_program_address(&[BANK], &crate::id())
}

/// Derive the PDA of the config account.
pub fn config_pda() -> (Pubkey, u8) {
    Pubkey::find_program_address(&[CONFIG], &crate::id())
}

/// Derive the PDA of an escrow account.
pub fn escrow_pda(mint: Pubkey, bank: Pubkey) -> (Pubkey, u8) {
    Pubkey::find_program_address(&[ESCROW, mint.as_ref(), bank.as_ref()], &crate::id())
}

/// Derive the PDA of a payment account.
pub fn payment_pda(payment_uid: &str, bank: Pubkey) -> (Pubkey, u8) {
    // Convert UUID string to bytes, remove dashes, pad to 32 bytes
    let mut uid_bytes = [0u8; 32];
    let uid_str = payment_uid.replace('-', ""); // Remove UUID dashes
    let uid_bytes_str = uid_str.as_bytes();
    let len = uid_bytes_str.len().min(32);
    uid_bytes[..len].copy_from_slice(&uid_bytes_str[..len]);

    Pubkey::find_program_address(&[PAYMENT, &uid_bytes, bank.as_ref()], &crate::id())
}

/// Derive the PDA of a SOL storage account.
/// This account holds SOL for escrows and can be used for transfers (no data, just lamports).
pub fn sol_storage_pda(mint: Pubkey, bank: Pubkey, escrow: Pubkey) -> (Pubkey, u8) {
    Pubkey::find_program_address(
        &[SOL_STORAGE, mint.as_ref(), bank.as_ref(), escrow.as_ref()],
        &crate::id(),
    )
}