Skip to main content

Dividends

Overview​

The Dividends contract pays ERC-20 dividends to the holders of a RestrictedLockupToken. Each holder gets a share in proportion to the balance of the holder at a snapshot timestamp. The contract implements the IDividends interface.

Before this contract, the InterestPayment contract had the dividend functions. They moved to this separate contract to make the InterestPayment contract smaller. The behavior of each function did not change. The errors have the Dividends_ prefix now.

Key Features​

  • Snapshot-based distributions: The share of a holder comes from the token balance of the holder at a timestamp in the past.
  • Multiple token support: The Transfer Admin can distribute any ERC-20 token (USDC, DAI, etc.) as dividends.
  • Proportional allocation: Each holder gets the dividend per token multiplied by the balance of the holder at the snapshot.
  • Batch claims: A holder can claim the dividends of several snapshots in one transaction.
  • Flexible funding: The Transfer Admin can fund more than one round for the same snapshot timestamp.
  • Audit trail: The contract records the funded, claimed and unclaimed amounts of each snapshot.
  • SnapshotPeriods: The contract reads the past balances and the past total supply from the SnapshotPeriods contract of the token. InterestPayment uses the same snapshots.
  • Separate roles and pause: The roles come from the external AccessControl contract. The contract has its own pause flag and its own reclaimer address.

Deployment​

Constructor​

constructor(address accessControl_, address trustedForwarder_, address restrictedLockupToken_)​

The parameters have the same order as the RecallablePayment constructor.

Parameters:

  • accessControl_ (address): The external AccessControl contract that holds the roles
  • trustedForwarder_ (address): The ERC-2771 trusted forwarder for meta transactions
  • restrictedLockupToken_ (address): The RestrictedLockupToken whose holders get the dividends

Requirements:

  • accessControl_ must not be the zero address. Otherwise the constructor reverts with EasyAccessControl_InvalidZeroAddress.
  • restrictedLockupToken_ must not be the zero address. Otherwise the constructor reverts with Dividends_InvalidRestrictedLockupTokenAddress.
  • The token must have a SnapshotPeriods contract. Otherwise the constructor reverts with Dividends_InvalidSnapshotPeriodsAddress. Without the snapshots, each funding and each claim would revert.

Deployment with hardhat-deploy​

The script deploy/13_dividends.js (tag Dividends) deploys the contract. It runs after the token, the AccessControl contract and the forwarder. Set these keys in hardhat-deployment.js:

  • dividendsEnabled: true: deploy the contract. With any other value, the script does not deploy it.
  • dividends: "<address>": use a contract that is already deployed. The script does not deploy a new one.

When dividendsEnabled is true, deploy/08_token.js connects the SnapshotPeriods contract to the token, also when interestPaymentEnabled is false. If the token has no SnapshotPeriods contract, the script stops before the deployment.

After the deployment:

  1. As the Contract Admin, call setReclaimerAddress(reclaimer). Each reclaim reverts until the reclaimer is set.
  2. No role grant is necessary for the Dividends contract. The role checks use the external AccessControl contract.

Usage​

How Dividend Distribution Works​

The contract distributes the dividends by the historical token ownership at a snapshot timestamp. A holder gets the same share, whenever the dividend is funded or claimed.

Funding Dividends​

// Fund dividends for a specific snapshot timestamp
dividends.fundDividend(
dividendTokenAddress, // e.g., USDC contract address
dividendAmount, // Total amount to distribute (must be divisible by total supply)
snapshotTimestamp // Historical timestamp for ownership calculation
);

Requirements:

  • The dividend amount must divide by the total token supply at the snapshot.
  • The snapshot timestamp must be more than 0 and before the current block.
  • The caller must have the Transfer Admin role.
  • The dividend token must be an ERC-20 contract with at least as many decimals as the RestrictedLockupToken.

Claiming Dividends​

// Individual claim
dividends.claimDividend(dividendTokenAddress, snapshotTimestamp, amount);

// Batch claim across multiple snapshots
uint256[] memory timestamps = [timestamp1, timestamp2, timestamp3];
uint256[] memory amounts = [0, amount2, amount3]
dividends.batchClaimDividend(dividendTokenAddress, timestamps, amounts);

