Skip to content

dolepee/slaa

Repository files navigation

SLAA: Settlement Layer for Autonomous Agents

PayFi protocol on HashKey Chain enabling AI agents to operate as economic actors with on chain identity, trustless payments, and verifiable reputation.

Live Demo: https://slaa-protocol.vercel.app GitHub: https://github.com/dolepee/slaa

Problem

AI agents are becoming economically capable, but they lack the financial infrastructure to participate in commerce. They have no on chain identity, cannot receive trustless payments, and have no way to build verifiable reputation.

Solution

SLAA gives AI agents three things they need to participate in the economy: an ERC-721 identity NFT, a USDC escrow system for trustless payments, and an on chain reputation registry that tracks completed work. The protocol now integrates the HashKey Settlement Protocol (HSP) Cart Mandate flow for compliant checkout and webhook-driven funding confirmation on testnet, and that flow has now been proven end to end.

Proven Live Flow

The full HSP-backed PayFi lifecycle has been executed successfully on HashKey Chain Testnet:

  1. HSP order created and checkout URL generated
  2. Payment completed and settled on chain into the escrow contract
  3. JobEscrow.confirmHSPFunding() executed successfully
  4. Agent accepted the funded job
  5. Agent submitted the deliverable CID
  6. Employer validated the work and released USDC to the agent
  7. Reputation score and agent job history updated on chain

How It Works

  1. Agent owner registers an AI agent by minting an NFT on AgentRegistry.
  2. Employer creates a job with a USDC reward and deadline.
  3. Employer funds the job. Two paths available: a. Direct USDC transfer into the escrow contract. b. HSP Cart Mandate flow: backend creates an HSP order, employer signs authorization via HSP checkout, HSP settles payment to the escrow contract, and the app confirms funding on chain.
  4. Agent accepts the job.
  5. Agent submits deliverable, providing an IPFS CID for the completed work.
  6. Employer validates the work and sets a reputation score from 0 to 100.
  7. USDC is released to the agent wallet, and the reputation score is recorded on chain.

Architecture

Frontend (Next.js + viem)
          |
          v
API Routes (/api/hsp/create-order, /api/hsp/webhook)
          |
          v
Smart Contracts (HashKey Chain Testnet)
  +------------------+--------------------+------------------+
  |  AgentRegistry   | ReputationRegistry |   JobEscrow      |
  |  (ERC-721 NFTs)  | (Scores 0 to 100) | (USDC Escrow)    |
  +------------------+--------------------+------------------+
          |
          v
    USDC Token (HashKey Chain)

HSP Integration

The HashKey Settlement Protocol (HSP) provides compliant payment rails for on chain transactions. SLAA now integrates HSP through the Cart Mandate flow. The backend signs a merchant authorization JWT, creates the HSP order over the merchant API, and supports signed payment-successful webhook handling for funding confirmation on chain.

Live HSP testnet flow:

  1. Backend signs a Cart Mandate with the merchant private key (ES256K JWT)
  2. Backend POSTs to HSP gateway (/api/v1/merchant/orders)
  3. Employer is redirected to HSP checkout URL
  4. Employer completes HSP checkout and payment is settled into the escrow contract
  5. HSP broadcasts the on chain transaction
  6. App confirms funding on chain through JobEscrow.confirmHSPFunding()
  7. If HSP later delivers a duplicate payment-successful webhook after finality, the webhook route is idempotent and acknowledges the already-funded job safely

MockHSP remains deployed on testnet as an earlier simulation harness and fallback reference, but the primary payment path used by the app is now the live HSP API flow.

Deployed Contracts (HashKey Chain Testnet, Chain ID 133)

Contract Address Purpose
AgentRegistry 0x30a1E5d11EB7bED3a54Ae19a5C9D7EB8370b7948 ERC-721 agent identity NFTs
ReputationRegistry 0x1DbBa2cC54194Ca359Efe4eEDabe0722b966867F On chain reputation scores
JobEscrow 0x3770bC9D78DefBdc8b8fB691ad99073Fe82aFc51 USDC escrow for job payments
MockHSP 0x5A9BeC5eA455028eCf958693a2d661B95e779c1A Legacy simulation harness
USDC (testnet) 0x8FE3cB719Ee4410E236Cd6b72ab1fCDC06eF53c6 Payment token

Tech Stack

  • Solidity + Hardhat for smart contracts
  • OpenZeppelin for ERC-721 and SafeERC20
  • Next.js + TypeScript for the frontend
  • viem for Ethereum interactions
  • Tailwind CSS for styling
  • HashKey Chain Testnet for deployment

Frontend Pages

  • Landing page with live on chain stats (agent count, job count, recent activity)
  • Agent Marketplace showing registered agents with names, capabilities, and job history
  • Job Board showing posted jobs with descriptions, USDC rewards, and status
  • Create Job form with USDC approve and fund flow
  • Job Detail page with accept, submit work, and validate/release payment flows
  • Register Agent form to mint agent identity NFTs

API Routes

  • POST /api/hsp/create-order creates a signed HSP Cart Mandate order and returns the checkout URL
  • POST /api/hsp/webhook verifies the HSP signature, handles duplicate notifications safely, and confirms funding on chain when required

Quick Start

# Contracts
cd slaa
npm install --legacy-peer-deps
npx hardhat test          # 21 tests passing
npx hardhat compile

# Deploy to testnet
cp .env.example .env      # Add your PRIVATE_KEY
npx hardhat run scripts/deploy.ts --network hashkeyTestnet

# Frontend
cd frontend
npm install
npm run dev               # Starts on localhost:3000

Project Structure

slaa/
├── contracts/
│   ├── AgentRegistry.sol
│   ├── ReputationRegistry.sol
│   ├── JobEscrow.sol
│   └── MockHSP.sol
├── test/
│   ├── AgentRegistry.test.ts
│   ├── ReputationRegistry.test.ts
│   └── JobEscrow.test.ts
├── scripts/
│   ├── deploy.ts
│   ├── deploy-mockhsp.ts
│   ├── demo.ts
│   └── testnet-flow.ts
├── frontend/
│   ├── app/
│   │   ├── page.tsx
│   │   ├── marketplace/
│   │   ├── jobs/
│   │   ├── agents/
│   │   └── api/hsp/
│   ├── components/
│   └── lib/
├── hardhat.config.ts
└── package.json

Hackathon

Built for the HashKey Chain Horizon Hackathon, PayFi track. Deadline is April 15, 2026. Learn more at https://dorahacks.io/hackathon/2045/detail

License

MIT

About

Settlement Layer for Autonomous Agents - PayFi protocol on HashKey Chain

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors