Introduction
Hi, I'm cardene, a software engineer and technical writer focused on blockchain and AI.
I've also authored Japanese technical books on specification-driven development with LLMs and decentralized application (DApp) development.
I also build and publish a variety of tools, libraries, and open-source projects.
ERC8017 proposes a mechanism for receiving all assets accumulated in a contract in exchange for a fixed payment.
This article explains the proposal below, which is a draft specification.
I also cover various EIPs, BIPs, SLIPs, CAIPs, ENSIPs, RFCs, and ACPs.
Overview
ERC8017 defines a bucket contract holding one type of payout asset and a purchase() function that dispenses the entire bucket for a fixed payment.
The bucket contains either ETH or a single ERC20 token. Buyers likewise pay in ETH or a single ERC20 token.
However, paying ETH to receive ETH is not permitted.
ERC20 is the standard interface for fungible tokens on Ethereum. In ERC8017, an ERC20 token can be used as either the payout asset or the payment asset.
For more on ERC20, see the following article.
[ERC20] An Introduction to the Fungible Token Standard
This mechanism is useful for converting an ongoing stream of revenue into another asset. Examples include buying back governance tokens with protocol revenue, accumulating reserves, and converting incentive budgets into other assets.
ERC8017 does not attempt to standardize a complete auction mechanism. Its scope is limited to a minimal contract interface that lets callers receive everything currently in the bucket by paying the specified fixed amount. External controllers or searchers decide when the exchange is worthwhile and when to execute it.
The following diagram illustrates the payment and payout flow of purchase().

The buyer pays exactly requiredPayment, which is forwarded to paymentSink.
Within the same transaction, the bucket's entire payoutAsset balance is transferred to to.
The race is won by the first caller to successfully execute purchase() when doing so is economically worthwhile.
Motivation
Protocols often need to convert a continuous stream of value into another asset. Typical examples include buying back a protocol's own token with revenue, increasing reserve holdings, accumulating reward funds, and adjusting treasury asset allocations.
Direct AMM integration makes the outcome dependent on external liquidity, slippage, fees, and pool conditions. Continual operation requires adjustments as pool conditions change. Running a general-purpose on-chain auction continuously, on the other hand, adds configuration complexity and gas costs.
ERC8017 extracts a smaller primitive based on an idea similar to a Dutch auction.
As assets gradually accumulate in the bucket, the deal becomes more attractive to a buyer who pays a fixed amount to receive them all.
External controllers or searchers can therefore monitor the bucket balance and market prices and execute purchase() only when the exchange is economically viable.
Specification
ERC8017 defines the payout asset, payment asset, required payment, payment destination, purchase function, administrative setters, and events. Any implementation claiming compliance, including a proxy or clone, must meet the specification in its externally observable behavior after deployment.
Terminology
| Term | Description |
|---|---|
payoutAsset |
Asset dispensed from the bucket. address(0) denotes ETH |
desiredAsset |
Asset paid by the buyer. address(0) denotes ETH |
requiredPayment |
Fixed amount required for a purchase |
paymentSink |
Destination receiving the buyer's payment |
purchase(address to) |
Function that collects payment and dispenses the entire bucket |
Importantly, neither payoutAsset nor desiredAsset can change after initialization.
Changing either would alter the asset pair itself, invalidating the assumptions of buyers, external controllers, and searchers.
The asset pair and the economic parameters have different mutability requirements.

