sla-escrow-api 0.3.0

SLA-Escrow: Service Level Agreement Enforcer for AI Agents
Documentation
use steel::*;

// Core Payment Events
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
pub struct PaymentCreatedWithFundEvent {
    pub payment_uid: [u8; 32],    // 32 bytes
    pub sla_hash: [u8; 32],       // 32 bytes
    pub escrow: Pubkey,           // 32 bytes
    pub buyer: Pubkey,            // 32 bytes
    pub seller: Pubkey,           // 32 bytes
    pub mint: Pubkey,             // 32 bytes
    pub oracle_authority: Pubkey, // 32 bytes
    pub amount: u64,              // 8 bytes
    pub expires_at: i64,          // 8 bytes
    pub timestamp: i64,           // 8 bytes
    pub state: u8,                // 1 byte
    pub _padding: [u8; 7],        // 7 bytes padding
}

#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
pub struct DeliverySubmittedEvent {
    pub payment_uid: [u8; 32],   // 32 bytes
    pub delivery_hash: [u8; 32], // 32 bytes
    pub timestamp: i64,          // 8 bytes
    pub seller: Pubkey,          // 32 bytes
}

#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
pub struct PaymentOracleConfirmedEvent {
    pub payment_uid: [u8; 32],     // 32 bytes - payment unique identifier
    pub oracle_authority: Pubkey,  // 32 bytes - oracle authority
    pub delivery_hash: [u8; 32],   // 32 bytes
    pub resolution_hash: [u8; 32], // 32 bytes - oracle's attestation digest (audit trail)
    pub sla_hash: [u8; 32],        // 32 bytes - SLA requirements hash (saves indexer cross-ref)
    pub amount: u64,               // 8 bytes - escrowed amount (for oracle dashboards/reputation)
    pub timestamp: i64,            // 8 bytes

    pub resolution_reason: u16, // 2 bytes - reason code (see ResolutionReason enum)
    pub resolution_state: u8,   // 1 byte
    pub _padding: [u8; 5],      // 5 bytes padding
}

#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
pub struct PaymentFundedEvent {
    pub payment_uid: [u8; 32], // 32 bytes - payment unique identifier
    pub mint: Pubkey,          // 32 bytes
    pub amount: u64,           // 8 bytes
    pub timestamp: i64,        // 8 bytes
    pub buyer: Pubkey,         // 32 bytes
}

#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
pub struct PaymentReleasedEvent {
    pub payment_uid: [u8; 32], // 32 bytes - payment unique identifier
    pub mint: Pubkey,          // 32 bytes
    pub amount: u64,           // 8 bytes
    pub oracle_tip: u64,       // 8 bytes — tip paid to oracle (0 if none)
    pub timestamp: i64,        // 8 bytes
    pub seller: Pubkey,        // 32 bytes
    pub is_expired: u8,        // 1 byte - 1 if expired, 0 if manual release
    pub _padding: [u8; 7],     // 7 bytes padding
}

#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
pub struct PaymentRefundedEvent {
    pub payment_uid: [u8; 32], // 32 bytes - payment unique identifier
    pub mint: Pubkey,          // 32 bytes
    pub amount: u64,           // 8 bytes
    pub oracle_tip: u64,       // 8 bytes — tip deducted from refund (0 if none)
    pub timestamp: i64,        // 8 bytes
    pub buyer: Pubkey,         // 32 bytes
}

#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
pub struct PaymentExpiredEvent {
    pub payment_uid: [u8; 32], // 32 bytes - payment unique identifier
    pub mint: Pubkey,          // 32 bytes
    pub amount: u64,           // 8 bytes
    pub timestamp: i64,        // 8 bytes
    pub buyer: Pubkey,         // 32 bytes
    pub seller: Pubkey,        // 32 bytes
}

#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
pub struct PaymentClosedEvent {
    pub payment_uid: [u8; 32], // 32 bytes - payment unique identifier
    pub timestamp: i64,        // 8 bytes
    pub closer: Pubkey,        // 32 bytes
}

// Payment Management Events
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
pub struct PaymentTTLExtendedEvent {
    pub payment_uid: [u8; 32],   // 32 bytes - payment unique identifier
    pub additional_seconds: i64, // 8 bytes
    pub new_expires_at: i64,     // 8 bytes
    pub timestamp: i64,          // 8 bytes
    pub buyer: Pubkey,           // 32 bytes
}

// Escrow Management Events
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
pub struct EscrowCreatedEvent {
    pub timestamp: i64,          // 8 bytes
    pub escrow: Pubkey,          // 32 bytes
    pub mint: Pubkey,            // 32 bytes
    pub authority: Pubkey,       // 32 bytes
    pub min_payment_amount: u64, // 8 bytes
    pub max_payment_amount: u64, // 8 bytes
    pub fee_bps: u16,            // 2 bytes
    pub paused: u8,              // 1 byte
    // Total: 8+32+32+32+8+8+2+1 = 123 bytes, need 5 bytes padding for 128-byte alignment
    pub _padding: [u8; 5], // 5 bytes padding
}

