|
1 | | -## Foundry |
| 1 | +# Xcrow Protocol |
2 | 2 |
|
3 | | -**Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.** |
| 3 | +Xcrow is a USDC escrow and payment settlement protocol for the AI agent economy, built on the Arc Network. It provides trustless job creation, execution tracking, and payment release between clients and AI agents, with native integration into Arc's ERC-8004 identity and reputation standard. |
4 | 4 |
|
5 | | -Foundry consists of: |
| 5 | +--- |
6 | 6 |
|
7 | | -- **Forge**: Ethereum testing framework (like Truffle, Hardhat and DappTools). |
8 | | -- **Cast**: Swiss army knife for interacting with EVM smart contracts, sending transactions and getting chain data. |
9 | | -- **Anvil**: Local Ethereum node, akin to Ganache, Hardhat Network. |
10 | | -- **Chisel**: Fast, utilitarian, and verbose solidity REPL. |
| 7 | +## Overview |
11 | 8 |
|
12 | | -## Documentation |
| 9 | +When a client hires an AI agent, Xcrow locks the agreed USDC amount in escrow at the moment of hire. Funds remain locked until the agent completes the job and the client releases payment. If either party acts in bad faith, the protocol enforces cancellation, dispute resolution, or expiry refunds without requiring a trusted intermediary. |
13 | 10 |
|
14 | | -https://book.getfoundry.sh/ |
| 11 | +Xcrow also writes proof-of-payment feedback directly to the ERC-8004 Reputation Registry on every settled job, building a tamper-proof on-chain track record for each agent over time. |
15 | 12 |
|
16 | | -## Usage |
| 13 | +--- |
17 | 14 |
|
18 | | -### Build |
| 15 | +## Architecture |
| 16 | + |
| 17 | +The protocol is composed of four core contracts and a shared type library. |
| 18 | + |
| 19 | +### XcrowEscrow |
| 20 | + |
| 21 | +The escrow vault. Holds USDC for the duration of a job and enforces the job lifecycle state machine. Supports both ERC-8004 identity-based hiring and direct wallet-based hiring. |
| 22 | + |
| 23 | +Job lifecycle: |
19 | 24 |
|
20 | | -```shell |
21 | | -$ forge build |
| 25 | +``` |
| 26 | +Created -> Accepted -> InProgress -> Completed -> Settled |
| 27 | + -> Disputed -> Resolved |
| 28 | + -> Cancelled (pre-acceptance) |
| 29 | + -> Expired (deadline passed) |
| 30 | + -> Refunded (dispute resolved in client's favor) |
22 | 31 | ``` |
23 | 32 |
|
24 | | -### Test |
| 33 | +Key mappings: |
| 34 | +- `clientJobs` — all jobs created by a client address |
| 35 | +- `agentJobs` — all jobs assigned to an ERC-8004 agent ID |
| 36 | +- `agentWalletJobs` — all jobs assigned to an agent wallet address (wallet-based hiring) |
| 37 | + |
| 38 | +### XcrowRouter |
| 39 | + |
| 40 | +The single entry point for all client-facing interactions. Orchestrates the escrow, reputation pricer, and cross-chain settler. Stores the `originalClient` mapping to correctly attribute refunds and feedback for jobs routed through it. |
| 41 | + |
| 42 | +Hiring modes supported: |
| 43 | +- `hireAgent` — hire by ERC-8004 agent ID |
| 44 | +- `hireAgentWithPermit` — same as above with EIP-2612 permit (single transaction, no pre-approval) |
| 45 | +- `hireAgentByWalletWithPermit` — hire by agent wallet address directly, no ERC-8004 lookup required |
| 46 | +- `hireAgentWithQuote` — hire at a reputation-weighted price from the pricer |
| 47 | +- `hireAgentCrossChain` — hire with CCTP V2 cross-chain payout |
| 48 | + |
| 49 | +Post-settlement: |
| 50 | +- `settleAndPay` — releases USDC to the agent and auto-submits proof-of-payment to the ERC-8004 Reputation Registry |
| 51 | +- `submitFeedback` — allows the client to submit a star rating and optional review URI after settlement |
| 52 | +- `rejectJobViaRouter` — agent rejects an assigned job; USDC is refunded directly to the original client |
| 53 | +- `cancelJobViaRouter` — client cancels a job before it is accepted; USDC is refunded in full |
| 54 | +- `disputeJobViaRouter` — either party raises a dispute for owner arbitration |
| 55 | + |
| 56 | +### ReputationPricer |
| 57 | + |
| 58 | +Computes reputation-weighted price quotes for agents registered on ERC-8004. Reads aggregated feedback from the Reputation Registry using a configurable set of trusted reviewers to filter out Sybil-manipulated scores. |
| 59 | + |
| 60 | +Pricing model: |
| 61 | +- Agents with no reviews, or fewer than `minReviewCount`, receive a base 1x multiplier |
| 62 | +- Agents with positive reputation receive a premium up to `maxPremiumBps` above base rate |
| 63 | +- Agents with negative reputation receive a penalty, floored at 0.1x to prevent zero-cost exploitation |
| 64 | + |
| 65 | +### CrossChainSettler |
| 66 | + |
| 67 | +Handles cross-chain USDC payouts via Circle's CCTP V2. When a job is settled cross-chain, the escrow releases funds to this contract, which burns USDC on Arc and instructs Circle to mint the equivalent on the destination chain directly to the agent's wallet. |
| 68 | + |
| 69 | +Supported destination domains: Ethereum, Arbitrum, Base. |
| 70 | + |
| 71 | +--- |
| 72 | + |
| 73 | +## ERC-8004 Integration |
| 74 | + |
| 75 | +Xcrow is built around Arc's ERC-8004 standard for AI agent identity and reputation. |
| 76 | + |
| 77 | +- **Identity Registry** (`0x8004A818BFB912233c491871b3d84c89A494BD9e`) — used to resolve agent wallet addresses from ERC-8004 token IDs and verify agent ownership |
| 78 | +- **Reputation Registry** (`0x8004B663056A597Dffe9eCcC1965A193B7388713`) — receives proof-of-payment feedback on every settled job via `giveFeedback`, and star ratings submitted by clients via `submitFeedback` |
| 79 | + |
| 80 | +Every job settled through the router contributes to the agent's on-chain reputation, which in turn affects their pricing multiplier through the ReputationPricer. |
| 81 | + |
| 82 | +--- |
| 83 | + |
| 84 | +## Deployed Contracts — Arc Testnet |
| 85 | + |
| 86 | +| Contract | Address | |
| 87 | +|---|---| |
| 88 | +| XcrowEscrow | `0x9D157b6fa143a5778c017FB233ee972387Ac1aE3` | |
| 89 | +| XcrowRouter | `0x81c3F812454B25D9696a66541788996532f89278` | |
| 90 | +| ReputationPricer | `0x9FD2686839350350272cA7717BFaE6409C0563c1` | |
| 91 | +| CrossChainSettler | `0xA3f6CB47D43Fc92c33b75DaE6cd5FfaC5950cEB0` | |
| 92 | +| ERC-8004 Identity | `0x8004A818BFB912233c491871b3d84c89A494BD9e` | |
| 93 | +| ERC-8004 Reputation | `0x8004B663056A597Dffe9eCcC1965A193B7388713` | |
| 94 | +| USDC | `0x3600000000000000000000000000000000000000` | |
| 95 | + |
| 96 | +Chain ID: `5042002` |
| 97 | + |
| 98 | +--- |
| 99 | + |
| 100 | +## Development |
| 101 | + |
| 102 | +### Prerequisites |
| 103 | + |
| 104 | +- [Foundry](https://book.getfoundry.sh/getting-started/installation) |
| 105 | + |
| 106 | +### Setup |
25 | 107 |
|
26 | 108 | ```shell |
27 | | -$ forge test |
| 109 | +git clone https://github.com/your-org/xcrow |
| 110 | +cd xcrow |
| 111 | +forge install |
28 | 112 | ``` |
29 | 113 |
|
30 | | -### Format |
| 114 | +Create a `.env` file: |
31 | 115 |
|
32 | | -```shell |
33 | | -$ forge fmt |
| 116 | +``` |
| 117 | +PRIVATE_KEY=your_deployer_private_key |
| 118 | +ARC_RPC_URL=https://rpc.testnet.arc.network |
34 | 119 | ``` |
35 | 120 |
|
36 | | -### Gas Snapshots |
| 121 | +### Build |
37 | 122 |
|
38 | 123 | ```shell |
39 | | -$ forge snapshot |
| 124 | +forge build |
40 | 125 | ``` |
41 | 126 |
|
42 | | -### Anvil |
| 127 | +### Test |
43 | 128 |
|
44 | 129 | ```shell |
45 | | -$ anvil |
| 130 | +forge test |
46 | 131 | ``` |
47 | 132 |
|
48 | 133 | ### Deploy |
49 | 134 |
|
50 | 135 | ```shell |
51 | | -$ forge script script/Counter.s.sol:CounterScript --rpc-url <your_rpc_url> --private-key <your_private_key> |
| 136 | +forge script script/Deploy.s.sol --rpc-url https://rpc.testnet.arc.network --broadcast |
52 | 137 | ``` |
53 | 138 |
|
54 | | -### Cast |
| 139 | +--- |
55 | 140 |
|
56 | | -```shell |
57 | | -$ cast <subcommand> |
58 | | -``` |
| 141 | +## Protocol Fees |
59 | 142 |
|
60 | | -### Help |
| 143 | +The protocol charges a configurable fee in basis points on each job, deducted from the escrowed amount at settlement. Fees accumulate in the escrow contract and are withdrawable by the contract owner to a designated treasury address. The default fee is 2.5% (250 bps). The maximum is capped at 10% (1000 bps). |
61 | 144 |
|
62 | | -```shell |
63 | | -$ forge --help |
64 | | -$ anvil --help |
65 | | -$ cast --help |
66 | | -``` |
| 145 | +--- |
| 146 | + |
| 147 | +## Security |
| 148 | + |
| 149 | +- All state-changing functions use `ReentrancyGuard` |
| 150 | +- The escrow and router are `Pausable` for emergency stops |
| 151 | +- Agent acceptance and job completion are gated to the assigned `agentWallet` |
| 152 | +- Refunds on rejection and cancellation are routed through `originalClient` to prevent USDC from being stranded in the router |
| 153 | +- `CrossChainSettler` restricts `settleCrossChain` to authorized callers only |
| 154 | +- Dispute resolution is owner-arbitrated with a configurable timeout for auto-refund |
| 155 | + |
| 156 | +--- |
| 157 | + |
| 158 | +## License |
| 159 | + |
| 160 | +GPL-3.0 |
0 commit comments