Frozen Wallets​

A freeze in the token stops the dividend claims of the wallet. claimDividend and batchClaimDividend revert with Dividends_WalletFrozen(wallet).

The Transfer Admin can move the unclaimed dividend of a frozen wallet to the reclaimer address with reclaimDividend. A freeze does not remove the entitlement. If the freeze is removed before an admin reclaims, the wallet can claim again.

Querying Dividend Information​

// Check unclaimed dividend amount for an address
uint256 unclaimed = dividends.unclaimedBalanceAt(
dividendTokenAddress,
holderAddress,
snapshotTimestamp
);

// Check total dividend amount available to claim (claimed + unclaimed)
uint256 totalAwarded = dividends.totalAwardedBalanceAt(
dividendTokenAddress,
holderAddress,
snapshotTimestamp
);

// Check how much dividend funding is available for a snapshot
uint256 totalFunds = dividends.tokensAt(dividendTokenAddress, snapshotTimestamp);

Dividend Allocation Logic​

The contract allocates the dividends in proportion to the token ownership at the snapshot timestamp:

Holder's Dividend = (Holder's Token Balance at Snapshot / Total Supply at Snapshot) × Total Dividend Amount

Example:

  • Total supply at the snapshot: 1,000,000 tokens
  • The holder owns: 50,000 tokens (5%)
  • Total dividend funded: 100,000 USDC
  • The share of the holder: 5,000 USDC

Multiple Dividend Rounds​

The Transfer Admin can fund more than one round for the same snapshot:

// Initial dividend funding
dividends.fundDividend(usdcAddress, 100000e6, snapshotTimestamp);

// Additional dividend funding for same snapshot
dividends.fundDividend(usdcAddress, 50000e6, snapshotTimestamp);

// Total available dividends: 150,000 USDC

Use with Interest Payments​

The Dividends contract and the InterestPayment contract can serve the same token at the same time. Both read the same SnapshotPeriods contract. They have separate funds, separate pause flags and separate reclaimer addresses. Examples:

  1. Quarterly dividends: Regular dividend distributions based on quarterly snapshots
  2. Interest and dividends: Debt service payments in InterestPayment and equity distributions in Dividends
  3. Special distributions: One-time dividend payments for specific events
  4. Multi-token distributions: Different dividend tokens (USDC, DAI, etc.) for different purposes

Example: Complete Dividend Cycle​

// 1. End of quarter - snapshot timestamp is recorded automatically
uint256 quarterEndTimestamp = block.timestamp;

// 2. Company profits are calculated off-chain
uint256 quarterlyProfits = 500000e6; // 500,000 USDC

// 3. Admin funds dividend distribution
usdcToken.approve(dividendsAddress, quarterlyProfits);
dividends.fundDividend(usdcAddress, quarterlyProfits, quarterEndTimestamp);

// 4. Token holders claim their dividends
dividends.claimDividend(usdcAddress, quarterEndTimestamp, amount);

API Reference​

Administrative Functions​

setReclaimerAddress(address newReclaimerAddress)​

Sets the address that receives the reclaimed dividends.

Parameters:

  • newReclaimerAddress (address): The new reclaimer address

Requirements:

  • The caller must have the Contract Admin role.
  • The address must not be the zero address or the Dividends contract. Otherwise the call reverts with Dividends_InvalidReclaimerAddress.

Emits: ReclaimerAddressChanged(admin, newReclaimer)


pause(bool isPaused_)​

Pauses or unpauses the contract. A pause blocks fundDividend, claimDividend, batchClaimDividend, reclaimDividend and reclaimTotalDividend. The views stay available.

Parameters:

  • isPaused_ (bool): true to pause, false to unpause

Requirements:

  • The caller must have the Contract Admin role or the Transfer Admin role.

Emits: Paused(account) or Unpaused(account)


Dividend Functions (IDividends Interface)​

fundDividend(address token_, uint256 amount_, uint256 timestamp_)​

Funds a dividend distribution for a snapshot timestamp.

Parameters:

  • token_ (address): ERC-20 token address for dividend payments
  • amount_ (uint256): Amount of tokens to distribute
  • timestamp_ (uint256): Snapshot timestamp for token holder eligibility

