sla-escrow-api 0.2.7

SLA-Escrow: Service Level Agreement Enforcer for AI Agents
Documentation
# sla-escrow-api

**Trustless Service Level Agreement (SLA) Enforcer for AI Agents on Solana.**

`sla-escrow-api` is the official Rust SDK for the SLA-Escrow program. It provides the cryptographic and logic foundation for **Settle-then-Work** or **Escrow-then-Work** payment protocols in the autonomous agent economy.

[Crates.io](https://crates.io/crates/sla-escrow-api)
[License](LICENSE)

---

## 🏗️ Architecture

SLA-Escrow acts as a non-custodial judge that locks funds in a Program Derived Address (PDA) until a predefined condition (the SLA) is met. This crate is designed for **AI Resource Providers** and **Oracles** who need high-fidelity payment auditing.

Key participants:

- **Buyer**: An agent requesting a service (locks funds in escrow).
- **Seller**: An agent providing the service.
- **Oracle**: A third party that confirms fulfillment by validating that a `delivery_hash` (proof of work) correctly satisfies a previously agreed upon `sla_hash` (the requirement).

## 🚀 Key SDK Features

### 📐 Profit Protection Logic

Calculating gross fees manually is prone to error. This SDK provides a single, high-level function to calculate exactly what you should charge your buyers to maintain a fixed profit margin after all on-chain fees are deducted:

```rust
use sla_escrow_api::sdk::EscrowSdk;

// Example: I want exactly $1.00 net payout in my wallet.
let desired_net = 1_000_000; // 1.00 USDC (6 decimals)
let gross_quote = EscrowSdk::calculate_gross_quote(
    desired_net,
    100, // Protocol fee (100 bps)
    10_000, // Min protocol fee
    50, // Oracle tip (50 bps)
);
// This returns the exact amount (e.g. 1_015_000) you must charge the buyer.
```

### 🔐 Instruction Builders

The `EscrowSdk` simplifies building complex instructions for the Solana network:

```rust
use sla_escrow_api::sdk::EscrowSdk;

// Build a fund_payment instruction
let ix = EscrowSdk::fund_payment(
    buyer_pubkey,
    None, // None for Native SOL
    seller_pubkey,
    solana_program::pubkey::Pubkey::default(), // Track Native SOL
    amount,
    300, // 5 minute TTL (Time-To-Live)
    payment_uid,
    sla_hash, // The SHA-256 hash of the work agreement
    oracle_authority
);
```

## 🛠️ Components

- **Account Derivation**: PDA helpers for `Bank`, `Escrow`, `Payment`, and `SOL Storage`.
- **Validation**: State machine checks to ensure payments aren't released prematurely.
- **Calculation Utilities**: Robust decimal arithmetic for fee and payout balancing.

## ⚖️ License

Licensed under the Apache License, Version 2.0.