---
eip: 8017
label: ERC-8017
title: Payout Race
status: Draft
type: Standards Track
category: ERC
created: 2025-08-31
requires: 20
official: https://eips.ethereum.org/EIPS/eip-8017
source: https://github.com/ethereum/ERCs/blob/master/ERCS/erc-8017.md
canonical: https://eips.huatuo.xyz/zh/eip-8017/
lang: zh
tldr: “支付竞赛”最小接口的草案：合约累积一种资产，并把全部余额交给第一个用另一种资产支付固定价格的调用者，适用于收入回购等场景。
tags: [defi, auction, buyback, erc20, erc]
---

# ERC-8017: Payout Race

> Minimal ERC for a single-asset payout bucket that vends its entire balance for a fixed payment amount.

**TL;DR:** “支付竞赛”最小接口的草案：合约累积一种资产，并把全部余额交给第一个用另一种资产支付固定价格的调用者，适用于收入回购等场景。

## 它解决什么问题？

协议常常需要把持续的收入（手续费、营收）不断兑换成另一种资产：回购自己的代币、建立储备、资助激励。通过 AMM 来做会面临滑点、池子流动性和手续费；运行连续的链上拍卖则复杂且耗费大量 gas。

ERC-8017 受 Uniswap Foundation 的 Unistaker 提案启发，标准化了一个更简单的原语。价值流入一个**桶（bucket）**。任何人都可以支付固定的**所需付款**来取走**整个**桶。随着桶越来越满，购买最终会变得有利可图，于是搜索者争相抢先，这在一定程度上类似荷兰式拍卖。

## 它如何运作

每个合约配置如下：

- `payoutAsset`：桶里装的资产（`address(0)` 表示 ETH，否则为某个 ERC-20）；
- `desiredAsset`：买家支付的资产（`address(0)` 表示 ETH，否则为某个 ERC-20）；
- `requiredPayment`：固定价格，管理员可调整；
- `paymentSink`：付款的去向（金库、分账合约、销毁）。

规则：

1. 支付资产和期望资产**不能同时是 ETH**，并且初始化之后两者都不能更改。
2. `purchase(to)` 在**入口处**读取支付资产余额，余额为零则回滚，收取恰好 `requiredPayment` 的款项（ETH 为 `msg.value`，ERC-20 为 `transferFrom(msg.sender, paymentSink, requiredPayment)`），然后把所捕获的全部余额发送给 `to`，并触发 `Purchased`。
3. `requiredPayment` 和 `paymentSink` 的管理员 setter 必须有访问控制，并触发 `PaymentConfigUpdated`。

可选的扩展：使用 [ERC-2612](/eip-2612/) 的 `purchaseWithPermit`，以及针对支付资产之外其他资产的管理员 `rescue`。

## 示例代码

搜索者先检查某场竞赛是否值得赢下，然后购买（ethers v6）：

```ts
import { Contract, ZeroAddress } from "ethers";

const race = new Contract(RACE, [
  "function payoutAsset() view returns (address)",
  "function desiredAsset() view returns (address)",
  "function requiredPayment() view returns (uint256)",
  "function purchase(address to) payable returns (uint256)",
], signer);

const [payout, desired, price] = await Promise.all([
  race.payoutAsset(), race.desiredAsset(), race.requiredPayment(),
]);
const bucket = payout === ZeroAddress
  ? await provider.getBalance(RACE)
  : await new Contract(payout, ["function balanceOf(address) view returns (uint256)"], provider)
      .balanceOf(RACE);

if (isProfitable(bucket, price)) {            // your own pricing logic
  if (desired === ZeroAddress) {
    await race.purchase(myAddress, { value: price });
  } else {
    // approve `price` of `desired` to RACE first (or use a permit helper)
    await race.purchase(myAddress);
  }
}
```

## 需要注意

- **状态：Draft。**
- 在价值细水长流地流入时效果最好。一次性的大额存入可能把桶推到远高于价格的水平，并把盈余交给第一个购买的人。如果支付资产相对于购买所用资产升值，购买可能会停滞。
- 修改 `requiredPayment` 有风险：调低会让搜索者立刻捡到便宜，调高则可能让机器人被搁浅。规范建议使用时间锁、公告窗口、冷却期或基于 TWAP 的调整。
- 以支付资产形式发送到合约的任何东西，包括未经请求的转账，都会随下一次支付一并发出。
- 买家在 mempool 中竞争，因此会有 MEV 竞争。接口中没有滑点参数；买家无法指定最低支付金额。
- 访问控制未做规定；参考实现使用了 [EIP-173](/eip-173/) 所有权。规范的参考合约有一处小的命名笔误（`receive` 中的 `payoutToken`），不应原样部署。


---

This is an unofficial plain-language summary. Read the full specification: https://eips.ethereum.org/EIPS/eip-8017