Requirements:

  • The caller must have the Transfer Admin role.
  • The contract must not be paused.
  • The timestamp must be more than 0 and before the current block.
  • The amount must be more than 0 and must divide by the total supply at the timestamp.
  • The total supply at the timestamp must be more than 0.
  • The contract must receive the full amount. A token with a transfer fee reverts with Dividends_InvalidFeeApplied.

Emits: DividendFunded(payer, token_, amount_, timestamp_)


claimDividend(address token_, uint256 timestamp_, uint256 amount_)​

Claims the dividend of the caller for a token and a timestamp.

Parameters:

  • token_ (address): ERC-20 token address
  • timestamp_ (uint256): Snapshot timestamp
  • amount_ (uint256): Amount of dividend to claim (0 = claim the full available amount)

Requirements:

  • The contract must not be paused.
  • The timestamp must be more than 0 and before the current block.
  • The caller must have an unclaimed dividend balance.
  • The amount must be 0 (to claim the full available amount) or not more than the unclaimed dividend of the caller at the snapshot.
  • The token must not report the caller as frozen. Otherwise the call reverts with Dividends_WalletFrozen(wallet).

Emits: DividendClaimed(payee, token_, amount_, timestamp_)


reclaimDividend(address token_, address targetAddress_, uint256 timestamp_, uint256 amount_)​

Reclaims the unclaimed dividend of one address for a token and a snapshot timestamp. The funds go to the reclaimer address.

Parameters:

  • token_ (address): ERC-20 token address
  • targetAddress_ (address): Address to reclaim the dividend from
  • timestamp_ (uint256): Snapshot timestamp
  • amount_ (uint256): Amount of dividend to reclaim (0 = reclaim the full available amount)

Requirements:

  • The caller must have the Transfer Admin role.
  • The contract must not be paused.
  • The reclaimer address must be set.
  • The amount must not be more than the unclaimed dividend of the address.

Emits: DividendReclaimed(payee, targetAddress_, token_, amount_, timestamp_)


reclaimTotalDividend(address token_, uint256 amount_, uint256 timestamp_)​

Reclaims the funds of a snapshot before any claim. The funds go to the reclaimer address.

Parameters:

  • token_ (address): ERC-20 token address
  • amount_ (uint256): Amount to reclaim (0 = reclaim all funds of the snapshot)
  • timestamp_ (uint256): Snapshot timestamp

Requirements:

  • The caller must have the Transfer Admin role.
  • The contract must not be paused.
  • The reclaimer address must be set.
  • No holder claimed and no admin reclaimed from the snapshot. Otherwise the call reverts with Dividends_AlreadyClaimed.
  • A positive amount must not be more than the funds of the snapshot and must divide by the total supply at the timestamp.

Emits: DividendReclaimed(payee, dividendsContractAddress, token_, amount, timestamp_)


batchClaimDividend(address token_, uint256[] timestamps_, uint256[] amounts_)​

Claims dividends across multiple timestamps for a token.

Parameters:

  • token_ (address): ERC-20 token address
  • timestamps_ (uint256[]): Array of snapshot timestamps
  • amounts_ (uint256[]): Array of amounts to claim for each timestamp (0 = claim full unclaimed amount for that snapshot)

Requirements:

  • The contract must not be paused.
  • All timestamps and amounts must be valid.
  • The timestamps_ and amounts_ arrays must have the same length. Otherwise the call reverts with Dividends_InvalidArrayLengths.
  • The token must not report the caller as frozen. Otherwise the call reverts with Dividends_WalletFrozen(wallet).

Emits: DividendClaimed(payee, token_, amount, timestamp_) for each timestamp


Query Functions​

Each query function that takes a timestamp reverts with Dividends_InvalidSnapshotId if the timestamp is 0 or not before the current block. isAmountDivisible is the exception: it does not examine the timestamp.

totalAwardedBalanceAt(address token_, address receiver_, uint256 timestamp_) → uint256​

Returns total awarded dividend balance (claimed + unclaimed) for an account.

Parameters:

  • token_ (address): Dividend token address
  • receiver_ (address): Address to query
  • timestamp_ (uint256): Snapshot timestamp

Returns:

  • uint256: Total awarded balance

unclaimedBalanceAt(address token_, address receiver_, uint256 timestamp_) → uint256​

Returns unclaimed dividend balance for an account at a timestamp.

Parameters:

  • token_ (address): Dividend token address
  • receiver_ (address): Address to query
  • timestamp_ (uint256): Snapshot timestamp

Returns:

  • uint256: Unclaimed dividend balance

claimedBalanceAt(address token_, address receiver_, uint256 timestamp_) → uint256​

Returns claimed dividend balance for an account at a timestamp.

Parameters:

  • token_ (address): Dividend token address
  • receiver_ (address): Address to query
  • timestamp_ (uint256): Snapshot timestamp

Returns:

  • uint256: Claimed dividend balance

tokensAt(address token_, uint256 timestamp_) → uint256​

Returns unused dividend tokens available for claims at a timestamp.

Parameters:

  • token_ (address): Dividend token address
  • timestamp_ (uint256): Snapshot timestamp

Returns:

  • uint256: Unused dividend token amount

fundsAt(address token_, uint256 timestamp_) → uint256​

Returns total funded dividend amount for a token at a timestamp.

Parameters:

  • token_ (address): Dividend token address
  • timestamp_ (uint256): Snapshot timestamp

Returns:

  • uint256: Total funded dividend amount

totalSupplyAt(uint256 timestamp_) → uint256​

Returns total token supply at a specific timestamp.

Parameters:

  • timestamp_ (uint256): Snapshot timestamp

Returns:

  • uint256: Total supply at timestamp

balanceOfAt(address sender_, uint256 timestamp_) → uint256​

Returns token balance of an address at a specific timestamp.

Parameters:

  • sender_ (address): Address to query
  • timestamp_ (uint256): Snapshot timestamp

Returns:

  • uint256: Balance at timestamp

isAmountDivisible(uint256 amount_, uint256 timestamp_) → bool​

Checks if an amount is divisible by total supply at a timestamp.

Parameters:

  • amount_ (uint256): Amount to check
  • timestamp_ (uint256): Snapshot timestamp

Returns:

  • bool: True if amount is divisible by total supply

restrictedLockupToken() → address, snapshotPeriods() → address, accessControl() → address, reclaimerAddress() → address​

Return the addresses that the contract uses. The first three are set in the constructor and do not change.


Events​

DividendFunded(address indexed payer, address indexed token, uint256 amount, uint256 indexed timestamp)​

Emitted when a dividend is funded.

Parameters:

  • payer (address, indexed): Address that funded the dividend
  • token (address, indexed): Dividend token address
  • amount (uint256): Amount of dividend funded
  • timestamp (uint256, indexed): Snapshot timestamp

DividendClaimed(address indexed payee, address indexed token, uint256 amount, uint256 indexed timestamp)​

Emitted when a dividend is claimed.

Parameters:

  • payee (address, indexed): Address that claimed the dividend
  • token (address, indexed): Dividend token address
  • amount (uint256): Amount of dividend claimed
  • timestamp (uint256, indexed): Snapshot timestamp

DividendReclaimed(address indexed payee, address indexed target, address indexed token, uint256 amount, uint256 timestamp)​

Emitted when the Transfer Admin reclaims a dividend. The funds go to the reclaimer address at the time of the reclaim. The event does not include that address. Use the ReclaimerAddressChanged history to find it.

Parameters:

  • payee (address, indexed): The Transfer Admin that started the reclaim, not the destination of the funds
  • target (address, indexed): The holder for reclaimDividend, or the Dividends contract for reclaimTotalDividend
  • token (address, indexed): Dividend token address
  • amount (uint256): Amount reclaimed
  • timestamp (uint256): Snapshot timestamp

ReclaimerAddressChanged(address indexed admin, address indexed newReclaimer)​

Emitted when the Contract Admin sets the reclaimer address. InterestPayment emits the same event. RecallablePayment emits ReclaimerAddressChanged(admin, previousReclaimer, newReclaimer) with 3 arguments, so its topic hash is different.


Paused(address account) and Unpaused(address account)​

Emitted when the contract is paused or unpaused.


