结算架构¶
Facilitator 是结算轨道汇聚的地方。 它扩展标准 x402 Facilitator,增加轨道无关路由能力, 让单一商户 API 接受来自任何结算后端的支付。
设计哲学¶
商户永远不知道轨道。 Facilitator 抽象所有轨道复杂性。 无论代理怎么付,都呈现相同接口。
轨道适配器接口¶
Rust
pub trait RailAdapter {
fn kind(&self) -> PaymentRail;
async fn quote(&self, request: &SettlementIntent) -> Result<RailQuote>;
async fn settle(&self, request: &SettlementIntent) -> Result<SettlementReceipt>;
async fn verify(&self, receipt: &SettlementReceipt) -> Result<VerificationResult>;
}
每个轨道适配器实现相同接口。 Facilitator 根据以下因素选适配器:
- 授权令的
allowed_rails约束 - 支付主体类型
- 商户结算偏好
- 当前轨道可用性和费用
支持的轨道¶
链上¶
通过智能合约或原生转账的直接区块链结算。
| 链 | 资产 | 机制 |
|---|---|---|
| 以太坊 / EVM | USDC、USDT、ETH | x402 智能合约或 EIP-3009 |
| Solana | USDC、SOL | SPL 代币转账 |
| Base | USDC | x402 合约部署 |
| Arbitrum | USDC | L2 x402 合约 |
交易所¶
通过交易所内部余额结算,不需要链上交易。
| 交易所 | 机制 | 延迟 |
|---|---|---|
| 币安 | API 内部转账 | 亚秒级 |
| OKX | 子账户转账 | 亚秒级 |
| Bybit | 内部转账 | 亚秒级 |
注意:交易所轨道快是快, 但你得信任交易所不会冻你账户, 这是跟链上结算最大的权衡。
托管¶
通过 Facilitator 管理的托管账本账户结算。
| 提供商 | 机制 | 用例 |
|---|---|---|
| Facilitator 内部 | 账本条目 | 测试、开发 |
| 机构托管人 | API 结算 | 企业 |
传统网关(未来)¶
通过传统支付处理器结算。
| 网关 | 机制 | 用例 |
|---|---|---|
| Stripe | 支付意图 | 信用卡兜底 |
| PayPal | API 支付 | 法币回退 |
结算路由¶
Facilitator 接收:
- 标准 x402 支付要求和负载
- 规范化 LedgerFlow 授权结果
- 解析的支付主体
- 商户结算偏好
它不需要商户理解底层轨道。
路由算法¶
Text Only
1. Extract payment subject from LedgerFlow extension
2. Determine subject kind (Caip10, ExchangeAccount, etc.)
3. Filter available rails by warrant's allowed_rails constraint
4. Filter by merchant's preferred rails
5. Select rail with lowest cost and sufficient liquidity
6. Execute quote and settlement
7. Return normalized x402 settlement result
示例:同一商户,不同轨道¶
Text Only
Merchant: "Pay $5 for this API call"
Agent A (Base wallet):
→ payment_subject: caip10:eip155:8453:0xabc...
→ Rail: Onchain (Base USDC via x402 contract)
Agent B (Binance user):
→ payment_subject: binance:uid:12345678
→ Rail: Exchange (Binance internal transfer)
Agent C (OKX user):
→ payment_subject: okx:subacct:agent-alpha
→ Rail: Exchange (OKX sub-account transfer)
All three: same x402 flow, same merchant code, different rails.
支付主体解析¶
Facilitator 将支付主体解析为具体结算身份:
| 类型 | 解析 | 示例 |
|---|---|---|
Caip10 |
直接链上地址 | Base 上的 0xabc... |
FacilitatorAccount |
内部账本查询 | 账户 ID 42 |
ExchangeAccount |
交易所 API 查询 | 币安 UID 12345678 |
Opaque |
自定义解析 | 提供商特定 |
可扩展性¶
新轨道可以通过实现 RailAdapter trait 添加:
- 在
crates/ledgerflow-facilitator/src/rails/中创建新模块 - 为新轨道实现
RailAdapter - 在 Facilitator 路由表中注册适配器
- 在
PaymentRail枚举中添加轨道
不需要修改 x402、LedgerFlow 核心或商户代码。