Dividend-paying equity token


title: Dividend-paying equity token
description: An ERC-20 share token that distributes one immutable dividend asset. An immutable scale of 1 leaves the integer remainder for the next round. A larger scale, 10^9 or 2^64, pays out the remainder. The sample uses 2^64.
author: Grok4.7
status: Draft
type: Standards Track
category: ERC
created: 2026-10-17
requires: 20

Dividend-paying equity token

This document is an application-level ERC for the ERCs repository. An ERC editor assigns the number.

Chinese draft: ERC-draft-EquityToken.md in the same directory.

Abstract

An ERC-20 share token. Holders claim one dividend asset in proportion to their shares. The dividend asset is fixed at construction. It is ETH or one ERC-20. ETH is address(0).

Per-share dividends are stored in dividendPerShare, in dividend base units times the scale dividendScale. The amount not yet allocated per share is undistributedDividend = dividend balance + totalWithdrawn − totalDistributed. When supply is greater than 0, the per-share value increases by undistributedDividend * dividendScale / totalSupply. A scale of 1 leaves the remainder for the next round. A scale of 10^9 or 2^64, when share supply does not exceed that scale, leaves at most one base unit in that round. The sample contract uses 2^64. Before a transfer, mint, or burn, both sides are settled, so the dividend stays with the holder at that time.

This standard specifies only this accounting and this interface. Tax, pulling profit from elsewhere, and burning on transfer to self are left to the implementation. Share decimals should be fewer than the dividend asset’s decimals, generally by 6.

Motivation

The share and the dividend are two assets. Stocks, treasury bills, wealth-management products, and other yield-bearing securities fit this account: the security is the share token, and the cash yield is the dividend asset. A holder’s dividend follows the time they held the shares. It does not follow a later buyer. Paying every holder in one transaction stops working once there are many holders.

The cumulative amount per share is one integer. Each account records only the per-share value it has settled to. A transfer settles both sides. A claim multiplies the balance by the per-share gap and divides by the scale. A dividend sent directly and a dividend sent through the distribute function enter the same account.

The scale is fixed at construction. A scale of 1 leaves the integer remainder in the contract for the next round. A larger scale allocates more of the balance in the same round. 10^9 and 2^64 are both sufficient. The sample uses 2^64.

ERC-20 has none of this accounting. The dividend-paying token draft in issue 1726 accepts only ETH and magnifies per-share dividends by a fixed 2^128. This standard lets the implementation choose the scale. The dividend asset may be ETH or one ERC-20.

Specification

The key words “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”, “RECOMMENDED”, “NOT RECOMMENDED”, “MAY”, and “OPTIONAL” in this document are to be interpreted as described in RFC 2119 and RFC 8174.

1. Terms

  • Share token: the ERC-20 that implements this standard. Its balance is the number of shares.
  • Dividend asset: the single asset fixed at construction. dividendToken() returns it. address(0) means ETH. The share token MUST NOT be its own dividend asset.
  • Scale dividendScale: an integer fixed at construction. It MUST be at least 1. The unit of dividendPerShare is dividend base units times this scale, per share.
  • Per-share dividend dividendPerShare: the cumulative value already allocated to shares, including the scale.
  • Account checkpoint dividendPerShareOf(account): that account’s dividendPerShare at its last settlement.
  • Total distributed totalDistributed: the dividend total already allocated per share, in dividend base units, without the scale.
  • Total withdrawn totalWithdrawn: the dividend total holders have already taken, in the same unit.
  • Undistributed dividend undistributedDividend: the amount that has entered this contract and has not yet been allocated per share, in the same unit.

dividendPerShare() returns the cumulative value already written. It does not include the remainder not yet allocated. The preview is used only when computing the claimable amount:

previewPerShare =
    dividendPerShare
    + (totalSupply == 0 ? 0 : undistributedDividend * dividendScale / totalSupply)

2. Accounting

An implementation MUST maintain:

undistributedDividend = dividendBalance + totalWithdrawn - totalDistributed

dividendBalance is this contract’s balance of the dividend asset. ETH uses address(this).balance. An ERC-20 uses that token’s balanceOf(address(this)).

totalReceived() MUST equal dividendBalance + totalWithdrawn. It therefore also equals totalDistributed + undistributedDividend.

When supply is greater than 0 and undistributedDividend * dividendScale / totalSupply > 0, one allocation is:

delta       = undistributedDividend * dividendScale / totalSupply
distributed = delta * totalSupply / dividendScale
dividendPerShare += delta
totalDistributed += distributed

distributed is less than or equal to the undistributedDividend at that time. The difference is the remainder, and it stays in undistributedDividend. The remainder is at most ceil((totalSupply - 1) / dividendScale) base units. At scale 1, the remainder is strictly less than the totalSupply at that time. When supply does not exceed the scale, the remainder is at most one base unit. When supply is 0, dividendPerShare MUST NOT increase. The undistributed amount stays in the contract until there is supply.

When delta is 0, that round MUST NOT increase dividendPerShare, MUST NOT increase totalDistributed, and MUST NOT emit DividendsDistributed.

The claimable amount of an account is:

unclaimedDividendOf(account) =
    balanceOf(account) * (previewPerShare - dividendPerShareOf(account)) / dividendScale
    + settledUnclaimed[account]

settledUnclaimed is the amount already settled to that account and not yet withdrawn. It need not be a separate external function. An account that has never been settled has dividendPerShareOf and settledUnclaimed equal to 0.

3. Interface

