ERC-1620 Money streaming (continuous payment) (Money Streaming)

Stagnant · Vaults & DeFi · created 2018-11-24

A stream contract standard in which two parties deposit ERC20 tokens that flow to the recipient at a fixed rate per unit time, measured by block number. The recipient can withdraw the amount accrued over the elapsed blocks at any time.

Why it is needed

Long-term monetary commitments such as salaries, subscriptions, rent, and consulting fees are typically paid in a single lump sum on a fixed date. Under this approach, the recipient receives no compensation proportional to the time actually worked or the service actually provided until the settlement date, and if the payer's circumstances change in the meantime, there is no way to reverse funds already sent. On blockchains, without a standard, payments with similar characteristics, such as salaries, subscriptions, rent, and crowdsale refunds, each have to be implemented with differently designed contracts, and wallets or apps cannot query, withdraw from, or halt them through shared functions and events. Changing terms or stopping midway also relies solely on trust between the parties, with no standardized mechanism for agreement.

What to implement

In depth

Stream struct

A stream consists of sender (the address funding it), recipient (the address receiving the money), tokenAddress (the ERC20 token address used for payment), balance (the total funds remaining in the stream), timeframe, and rate. timeframe represents the stream's start and end points as two block numbers, start and stop, and rate defines the payment speed via payment (how much to send) and interval (how often to send it).

Time measurement and solvency calculation

This standard uses block number as a proxy for time instead of an actual clock. The amount the recipient can withdraw up to a given point, i.e. ongoing solvency, is calculated as payment rate * (current block height - start block height). Block number serves as the basis for this approach because it is a trustworthy reference that all participants can verify identically.

The create function

create establishes a new stream between msg.sender and _recipient. It specifies the token address, start and end blocks, payment, and interval together. A single sender MUST be able to open multiple streams at once, and it SHOULD use only ERC20-compatible tokens rather than accepting ether. A successful call emits the LogCreate event.

The withdraw function

withdraw pulls out all or part of the available funds for a given stream. This action MUST be performable only by the recipient. A successful call emits the LogWithdraw event.

The redeem function

redeem closes the stream and distributes the remaining funds to the sender and recipient. It is RECOMMENDED that either party be able to call this. A successful call emits the LogRedeem event, which records _senderBalance and _recipientBalance, the respective shares after distribution.

Update agreement process (confirmUpdate / revokeUpdate)

Changing a stream's terms (token, end block, payment, interval) requires agreement from all involved parties, and MUST NOT take effect from only one party's agreement. When a party signals agreement, LogConfirmUpdate is emitted, and once the last party agrees, LogExecuteUpdate is emitted and the change takes effect. A proposed update can be withdrawn via revoke, which emits LogRevokeUpdate. Note that in the original specification, the code listed under the confirmUpdate description is actually named update, and the code listed under the revokeUpdate description is actually named confirmUpdate, so the function names and section headings are mismatched.

Uncertainty in block time and ways to correct for it

Because Ethereum block times fluctuate within a range on average, a configured period can end up diverging from the duration actually intended on a real clock. If the average block time becomes slower than expected, the recipient receives funds later; if it becomes faster, the recipient receives funds sooner. The original text proposes two responses. One is for participants to agree on a call to update to correct the terms, and the other is to use past block timestamps to automatically checkpoint the stream every so many blocks so it self-corrects for the error, though this is noted as still being at the research stage due to the gas cost burden. Also mentioned is the option of setting the stream's duration to a multiple of the chain's average block time (GCD).

Proposal status and out-of-scope items

This proposal's status is Stagnant, meaning it is a draft that has stalled. The original text mentions, only as areas for future exploration not included in this specification's scope, alternatives such as payment channels or Plasma chains, implementations on sidechains (POA Network, xDai, etc.), oracles that would supply time information instead of block numbers, and multi-hop streams that pass stream funds along an A-B-C chain without an intermediate step.

Original ERC · ← ERCs