The payoutAsset and desiredAsset values are fixed because they define the asset pair.
The requiredPayment and paymentSink values are operational economic parameters that only authorized administrators can change.
IPayoutRace
The interface is defined as follows.
interface IPayoutRace {
function payoutAsset() external view returns (address);
function desiredAsset() external view returns (address);
function requiredPayment() external view returns (uint256);
function paymentSink() external view returns (address);
function purchase(address to) external payable returns (uint256 dispensed);
function setRequiredPayment(uint256 amount) external;
function setPaymentSink(address sink) external;
event Purchased(address indexed buyer, address indexed to, uint256 dispensed, uint256 paid);
event PaymentConfigUpdated(address desiredAsset, uint256 requiredPayment, address sink);
}The interface exposes the information needed to make purchases and records the actual amounts paid and dispensed in the Purchased event after a purchase.
When an administrator changes requiredPayment or paymentSink, the contract emits PaymentConfigUpdated.
Functions
payoutAsset()
The payoutAsset() function returns the address of the asset dispensed from the bucket.
A return value of address(0) means that the payout asset is ETH.
function payoutAsset() external view returns (address);| Return value | Description |
|---|---|
address |
Payout asset address. address(0) denotes ETH |
desiredAsset()
The desiredAsset() function returns the address of the asset the buyer must pay.
If the return value is address(0), the buyer pays in ETH.
function desiredAsset() external view returns (address);| Return value | Description |
|---|---|
address |
Payment asset address. address(0) denotes ETH |
requiredPayment()
The requiredPayment() function returns the fixed amount payable by the buyer.
The amount is denominated in desiredAsset.
function requiredPayment() external view returns (uint256);| Return value | Description |
|---|---|
uint256 |
Fixed amount required for a purchase |
paymentSink()
The paymentSink() function returns the destination that receives the buyer's payment.
It can be a treasury, distribution contract, or burn destination, for example.
function paymentSink() external view returns (address);| Return value | Description |
|---|---|
address |
Payment recipient |
purchase(address to)
The purchase() function collects the fixed payment from the buyer and sends the entire payout asset balance in the bucket to to.
It returns the amount actually dispensed.
function purchase(address to) external payable returns (uint256 dispensed);| Field | Type | Description |
|---|---|---|
to |
address |
Recipient of the payout asset |
dispensed |
uint256 |
Amount actually dispensed |
The caller must pay exactly requiredPayment().
For ETH payments, the call fails unless msg.value == requiredPayment().
For ERC20 payments, the call fails unless msg.value == 0, and the contract calls transferFrom(msg.sender, paymentSink(), requiredPayment()) on desiredAsset.
How the fixed payment is collected depends on whether the payment asset is ETH or an ERC20 token.

For ETH payments, msg.value is the payment amount.
For ERC20 payments, the contract uses the buyer's allowance to call transferFrom() and deliver the payment to paymentSink.
The payout amount is determined from the live balance at function entry.
For an ETH payout, it is based on address(this).balance; for an ERC20 payout, it is based on balanceOf(address(this)).
The purchase must fail if that amount is zero.
An incorrect payment amount, an empty bucket, or failure of either to or paymentSink to receive its respective transfer causes the purchase to fail.
Payment collection and the full payout complete atomically in the same transaction only when the purchase succeeds.
Asset pairs
The payoutAsset and desiredAsset values represent either ETH or an ERC20 token.
They must not both be address(0).
The following diagram shows the permitted and prohibited asset pairs.

ETH-to-ETH purchases are prohibited because incoming msg.value and the ETH already accumulated for payout would become part of the same ETH balance.
Prohibiting this pair makes it easier to treat the payout amount as the live balance captured at function entry.
Compliance requirements
A contract claiming ERC8017 compliance must provide consistent externally observable behavior for purchases, asset pairs, and configuration changes. The requirements concern the execution outcomes that buyers and integrators rely on rather than the implementation's internal coding style.
Require the exact fixed payment
Buyers must pay exactly requiredPayment().
For ETH payments, msg.value must equal that fixed amount.
For ERC20 payments, msg.value must be zero, and the fixed amount is collected using transferFrom().
Prohibit ETH on both sides of the asset pair
The payoutAsset and desiredAsset values must not both be address(0).
If buyers paid ETH to receive ETH, it would be difficult to distinguish the buyer's msg.value from ETH accumulated in the bucket for payout.
This is why that particular pairing is prohibited.
Keep the asset pair unchanged after initialization
Neither payoutAsset nor desiredAsset may change after initialization.
Changing the asset pair would alter the market conditions monitored by external controllers and searchers.
To keep the assumptions underlying purchase decisions stable, a conforming ERC8017 contract must not expose setters capable of changing these two values.
Dispense the entire bucket in one transfer
The purchase() function obtains the payout asset balance at function entry and transfers that entire amount to to in a single call.
Partial purchases and split payouts are outside the scope of the proposal.
If the amount to dispense is zero, the purchase fails.
The payout amount is determined at function entry rather than recalculated midway through execution.

The specification does not define a way to purchase only part of the assets in the bucket.
On success, the entire captured payout asset balance is transferred to to.
Forward payment to paymentSink
For ETH payments, the contract forwards msg.value to paymentSink().
For ERC20 payments, the contract uses transferFrom() to send requiredPayment() to paymentSink().
Forwarding payment instead of retaining it in the bucket contract makes it easier to track the buyer's payment separately from the payout asset balance.
Restrict administrative operations
Only authorized roles may call setRequiredPayment() and setPaymentSink().
Changes to the fixed amount or payment destination directly affect purchase conditions, so publicly accessible setters would not satisfy the compliance requirements.
The contract must also emit PaymentConfigUpdated when requiredPayment or paymentSink changes.
Purchased
On a successful purchase, the contract emits Purchased.
event Purchased(address indexed buyer, address indexed to, uint256 dispensed, uint256 paid);| Field | Type | Description |
|---|---|---|
buyer |
address |
Account that called purchase() |
to |
address |
Payout asset recipient |
dispensed |
uint256 |
Amount dispensed |
paid |
uint256 |
Amount paid |
This event lets indexers and analytics tools track which buyer made a purchase, how much they paid, and how much they received.
PaymentConfigUpdated
The contract emits PaymentConfigUpdated when requiredPayment or paymentSink changes.
event PaymentConfigUpdated(address desiredAsset, uint256 requiredPayment, address sink);| Field | Type | Description |
|---|---|---|
desiredAsset |
address |
Payment asset |
requiredPayment |
uint256 |
Fixed amount required for a purchase |
sink |
address |
Payment recipient |
The desiredAsset itself cannot change.
Including desiredAsset in the event lets external consumers easily identify the asset to which the updated payment amount and destination apply.
Optional extensions
Optional extensions improve convenience and operational asset recovery without changing the core mechanism of fixed payment and full payout.
purchaseWithPermit
For ERC20 payments, buyers ordinarily need to call approve() beforehand.
An optional purchaseWithPermit(...) function can combine signature-based approval and purchase into the same transaction.
This extension can be used only when desiredAsset != address(0).
An implementation calls permit() on desiredAsset, ensures sufficient allowance has been granted, and collects payment through transferFrom() in the same transaction.
The call must fail if desiredAsset does not support EIP2612 or if the resulting allowance is insufficient.
EIP2612 allows users to grant the equivalent of an ERC20 approve() authorization through a signature.
With this extension, buyers can make purchases without sending a separate approval transaction.
For more on EIP2612, see the following article.
[ERC2612] Combining ERC20 Approval and Transfer in One Transaction
rescue
An implementation may optionally provide a rescue function for administrators to recover assets transferred unintentionally.
However, the function must not transfer the payoutAsset.
Otherwise, administrators could withdraw assets from the bucket that should be available to buyers.
If rescue is implemented, access must be restricted to authorized roles and the function must emit Rescued(address token, address to, uint256 amount).
Examples of recoverable assets are ERC20 tokens sent accidentally and ETH sent directly when the payout asset is an ERC20 token.
Additional considerations
Fixed payments and live balances
The effective price in ERC8017 is determined by the combination of requiredPayment and the bucket's live balance.
The contract does not calculate market prices.
External controllers or searchers instead decide whether to make a purchase based on the bucket balance, external prices, gas costs, and fees.
Reading the live balance naturally reflects balance changes from rebasing and fee-on-transfer tokens. On the other hand, if third parties transfer payout tokens directly to the bucket, those tokens are included in the next payout. Buyers and controllers must account for unsolicited deposits when evaluating profitability.
The role of paymentSink
The paymentSink is the destination that receives the buyer's payment.
Instead of keeping the payment inside the bucket contract, the contract can forward it directly to a treasury, distribution contract, or burn destination.
This separation keeps the bucket's balance focused on the payout asset.
During an audit, paymentSink and Purchased events also make it easier to trace the buyer's payment.
Administrative permissions
Administrators can call setRequiredPayment() and setPaymentSink().
The mechanism for managing these permissions is not prescribed.
Implementations can choose EIP173-style ownership, role-based access control, or another mechanism that enforces the required behavior.
EIP173 defines a standard interface for retrieving and transferring contract ownership. ERC8017 illustrates ownership management in its reference implementation, but implementations are not limited to EIP173.
For more on ERC173, see the following article.
[ERC173] Smart Contract Ownership Management
Risks when changing requiredPayment
Although requiredPayment is a fixed amount for a given purchase, an implementation may allow administrators to change it.
Changing the amount when payout assets have already accumulated in the bucket directly affects the behavior of buyers and searchers.
The following diagram illustrates the main risks of changing requiredPayment.

Lowering requiredPayment can let a buyer purchase an already substantial bucket at a discount, leaking value to that buyer.
Raising it can stall purchases or cause losses for searchers running existing arbitrage strategies.
Possible safeguards include timelocks, notice periods, gradual adjustments, per-block deposit caps, cooldowns following changes, and adjustments using time-weighted average prices.
Why the proposal does not dispense multiple assets
ERC8017 limits the payout to one asset type. Dispensing multiple assets together would introduce additional requirements for allowlists, individual token balance queries, handling transfer failures, and valuation.
With a single asset, a buyer can readily understand that paying the fixed amount yields the entire current balance of that asset. It is easier to implement a multi-asset sweep as a separate mechanism outside the scope of this small specification.
Compatibility
ERC8017 can be used with ERC20 tokens.
Wallets and dApps can prepare payments through the usual approve() and transferFrom() flow.
Implementations offering the optional purchaseWithPermit() extension can combine approval and purchase using EIP2612 signatures.
Existing ERC20 tokens do not need to be modified.
The payment-side ERC20 token must support sending funds to paymentSink via transferFrom(), and the payout-side ERC20 token must support sending funds to to via transfer().
Reference implementation
The reference implementation declares payoutAsset and desiredAsset as immutable and allows only the owner to update requiredPayment and paymentSink.
The purchase logic is outlined below.
function purchase(address to) external payable nonReentrant returns (uint256 dispensed) {
uint256 toDispense;
if (payoutAsset == address(0)) {
toDispense = address(this).balance;
} else {
toDispense = IERC20(payoutAsset).balanceOf(address(this));
}
require(toDispense > 0, "empty");
if (desiredAsset == address(0)) {
require(msg.value == requiredPayment, "bad msg.value");
(bool ok, ) = paymentSink.call{value: msg.value}("");
require(ok, "sink transfer failed");
} else {
require(msg.value == 0, "unexpected ETH");
require(
IERC20(desiredAsset).transferFrom(msg.sender, paymentSink, requiredPayment),
"payment transfer failed"
);
}
if (payoutAsset == address(0)) {
(bool ok2, ) = to.call{value: toDispense}("");
require(ok2, "ETH payout failed");
} else {
require(IERC20(payoutAsset).transfer(to, toDispense), "token payout failed");
}
emit Purchased(msg.sender, to, toDispense, requiredPayment);
return toDispense;
}The key point is that toDispense is established before payment and payout interactions.
The contract then sends the payment to paymentSink and finally transfers the payout to to.
The reference implementation also uses nonReentrant to prevent reentrancy.
The following diagram illustrates the fixed order of operations involving external calls.

Because payment collection and full payout involve external calls, it is important to avoid unnecessary external interactions between them. Fixing the payout amount first, then collecting payment, dispensing the payout, and recording the event helps limit exposure to reentrancy.
The receive() function is designed to accept ETH only when ETH is the payout asset.
If ETH is sent directly when the payout asset is an ERC20 token, it is not the configured payoutAsset and is therefore not part of the normal purchase.
Security
Determining the payout amount
The payout amount is calculated from the live balance at function entry.
The ban on ETH-to-ETH exchanges avoids mixing incoming ETH payment in msg.value with the ETH payout balance.
Implementations reuse the calculated toDispense in subsequent operations so that external calls do not change the amount being dispensed.
Reentrancy
The purchase() function involves external calls, such as ERC20 transferFrom(), ETH transfers, and ERC20 transfer().
It therefore requires protection against reentrancy.
A safer design determines the payout amount first, avoids unnecessary callbacks between payment and payout, and implements a reentrancy guard.
Payout and payment recipients
The address to must be able to receive the payout asset.
For ETH payouts, it must be able to receive ETH; for ERC20 payouts, it must not cause the token's transfer() to fail.
The paymentSink must likewise be able to receive the payment asset.
For ETH payments, it must be an address that can receive ETH; for ERC20 payments, the transfer via transferFrom() must be able to succeed.
Unsolicited deposits
If a third party sends the payout asset directly to the bucket, it becomes part of the next purchase().
This follows from the decision to use the live balance as the source of truth.
Operators must consider how unsolicited deposits affect purchase conditions.
Assets other than the payout asset can be recoverable through the optional rescue extension.
Allowances and signatures
For ERC20 payments, buyers must grant the contract sufficient allowance.
Ordinary allowance updates carry a race-condition risk related to when the approved amount changes.
Implementations of purchaseWithPermit() must verify the signature's domain, deadline, and nonce through the token's permit mechanism, and check that the resulting allowance is sufficient.
Receiving a signature alone does not mean a purchase has succeeded; the payment must actually be collectible through transferFrom().
Administrative changes
The setRequiredPayment() and setPaymentSink() functions change economic conditions and the flow of funds.
Accounts or governance mechanisms with administrative authority must therefore be protected carefully.
Possible safeguards include timelocks, notice periods, gradual adjustments, and making parameters that should not change immutable.
Proxies and clones
With proxies and minimal clones, the implementation's constructor does not run separately for every instance.
The payoutAsset and desiredAsset must therefore be set only once during initialization and remain unchanged thereafter.
The initializer should prevent repeated initialization and reentrancy.
Conclusion
This article covered ERC8017, a mechanism for receiving all assets accumulated in a contract in exchange for a fixed payment.
Rather than standardizing an AMM or a comprehensive auction system, ERC8017 narrowly defines fixed payment and full-bucket payout.
This limited scope lets external controllers use the primitive for protocol revenue buybacks, reserve accumulation, and incentive budget conversion.
Implementations and operators must nonetheless manage changes to requiredPayment, unsolicited deposits, reentrancy, and the ability of paymentSink to receive payments.
I also publish articles on the following platforms.