Custom Errors​

Access Control Errors​

  • EasyAccessControl_InvalidZeroAddress(): The constructor got the zero address for the AccessControl contract.
  • EasyAccessControl_DoesNotHaveContractAdminRole(address addr): The caller of setReclaimerAddress is not the Contract Admin.
  • EasyAccessControl_DoesNotHaveTransferAdminRole(address addr): The caller of a funding or a reclaim is not the Transfer Admin.
  • EasyAccessControl_DoesNotHaveContractOrTransferAdminRole(address addr): The caller of pause has neither role.

Configuration Errors​

  • Dividends_InvalidRestrictedLockupTokenAddress(): The constructor got the zero address for the token.
  • Dividends_InvalidSnapshotPeriodsAddress(): The token has no SnapshotPeriods contract.
  • Dividends_InvalidReclaimerAddress(): The new reclaimer is the zero address or the Dividends contract, or a reclaim occurs while no reclaimer is set.

Dividend Errors​

  • Dividends_InvalidSnapshotId(): The snapshot timestamp is 0 or not before the current block.
  • Dividends_InvalidAmount(): The funding amount is 0.
  • Dividends_InvalidTokenAddress(): The dividend token address is zero.
  • Dividends_InvalidTokenDecimals(uint8 restrictedLockupTokenDecimals): The dividend token has fewer decimals than the RestrictedLockupToken.
  • Dividends_ZeroTotalSupply(): The total supply of the token at the snapshot timestamp is 0.
  • Dividends_IndivisibleAmount(uint256 amount, uint256 totalSupplyAt): The amount does not divide by the total supply at the snapshot timestamp.
  • Dividends_InvalidFeeApplied(): The contract received less than the funding amount, for example from a token with a transfer fee.
  • Dividends_NoRemainingUnclaimedBalance(): The address has no unclaimed dividend for the snapshot.
  • Dividends_NotEnoughFundsToClaim(): The amount is more than the unclaimed dividend, or more than the funds of the snapshot for reclaimTotalDividend.
  • Dividends_NoFundsToClaim(): The snapshot has no funds for reclaimTotalDividend.
  • Dividends_AlreadyClaimed(): A holder claimed or an admin reclaimed from the snapshot before reclaimTotalDividend.
  • Dividends_InvalidUnclaimedBalance(uint256 claimableFunds, uint256 claimedFunds): The claimed amount of an address is more than its claimable amount.
  • Dividends_InvalidArrayLengths(): The arrays of batchClaimDividend have different lengths.
  • Dividends_WalletFrozen(address wallet): The token reports the caller of claimDividend or batchClaimDividend as frozen.

Pausable Errors​

  • EnforcedPause(): The contract is paused.
  • ExpectedPause(): The contract is not paused.

Error names before the move​

The InterestPayment contract used these names for the same errors:

InterestPayment errorDividends error
InterestPayment_InvalidDividendSnapshotIdDividends_InvalidSnapshotId
InterestPayment_NoRemainingUnclaimedDividendBalanceDividends_NoRemainingUnclaimedBalance
InterestPayment_InvalidDividendTokenAddressDividends_InvalidTokenAddress
InterestPayment_InvalidTokenDecimalsDividends_InvalidTokenDecimals
InterestPayment_IndivisibleAmountDividends_IndivisibleAmount
InterestPayment_InvalidUnclaimedDividendBalanceDividends_InvalidUnclaimedBalance
InterestPayment_ZeroTotalSupplyDividends_ZeroTotalSupply
InterestPayment_DividendsAlreadyClaimedDividends_AlreadyClaimed
InterestPayment_InvalidArrayLengthsDividends_InvalidArrayLengths
InterestPayment_InvalidAmountDividends_InvalidAmount
InterestPayment_InvalidFeeAppliedDividends_InvalidFeeApplied
InterestPayment_NoFundsToClaimDividends_NoFundsToClaim
InterestPayment_NotEnoughFundsToClaimDividends_NotEnoughFundsToClaim
InterestPayment_InvalidReclaimerAddressDividends_InvalidReclaimerAddress
InterestPayment_WalletFrozen (a dividend claim)Dividends_WalletFrozen