#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
pub struct EscrowClosedEvent {
    pub timestamp: i64, // 8 bytes
    pub escrow: Pubkey, // 32 bytes
    pub mint: Pubkey,   // 32 bytes
    pub authority: Pubkey, // 32 bytes
                        // Total: 8+32+32+32 = 104 bytes (already 8-byte aligned)
}

#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
pub struct EscrowSettingsUpdatedEvent {
    pub escrow: Pubkey,          // 32 bytes
    pub mint: Pubkey,            // 32 bytes
    pub authority: Pubkey,       // 32 bytes
    pub min_payment_amount: u64, // 8 bytes
    pub max_payment_amount: u64, // 8 bytes
    pub min_fee_amount: u64,     // 8 bytes
    pub timestamp: i64,          // 8 bytes
    pub new_fee_bps: u16,        // 2 bytes
    // Total: 32+32+32+8+8+8+8+2 = 130 bytes, need 6 bytes padding for 136-byte alignment
    pub _padding: [u8; 6], // 6 bytes padding
}

#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
pub struct EscrowPausedEvent {
    pub escrow: Pubkey,    // 32 bytes
    pub mint: Pubkey,      // 32 bytes
    pub authority: Pubkey, // 32 bytes
    pub timestamp: i64,    // 8 bytes
    pub paused: u8,        // 1 byte
    // Total: 32+32+32+8+1 = 105 bytes, need 7 bytes padding for 112-byte alignment
    pub _padding: [u8; 7], // 7 bytes padding
}

// Bank Management Events
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
pub struct BankInitializedEvent {
    pub timestamp: i64,    // 8 bytes
    pub bank: Pubkey,      // 32 bytes
    pub authority: Pubkey, // 32 bytes
    pub fee_bps: u16,      // 2 bytes
    // Total: 8+32+32+2 = 74 bytes, need 6 bytes padding for 80-byte alignment
    pub _padding: [u8; 6], // 6 bytes padding
}

#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
pub struct AuthorityUpdatedEvent {
    pub timestamp: i64,        // 8 bytes
    pub bank: Pubkey,          // 32 bytes
    pub old_authority: Pubkey, // 32 bytes
    pub new_authority: Pubkey, // 32 bytes
                               // Total: 8+32+32+32 = 104 bytes (already 8-byte aligned)
}

#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
pub struct FeesWithdrawnEvent {
    pub timestamp: i64, // 8 bytes
    pub amount: u64,    // 8 bytes
    pub escrow: Pubkey, // 32 bytes
    pub mint: Pubkey,   // 32 bytes
    pub authority: Pubkey, // 32 bytes
                        // Total: 8+8+32+32+32 = 112 bytes (already 8-byte aligned)
}

#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
pub struct ConfigUpdatedEvent {
    pub timestamp: i64,               // 8 bytes
    pub authority: Pubkey,            // 32 bytes
    pub closure_delay_seconds: i64,   // 8 bytes
    pub refund_cooldown_seconds: i64, // 8 bytes
    pub delivery_cutoff_seconds: i64, // 8 bytes
                                      // Total: 8+32+8+8+8 = 64 bytes (already 8-byte aligned)
}

#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
pub struct AuthorityProposedEvent {
    pub timestamp: i64,            // 8 bytes
    pub bank: Pubkey,              // 32 bytes
    pub current_authority: Pubkey, // 32 bytes
    pub proposed_authority: Pubkey, // 32 bytes
                                   // Total: 8+32+32+32 = 104 bytes (8-byte aligned)
}

#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
pub struct AuthorityProposalCancelledEvent {
    pub timestamp: i64,              // 8 bytes
    pub bank: Pubkey,                // 32 bytes
    pub cancelled_authority: Pubkey, // 32 bytes
    pub cancelled_by: Pubkey,        // 32 bytes
                                     // Total: 8+32+32+32 = 104 bytes (8-byte aligned)
}

// Event Macros
event!(PaymentCreatedWithFundEvent);
event!(PaymentOracleConfirmedEvent);
event!(PaymentFundedEvent);
event!(PaymentReleasedEvent);
event!(PaymentRefundedEvent);
event!(PaymentExpiredEvent);
event!(PaymentClosedEvent);
event!(PaymentTTLExtendedEvent);
event!(EscrowCreatedEvent);
event!(EscrowClosedEvent);
event!(EscrowSettingsUpdatedEvent);
event!(EscrowPausedEvent);
event!(BankInitializedEvent);
event!(AuthorityUpdatedEvent);
event!(FeesWithdrawnEvent);
event!(DeliverySubmittedEvent);
event!(ConfigUpdatedEvent);
event!(AuthorityProposedEvent);
event!(AuthorityProposalCancelledEvent);