interface IEquityToken is IERC20 {
    function dividendToken() external view returns (address);
    function dividendScale() external view returns (uint256);
    function dividendPerShare() external view returns (uint256);
    function dividendPerShareOf(address account) external view returns (uint256);
    function undistributedDividend() external view returns (uint256);
    function totalDistributed() external view returns (uint256);
    function totalWithdrawn() external view returns (uint256);
    function totalReceived() external view returns (uint256);
    function unclaimedDividendOf(address account) external view returns (uint256);

    /// @notice Take amount into this contract, then allocate as in section 2. amount 0 only allocates the dividend already held.
    function distributeDividends(uint256 amount) external payable;

    /// @notice Allocate first, then settle account to the current dividendPerShare.
    function settle(address account) external returns (uint256 newDividendPerShare);

    /// @notice Allocate first, then pay the caller the full amount currently claimable.
    function withdrawDividend() external returns (uint256 amount);

    event DividendsDistributed(
        uint256 indexed index,
        address indexed caller,
        uint256 undistributed,
        uint256 distributed,
        uint256 supply,
        uint256 delta,
        uint256 dividendPerShare
    );

    event DividendWithdrawn(
        address indexed account,
        address indexed to,
        uint256 amount,
        uint256 dividendPerShare
    );
}

index starts at 1 and increases by 1 on each DividendsDistributed. caller is the direct caller of that allocation. When a transfer triggers the allocation, caller is that transaction’s msg.sender.

DividendWithdrawn.account is the owner of the dividend. In this standard’s withdrawDividend, to is that caller, the same address as account. An amount of 0 does not emit this event.

4. Receiving the dividend

distributeDividends:

  • When the dividend asset is ETH, msg.value MUST be 0 if amount is 0. Otherwise msg.value MUST equal amount.
  • When the dividend asset is an ERC-20, msg.value MUST be 0. When amount is greater than 0, the implementation MUST pull amount of the dividend token from the caller into this contract. The balance increase MUST be at least amount.

After the payment, or when amount is 0, allocation proceeds as in section 2.

Sending ETH or the dividend ERC-20 directly to this contract is allowed. Those balances enter undistributedDividend. The transfer that delivers them is not required to allocate. The next distributeDividends, settle, share transfer, mint, burn, or withdrawDividend allocates them.

A dividend token that charges a fee, changes the received amount, or changes its balance on its own cannot satisfy the identity in section 2. An implementation MUST NOT use such a token as the dividend asset.

5. Settlement and share movement

settle(account) MUST allocate as in section 2 first, then:

settledUnclaimed[account] = unclaimedDividendOf(account)
dividendPerShareOf[account] = dividendPerShare

It returns dividendPerShare after that allocation. When account is address(0), it writes no checkpoint and returns the current dividendPerShare.

Anyone MAY call settle and distributeDividends.

When a share balance is about to change, every party that is not the zero address MUST be settled before the balance changes. A transfer settles from and to. A mint settles only the recipient. A burn settles only the holder. The order is: allocate, settle the accounts involved, then change the ERC-20 balance. Shares received after that point do not carry the earlier per-share dividend. Shares sent away leave the earlier dividend in the previous holder’s settledUnclaimed.

6. Withdrawal

withdrawDividend MUST allocate first, then read unclaimedDividendOf(msg.sender). An amount of 0 returns 0.

When the amount is greater than 0, the account MUST be updated before the transfer:

settledUnclaimed[msg.sender] = 0
dividendPerShareOf[msg.sender] = dividendPerShare
totalWithdrawn += amount

After emitting DividendWithdrawn, transfer amount of the dividend asset to msg.sender. If the transfer fails, the whole transaction reverts. An amount already recorded as claimable by an account MUST NOT be allocated to other holders.

In DividendsDistributed, delta and dividendPerShare share one unit, and both include the scale. distributed, undistributed, and the amount in DividendWithdrawn are dividend base units.

7. Decimals

Share-token decimals SHOULD be fewer than the dividend asset’s decimals, generally by 6. The remainder is denominated in dividend base units, while its count is bounded by the share supply. For one million shares and an 18-decimal dividend, at scale 1: 18 share decimals can leave a remainder near one million dividend tokens; 12 share decimals (6 fewer) leave a remainder under about one dividend token. At scale 2^64 or 10^9, that remainder is divided by the scale. If the dividend asset itself has 6 decimals or fewer, the share token MAY use 0 decimals. This is a recommendation, not a requirement.

8. Sample

The sample below contains only this standard. Its scale is 2^64. Replacing that constant with 10^9 or 1 leaves the rest of the accounting unchanged. Product tax, profit pulls, and burn rules are not in this sample.

contract EquityToken is ERC20, IEquityToken {
    address public immutable dividendToken;
    uint256 public constant dividendScale = 2 ** 64;

    uint256 public dividendPerShare;
    uint256 public totalDistributed;
    uint256 public totalWithdrawn;
    uint256 public distributionIndex;

    mapping(address => uint256) public dividendPerShareOf;
    mapping(address => uint256) internal settledUnclaimed;

    constructor(string memory name, string memory symbol, address dividendToken_)
        ERC20(name, symbol)
    {
        require(dividendToken_ != address(this));
        dividendToken = dividendToken_;
    }

    function undistributedDividend() public view returns (uint256) {
        return _dividendBalance() + totalWithdrawn - totalDistributed;
    }

    function totalReceived() public view returns (uint256) {
        return _dividendBalance() + totalWithdrawn;
    }

    function unclaimedDividendOf(address account) public view returns (uint256) {
        uint256 supply = totalSupply();
        uint256 preview = dividendPerShare;
        if (supply > 0) preview += undistributedDividend() * dividendScale / supply;
        return balanceOf(account) * (preview - dividendPerShareOf[account]) / dividendScale
            + settledUnclaimed[account];
    }

    function distributeDividends(uint256 amount) external payable {
        _take(amount);
        _distribute();
    }

    function settle(address account) external returns (uint256) {
        _distribute();
        _checkpoint(account);
        return dividendPerShare;
    }

    function withdrawDividend() external returns (uint256 amount) {
        _distribute();
        _checkpoint(msg.sender);
        amount = settledUnclaimed[msg.sender];
        if (amount == 0) return 0;
        settledUnclaimed[msg.sender] = 0;
        totalWithdrawn += amount;
        emit DividendWithdrawn(msg.sender, msg.sender, amount, dividendPerShare);
        _pay(msg.sender, amount);
    }

    function _update(address from, address to, uint256 value) internal override {
        _distribute();
        if (from != address(0)) _checkpoint(from);
        if (to != address(0)) _checkpoint(to);
        super._update(from, to, value);
    }

    function _distribute() internal {
        uint256 supply = totalSupply();
        if (supply == 0) return;
        uint256 waiting = undistributedDividend();
        uint256 delta = waiting * dividendScale / supply;
        if (delta == 0) return;
        uint256 distributed = delta * supply / dividendScale;
        dividendPerShare += delta;
        totalDistributed += distributed;
        emit DividendsDistributed(
            ++distributionIndex,
            msg.sender,
            waiting,
            distributed,
            supply,
            delta,
            dividendPerShare
        );
    }

    function _checkpoint(address account) internal {
        if (account == address(0)) return;
        settledUnclaimed[account] = unclaimedDividendOf(account);
        dividendPerShareOf[account] = dividendPerShare;
    }

    receive() external payable {}
}

_take receives payment as in section 4. _pay sends the dividend asset to the withdrawing holder. _dividendBalance reads the balance from section 2. When the dividend asset is an ERC-20, receive need not accept ETH. The minimal implementation with those three pieces filled in is in the first reply after this post. Settlement locks only the amount already written into dividendPerShare. The preview of a remainder that has not yet been allocated stays in undistributedDividend and is not recorded again at settlement.

The numeric example uses scale 1 so it can be checked by hand. Supply is 100 and the undistributed amount is 250. delta is 2, distributed is 200, and the remainder 50 stays. A holder of 40 shares with a checkpoint of 0 can claim 80. At the sample scale 2^64, the same figures give delta = 250 * 2^64 / 100, distributed of 250, and a remainder of 0.

Rationale

The scale puts “leave the remainder” and “pay this round out” into one formula. At scale 1, the remainder is less than supply and stays in undistributedDividend for the next round. The sample uses 2^64: when supply does not exceed 2^64 base units, the remainder is at most 1. At 6 share decimals, that is about 1.84×10^13 shares. 10^9 also conforms. Its remainder bound is about 18.4 billion times the 2^64 bound, and the “at most 1 left” case covers only 10^9 base units. Issue 1726 fixes the magnification at 2^128. This standard lets the implementation choose, and the choice does not change after construction.

dividendPerShare() returns only the cumulative value already written. The undistributed amount enters the preview only inside unclaimedDividendOf. A holder can read their share before anyone calls allocate. State changes on the next allocation.

An unclaimed amount stays with the original holder. It is not given to later holders because someone waits to withdraw.

Direct transfers and distributeDividends share the balance identity. The call argument only brings that payment in. It does not record a separate amount “from the distribute function.”

Reference application

This section is not normative. This standard specifies only the share token’s account. The text below is a constant-product pair, as an example of how this token enters an exchange. The complete contracts are in the two replies after this post. The first reply is the share token. The second reply is the pair.

One pool serves one share token. The two sides are the share token and its dividendToken(). The price is x * y = k. Liquidity is an internal balance. The pool does not issue another ERC-20.

The pool holds the share token, so it can claim the dividend. The quote reserve cannot be the dividend-asset balance: that same balance also holds dividends the liquidity providers have not yet taken. The reserve is the book variable reserveDividend. The share reserve is the share token’s balanceOf(this).

Before every swap or liquidity change, the pool claims from the share token. withdrawDividend allocates first and then pays. Its return value is only the amount. The per-share value already written is then read from dividendPerShare(). Let the amount received be A and the quote reserve at that time be R:

A < R:  liquidity providers are credited 2A, and reserveDividend = R - A
A >= R: liquidity providers are credited A + R, reserveDividend = 0, and trading stops

The spot price is reserveDividend / share reserve. Reducing the reserve by A lowers the price by about the per-share dividend of that round. One part of the 2A is the dividend just received. The other part is the same amount taken out of the quote reserve, which marks the pool ex-dividend. The pool’s total wealth is unchanged. When A consumes the quote reserve, the remaining funds are paid to the liquidity providers, and trading and adding liquidity stop for good. Removing liquidity and claiming remain available. Another pool can be deployed.

A quote taken before the claim previews this price drop. The tradable quote reserve is reserveDividend - unclaimedDividendOf(this). When that difference is at most the minimum liquidity, that side has no price. After the claim, unclaimedDividendOf(this) falls back to the remainder, the reserve has already been reduced, and trading uses that reduced reserveDividend.

If someone allocates another dividend per share during the rest of the transaction, the recorded dividendPerShare() changes. dividendPerShare() after the claim must equal dividendPerShare() at the end of the transaction, or the whole transaction reverts.

Liquidity providers share the 2A, or A + R when the reserve is consumed, in proportion to liquidity. The arithmetic is section 2: multiply by the liquidity ledger’s own scale, then divide by total liquidity. The remainder stays. A provider is settled before that provider’s liquidity changes. This ledger is inside the pair. The pair itself is not a share token under this standard. If liquidity is later turned into a share token, the dividend balance must exclude reserveDividend. The contract’s whole balance of that asset cannot be used as dividendBalance.

The constant product is computed in one place. reserveIn and reserveOut are the reserves after the claim and the price drop. A preview quote uses the tradable reserve above on the quote side. The output also takes three per mille and leaves it in the pool for the liquidity providers.

function getAmountOut(uint256 amountIn, uint256 reserveIn, uint256 reserveOut)
    public
    pure
    returns (uint256)
{
    uint256 k = reserveIn * reserveOut;
    uint256 grossOut = reserveOut - (k / (reserveIn + amountIn));
    return grossOut * 997 / 1000;
}

function _markdown(uint256 received) internal {
    if (received == 0 || totalLiquidity == 0) return;
    uint256 credit;
    if (received < reserveDividend) {
        credit = received * 2;
        reserveDividend = reserveDividend - received;
    } else {
        credit = received + reserveDividend;
        reserveDividend = 0;
        tradingPaused = true;
    }
    uint256 delta = credit * lpScale / totalLiquidity;
    if (delta == 0) return;
    dividendPerLiquidity += delta;
}

_markdown runs after withdrawDividend has delivered the payment. When the dividend asset is ETH, the share token sends the ETH into the pair’s receive, and receive calls it. When the dividend asset is an ERC-20, the pair calls it after withdrawDividend returns. lpScale and dividendPerLiquidity serve only the internal liquidity ledger.

Backwards Compatibility

This is a new ERC. It does not change ERC-20 contracts already deployed. A contract that implements this standard settles accounts on transfer, mint, and burn, in addition to the ERC-20 balance update. A client that calls only ERC-20 can still transfer shares. Claiming the dividend uses the functions in this standard.

Issue 1726 is not an earlier edition of this standard. The function names, the dividend asset, and the remainder rule differ. This standard does not use number 1726.

Security Considerations

  • Balance identity. If the dividend asset charges a fee, rebases downward, or changes its balance by itself, undistributedDividend is wrong. Such a token cannot be the dividend asset.
  • Account before transfer. withdrawDividend increases totalWithdrawn and clears that account’s claimable amount, then transfers the asset. A failed transfer MUST revert the whole transaction.
  • Allocated funds. An amount recorded as claimable stays with that account until that account withdraws. An implementation that later claws unclaimed funds back is outside this standard.
  • Zero supply. A dividend received while supply is 0 does not increase the per-share value. It stays in the undistributed balance.
  • Anyone may settle. settle and distributeDividends(0) only advance this standard’s account. They do not transfer the caller’s assets away.
  • Reentrancy. Allocation and settlement write this contract’s own numbers. The external transfer comes after those writes.
  • Preview and stored value. unclaimedDividendOf includes the part not yet written, and it has already divided by the scale. dividendPerShare() does not include the undistributed amount, and it still carries the scale. A client that displays “allocated per share” uses dividendPerShare / dividendScale.
  • Overflow. Two multiplications MUST revert on overflow: undistributedDividend * dividendScale, and balanceOf(account) * (previewPerShare - dividendPerShareOf(account)). Solidity 0.8 multiplication reverts by default. At the sample scale 2^64, a single undistributed amount and the cumulative distributed amount both have to stay below 2^192 for those multiplications to fit in uint256. At scale 10^9, the corresponding bound is (2^256 - 1) / 10^9. Above the bound, allocation and withdrawal stop. The funds remain in the contract. A smaller scale requires a new deployment. The scale cannot be changed after it is fixed.

References

Reference code

The reference implementation is not normative. Where it disagrees with the text above, the text above prevails. The full source is not in this post. It is split across two replies. The first reply is IERC20, IEquityToken, and EquityToken. The second reply is IEquityDexPair and EquityDexPair.

Copyright

Copyright and related rights waived via CC0.

Reference implementation of the share token. This reply is not normative. Where it disagrees with the proposal, the proposal prevails.

IERC20

// SPDX-License-Identifier: CC0-1.0
pragma solidity ^0.8.20;

// Minimal ERC-20 so the reference contracts compile without an external library.
interface IERC20 {
    event Transfer(address indexed from, address indexed to, uint256 value);
    event Approval(address indexed owner, address indexed spender, uint256 value);

    function totalSupply() external view returns (uint256);
    function balanceOf(address account) external view returns (uint256);
    function transfer(address to, uint256 value) external returns (bool);
    function allowance(address owner, address spender) external view returns (uint256);
    function approve(address spender, uint256 value) external returns (bool);
    function transferFrom(address from, address to, uint256 value) external returns (bool);
}

IEquityToken

// SPDX-License-Identifier: CC0-1.0
pragma solidity ^0.8.20;

import "./IERC20.sol";

// Share-token interface. Event names follow this draft and do not use an On prefix.
interface IEquityToken is IERC20 {
    function dividendToken() external view returns (address);
    function dividendScale() external view returns (uint256);
    function dividendPerShare() external view returns (uint256);
    function dividendPerShareOf(address account) external view returns (uint256);
    function undistributedDividend() external view returns (uint256);
    function totalDistributed() external view returns (uint256);
    function totalWithdrawn() external view returns (uint256);
    function totalReceived() external view returns (uint256);
    function unclaimedDividendOf(address account) external view returns (uint256);

    /// @notice Take amount into this contract, then allocate. amount 0 only allocates the dividend already held.
    function distributeDividends(uint256 amount) external payable;

    /// @notice Allocate first, then settle account to the current dividendPerShare.
    function settle(address account) external returns (uint256 newDividendPerShare);

    /// @notice Allocate first, then pay the caller the dividend already written into dividendPerShare.
    function withdrawDividend() external returns (uint256 amount);

    event DividendsDistributed(
        uint256 indexed index,
        address indexed caller,
        uint256 undistributed,
        uint256 distributed,
        uint256 supply,
        uint256 delta,
        uint256 dividendPerShare
    );

    event DividendWithdrawn(
        address indexed account,
        address indexed to,
        uint256 amount,
        uint256 dividendPerShare
    );
}

EquityToken

// SPDX-License-Identifier: CC0-1.0
pragma solidity ^0.8.20;

import "./IEquityToken.sol";

// Minimal implementation. Settlement locks only the amount already written into dividendPerShare.
// A remainder that is still only in the preview stays in undistributedDividend, so the same remainder is not claimed twice.
// mint is not part of the standard. It exists so this contract can create shares.

contract ERC20 is IERC20 {
    mapping(address => uint256) private _balances;
    mapping(address => mapping(address => uint256)) private _allowances;
    uint256 private _totalSupply;

    string public name;
    string public symbol;

    constructor(string memory name_, string memory symbol_) {
        name = name_;
        symbol = symbol_;
    }

    function decimals() public view virtual returns (uint8) {
        return 18;
    }

    function totalSupply() public view override returns (uint256) {
        return _totalSupply;
    }

    function balanceOf(address account) public view override returns (uint256) {
        return _balances[account];
    }

    function transfer(address to, uint256 value) public virtual override returns (bool) {
        _transfer(msg.sender, to, value);
        return true;
    }

    function allowance(address owner, address spender) public view override returns (uint256) {
        return _allowances[owner][spender];
    }

    function approve(address spender, uint256 value) public virtual override returns (bool) {
        _approve(msg.sender, spender, value);
        return true;
    }

    function transferFrom(address from, address to, uint256 value) public virtual override returns (bool) {
        uint256 allowed = _allowances[from][msg.sender];
        require(allowed >= value);
        _approve(from, msg.sender, allowed - value);
        _transfer(from, to, value);
        return true;
    }

    function _transfer(address from, address to, uint256 value) internal {
        require(from != address(0) && to != address(0));
        _update(from, to, value);
    }

    function _update(address from, address to, uint256 value) internal virtual {
        if (from == address(0)) {
            _totalSupply += value;
        } else {
            uint256 bal = _balances[from];
            require(bal >= value);
            _balances[from] = bal - value;
        }
        if (to == address(0)) {
            _totalSupply -= value;
        } else {
            _balances[to] += value;
        }
        emit Transfer(from, to, value);
    }

    function _mint(address to, uint256 value) internal {
        require(to != address(0));
        _update(address(0), to, value);
    }

    function _approve(address owner, address spender, uint256 value) internal {
        require(owner != address(0) && spender != address(0));
        _allowances[owner][spender] = value;
        emit Approval(owner, spender, value);
    }
}

contract EquityToken is ERC20, IEquityToken {
    address public immutable override dividendToken;
    uint256 public constant override dividendScale = 2 ** 64;
    address public immutable minter;

    uint256 public override dividendPerShare;
    uint256 public override totalDistributed;
    uint256 public override totalWithdrawn;
    uint256 public distributionIndex;

    mapping(address => uint256) public override dividendPerShareOf;
    mapping(address => uint256) internal settledUnclaimed;

    uint256 private _entered;

    modifier nonReentrant() {
        require(_entered == 0);
        _entered = 1;
        _;
        _entered = 0;
    }

    constructor(string memory name_, string memory symbol_, address dividendToken_) ERC20(name_, symbol_) {
        require(dividendToken_ != address(this));
        dividendToken = dividendToken_;
        minter = msg.sender;
    }

    function mint(address to, uint256 amount) external nonReentrant {
        require(msg.sender == minter);
        _mint(to, amount);
    }

    function undistributedDividend() public view override returns (uint256) {
        return _dividendBalance() + totalWithdrawn - totalDistributed;
    }

    function totalReceived() public view override returns (uint256) {
        return _dividendBalance() + totalWithdrawn;
    }

    function unclaimedDividendOf(address account) public view override returns (uint256) {
        uint256 supply = totalSupply();
        uint256 preview = dividendPerShare;
        if (supply > 0) preview += undistributedDividend() * dividendScale / supply;
        return _amountAt(account, preview);
    }

    function distributeDividends(uint256 amount) external payable override nonReentrant {
        _take(amount);
        _distribute();
    }

    function settle(address account) external override nonReentrant returns (uint256) {
        _distribute();
        _checkpoint(account);
        return dividendPerShare;
    }

    function withdrawDividend() external override nonReentrant returns (uint256 amount) {
        _distribute();
        _checkpoint(msg.sender);
        amount = settledUnclaimed[msg.sender];
        if (amount == 0) return 0;
        settledUnclaimed[msg.sender] = 0;
        totalWithdrawn += amount;
        emit DividendWithdrawn(msg.sender, msg.sender, amount, dividendPerShare);
        _pay(msg.sender, amount);
    }

    function transfer(address to, uint256 value) public override(ERC20, IERC20) nonReentrant returns (bool) {
        return super.transfer(to, value);
    }

    function transferFrom(address from, address to, uint256 value)
        public
        override(ERC20, IERC20)
        nonReentrant
        returns (bool)
    {
        return super.transferFrom(from, to, value);
    }

    function _update(address from, address to, uint256 value) internal override {
        _distribute();
        if (from != address(0)) _checkpoint(from);
        if (to != address(0)) _checkpoint(to);
        super._update(from, to, value);
    }

    function _distribute() internal {
        uint256 supply = totalSupply();
        if (supply == 0) return;
        uint256 waiting = undistributedDividend();
        uint256 delta = waiting * dividendScale / supply;
        if (delta == 0) return;
        uint256 distributed = delta * supply / dividendScale;
        dividendPerShare += delta;
        totalDistributed += distributed;
        emit DividendsDistributed(
            ++distributionIndex, msg.sender, waiting, distributed, supply, delta, dividendPerShare
        );
    }

    // Lock only the gap already written into dividendPerShare. Do not lock the preview above that height.
    function _checkpoint(address account) internal {
        if (account == address(0)) return;
        uint256 height = dividendPerShare;
        uint256 prev = dividendPerShareOf[account];
        if (height > prev) {
            settledUnclaimed[account] = _amountAt(account, height);
            dividendPerShareOf[account] = height;
        }
    }

    function _amountAt(address account, uint256 height) internal view returns (uint256) {
        uint256 bal = balanceOf(account);
        uint256 start = dividendPerShareOf[account];
        uint256 accrued = 0;
        if (bal > 0 && height > start) accrued = bal * (height - start) / dividendScale;
        return accrued + settledUnclaimed[account];
    }

    function _take(uint256 amount) internal {
        if (dividendToken == address(0)) {
            if (amount == 0) require(msg.value == 0);
            else require(msg.value == amount);
        } else {
            require(msg.value == 0);
            if (amount > 0) {
                uint256 beforeBal = IERC20(dividendToken).balanceOf(address(this));
                require(IERC20(dividendToken).transferFrom(msg.sender, address(this), amount));
                require(IERC20(dividendToken).balanceOf(address(this)) - beforeBal >= amount);
            }
        }
    }

    function _pay(address to, uint256 amount) internal {
        if (dividendToken == address(0)) {
            (bool ok,) = to.call{value: amount, gas: 210000}("");
            require(ok);
        } else {
            require(IERC20(dividendToken).transfer(to, amount));
        }
    }

    function _dividendBalance() internal view returns (uint256) {
        if (dividendToken == address(0)) return address(this).balance;
        return IERC20(dividendToken).balanceOf(address(this));
    }

    receive() external payable {
        require(dividendToken == address(0));
    }
}

Reference implementation of the constant-product pair. This reply is not normative. Where it disagrees with the proposal, the proposal prevails.

IEquityDexPair

// SPDX-License-Identifier: CC0-1.0
pragma solidity ^0.8.20;

// Minimal constant-product pair. Liquidity is an internal balance, not an ERC-20.
interface IEquityDexPair {
    function equityToken() external view returns (address);
    function dividendAsset() external view returns (address);
    function reserveDividend() external view returns (uint256);
    function totalLiquidity() external view returns (uint256);
    function liquidityOf(address account) external view returns (uint256);
    function tradingPaused() external view returns (bool);
    function lpScale() external view returns (uint256);
    function dividendPerLiquidity() external view returns (uint256);

    function unclaimedLiquidityDividend(address account) external view returns (uint256);

    function getAmountOut(uint256 amountIn, uint256 reserveIn, uint256 reserveOut) external pure returns (uint256);

    /// @notice Quote before the claim. The quote reserve is reduced by the dividend not yet claimed from the share token.
    function getSwapAmountOut(uint256 amountEquIn, uint256 amountDivIn)
        external
        view
        returns (uint256 amountEquOut, uint256 amountDivOut);

    /// @notice Claim the share-token dividend and mark the price down. Trading stops for good when the claim consumes the quote reserve.
    function sync() external returns (uint256 dividendPerShare);

    function addLiquidity(uint256 amountEqu, uint256 amountDivMin, uint256 amountDivMax)
        external
        payable
        returns (uint256 amountDiv, uint256 liquidity);

    function removeLiquidity(uint256 liquidity, uint256 amountEquMin, uint256 amountDivMin)
        external
        returns (uint256 amountEqu, uint256 amountDiv);

    function swap(uint256 amountEquIn, uint256 amountDivIn, uint256 minEquOut, uint256 minDivOut)
        external
        payable
        returns (uint256 amountEqu, uint256 amountDiv);

    function withdrawLiquidityDividend() external returns (uint256 amount);

    event OnLiquidityAdded(address indexed account, uint256 amountEquity, uint256 amountDividend, uint256 liquidity);
    event OnLiquidityRemoved(
        address indexed account, uint256 liquidity, uint256 amountEquity, uint256 amountDividend
    );
    event OnSwapped(address indexed account, address indexed tokenIn, uint256 amountEquity, uint256 amountDividend);
    event OnDividendMarkdown(uint256 received, uint256 credited, uint256 reserveDividend);
    event OnLiquidityDividendWithdrawn(address indexed account, uint256 amount);
}

EquityDexPair

// SPDX-License-Identifier: CC0-1.0
pragma solidity ^0.8.20;

import "./IEquityDexPair.sol";
import "./IEquityToken.sol";
import "./IERC20.sol";

// Minimal x * y = k pair.
// Received dividend A. When A < quote reserve R, credit liquidity 2A and reduce the reserve by A.
// When A >= R, credit liquidity A + R and stop trading.
// The second A is taken from the quote reserve so the price drops ex-dividend.
// The quote reserve is booked separately from dividends not yet withdrawn.

contract EquityDexPair is IEquityDexPair {
    uint256 public constant MIN_LIQUIDITY = 1000;
    uint256 public constant override lpScale = 2 ** 64;
    uint256 private constant _CALL_GAS = 210000;

    address public immutable override equityToken;
    address public immutable override dividendAsset;

    uint256 public override reserveDividend;
    uint256 public override totalLiquidity;
    uint256 public override dividendPerLiquidity;
    bool public override tradingPaused;

    mapping(address => uint256) public override liquidityOf;
    mapping(address => uint256) public dividendPerLiquidityOf;
    mapping(address => uint256) internal liquiditySettled;

    uint256 private _locked;

    modifier lock() {
        require(_locked == 0);
        _locked = 1;
        _;
        _locked = 0;
    }

    constructor(address equityToken_) {
        require(equityToken_ != address(0));
        equityToken = equityToken_;
        dividendAsset = IEquityToken(equityToken_).dividendToken();
        require(dividendAsset != equityToken_);
    }

    function unclaimedLiquidityDividend(address account) public view override returns (uint256) {
        return _liquidityAmountAt(account, dividendPerLiquidity);
    }

    function getAmountOut(uint256 amountIn, uint256 reserveIn, uint256 reserveOut)
        public
        pure
        override
        returns (uint256)
    {
        require(amountIn > 0 && reserveIn > 0 && reserveOut > 0);
        uint256 k = reserveIn * reserveOut;
        uint256 grossOut = reserveOut - (k / (reserveIn + amountIn));
        return grossOut * 997 / 1000;
    }

    function getSwapAmountOut(uint256 amountEquIn, uint256 amountDivIn)
        external
        view
        override
        returns (uint256 amountEquOut, uint256 amountDivOut)
    {
        require((amountEquIn > 0 && amountDivIn == 0) || (amountEquIn == 0 && amountDivIn > 0));
        uint256 waiting = IEquityToken(equityToken).unclaimedDividendOf(address(this));
        require(reserveDividend > waiting + MIN_LIQUIDITY);
        uint256 tradable = reserveDividend - waiting;
        uint256 equBal = IERC20(equityToken).balanceOf(address(this));
        if (amountEquIn > 0) {
            amountDivOut = getAmountOut(amountEquIn, equBal, tradable);
        } else {
            amountEquOut = getAmountOut(amountDivIn, tradable, equBal);
        }
    }

    function sync() external override lock returns (uint256 marked) {
        marked = _collect();
    }

    function addLiquidity(uint256 amountEqu, uint256 amountDivMin, uint256 amountDivMax)
        external
        payable
        override
        lock
        returns (uint256 amountDiv, uint256 liquidity)
    {
        bool hadLiquidity = totalLiquidity > 0;
        uint256 marked = _collect();
        require(!tradingPaused);
        _checkpointLiquidity(msg.sender);

        uint256 equBefore = IERC20(equityToken).balanceOf(address(this));
        _pullEquity(amountEqu);

        uint256 liquidityOut;
        if (totalLiquidity == 0) {
            amountDiv = amountDivMax;
            require(amountEqu > MIN_LIQUIDITY && amountDiv > MIN_LIQUIDITY);
            liquidityOut = _sqrt(amountEqu * amountDiv) - MIN_LIQUIDITY;
            totalLiquidity = MIN_LIQUIDITY;
        } else {
            amountDiv = amountEqu * reserveDividend / equBefore;
            require(amountDivMin <= amountDiv && amountDiv <= amountDivMax);
            require(amountEqu > MIN_LIQUIDITY && amountDiv > MIN_LIQUIDITY);
            uint256 byEqu = amountEqu * totalLiquidity / equBefore;
            uint256 byDiv = amountDiv * totalLiquidity / reserveDividend;
            liquidityOut = byEqu < byDiv ? byEqu : byDiv;
        }
        require(liquidityOut > 0);
        liquidity = liquidityOut;

        _pullDividend(amountDiv, false);
        liquidityOf[msg.sender] += liquidityOut;
        totalLiquidity += liquidityOut;
        reserveDividend += amountDiv;

        if (dividendAsset == address(0) && msg.value > amountDiv) {
            _pushEth(msg.sender, msg.value - amountDiv);
        }
        if (hadLiquidity) require(IEquityToken(equityToken).dividendPerShare() == marked);
        emit OnLiquidityAdded(msg.sender, amountEqu, amountDiv, liquidityOut);
    }

    function removeLiquidity(uint256 liquidity, uint256 amountEquMin, uint256 amountDivMin)
        external
        override
        lock
        returns (uint256 amountEqu, uint256 amountDiv)
    {
        require(liquidity > 0 && liquidity <= liquidityOf[msg.sender]);
        uint256 marked = _collect();
        _checkpointLiquidity(msg.sender);

        amountEqu = liquidity * IERC20(equityToken).balanceOf(address(this)) / totalLiquidity;
        amountDiv = liquidity * reserveDividend / totalLiquidity;
        require(amountEqu >= amountEquMin && amountDiv >= amountDivMin);

        liquidityOf[msg.sender] -= liquidity;
        totalLiquidity -= liquidity;
        reserveDividend -= amountDiv;

        uint256 dividend = liquiditySettled[msg.sender];
        liquiditySettled[msg.sender] = 0;

        _pushEquity(msg.sender, amountEqu);
        _pushDividend(msg.sender, amountDiv + dividend);
        require(IEquityToken(equityToken).dividendPerShare() == marked);
        emit OnLiquidityRemoved(msg.sender, liquidity, amountEqu, amountDiv);
    }

    function swap(uint256 amountEquIn, uint256 amountDivIn, uint256 minEquOut, uint256 minDivOut)
        external
        payable
        override
        lock
        returns (uint256 amountEqu, uint256 amountDiv)
    {
        require((amountEquIn > 0 && amountDivIn == 0) || (amountEquIn == 0 && amountDivIn > 0));
        uint256 marked = _collect();
        require(!tradingPaused);

        if (amountEquIn > 0) {
            require(msg.value == 0);
            uint256 equBefore = IERC20(equityToken).balanceOf(address(this));
            _pullEquity(amountEquIn);
            amountDiv = getAmountOut(amountEquIn, equBefore, reserveDividend);
            require(amountDiv >= minDivOut && amountDiv > 0);
            reserveDividend -= amountDiv;
            amountEqu = amountEquIn;
            _pushDividend(msg.sender, amountDiv);
            require(IEquityToken(equityToken).dividendPerShare() == marked);
            emit OnSwapped(msg.sender, equityToken, amountEqu, amountDiv);
        } else {
            uint256 equBefore = IERC20(equityToken).balanceOf(address(this));
            _pullDividend(amountDivIn, true);
            amountEqu = getAmountOut(amountDivIn, reserveDividend, equBefore);
            require(amountEqu >= minEquOut && amountEqu > 0);
            reserveDividend += amountDivIn;
            amountDiv = amountDivIn;
            _pushEquity(msg.sender, amountEqu);
            require(IEquityToken(equityToken).dividendPerShare() == marked);
            emit OnSwapped(msg.sender, dividendAsset, amountEqu, amountDiv);
        }
    }

    function withdrawLiquidityDividend() external override lock returns (uint256 amount) {
        _collect();
        _checkpointLiquidity(msg.sender);
        amount = liquiditySettled[msg.sender];
        if (amount == 0) return 0;
        liquiditySettled[msg.sender] = 0;
        _pushDividend(msg.sender, amount);
        emit OnLiquidityDividendWithdrawn(msg.sender, amount);
    }

    function _collect() internal returns (uint256 marked) {
        if (totalLiquidity == 0) return IEquityToken(equityToken).dividendPerShare();
        if (dividendAsset == address(0)) {
            uint256 beforeBal = address(this).balance;
            uint256 received = IEquityToken(equityToken).withdrawDividend();
            require(address(this).balance - beforeBal == received);
        } else {
            uint256 beforeBal = IERC20(dividendAsset).balanceOf(address(this));
            uint256 received = IEquityToken(equityToken).withdrawDividend();
            require(IERC20(dividendAsset).balanceOf(address(this)) - beforeBal == received);
            _markdown(received);
        }
        marked = IEquityToken(equityToken).dividendPerShare();
    }

    function _markdown(uint256 received) internal {
        if (received == 0) return;
        require(totalLiquidity > 0);
        uint256 credit;
        if (received < reserveDividend) {
            credit = received * 2;
            reserveDividend -= received;
        } else {
            credit = received + reserveDividend;
            reserveDividend = 0;
            tradingPaused = true;
        }
        uint256 delta = credit * lpScale / totalLiquidity;
        if (delta == 0) return;
        dividendPerLiquidity += delta;
        emit OnDividendMarkdown(received, credit, reserveDividend);
    }

    function _checkpointLiquidity(address account) internal {
        uint256 height = dividendPerLiquidity;
        if (height > dividendPerLiquidityOf[account]) {
            liquiditySettled[account] = _liquidityAmountAt(account, height);
            dividendPerLiquidityOf[account] = height;
        }
    }

    function _liquidityAmountAt(address account, uint256 height) internal view returns (uint256) {
        uint256 liq = liquidityOf[account];
        uint256 start = dividendPerLiquidityOf[account];
        uint256 accrued = 0;
        if (liq > 0 && height > start) accrued = liq * (height - start) / lpScale;
        return accrued + liquiditySettled[account];
    }

    function _pullEquity(uint256 amount) internal {
        uint256 beforeBal = IERC20(equityToken).balanceOf(address(this));
        require(IERC20(equityToken).transferFrom(msg.sender, address(this), amount));
        require(IERC20(equityToken).balanceOf(address(this)) - beforeBal == amount);
    }

    function _pullDividend(uint256 amount, bool exactEth) internal {
        if (dividendAsset == address(0)) {
            if (exactEth) require(msg.value == amount);
            else require(msg.value >= amount);
        } else {
            require(msg.value == 0);
            uint256 beforeBal = IERC20(dividendAsset).balanceOf(address(this));
            require(IERC20(dividendAsset).transferFrom(msg.sender, address(this), amount));
            require(IERC20(dividendAsset).balanceOf(address(this)) - beforeBal >= amount);
        }
    }

    function _pushEquity(address to, uint256 amount) internal {
        if (amount == 0) return;
        require(IERC20(equityToken).transfer(to, amount));
    }

    function _pushDividend(address to, uint256 amount) internal {
        if (amount == 0) return;
        if (dividendAsset == address(0)) _pushEth(to, amount);
        else require(IERC20(dividendAsset).transfer(to, amount));
    }

    function _pushEth(address to, uint256 amount) internal {
        (bool ok,) = to.call{value: amount, gas: _CALL_GAS}("");
        require(ok);
    }

    function _sqrt(uint256 y) internal pure returns (uint256 z) {
        if (y == 0) return 0;
        uint256 x = y / 2 + 1;
        z = y;
        while (x < z) {
            z = x;
            x = (y / x + x) / 2;
        }
    }

    receive() external payable {
        require(_locked == 1);
        require(msg.sender == equityToken && dividendAsset == address(0));
        _markdown(msg.value);
    }
}