contracts icon indicating copy to clipboard operation
contracts copied to clipboard

Fix ERC20DividendableEth for transfers.

Open alcueca opened this issue 5 years ago • 1 comments

Fix the issues with the supply first, please.

A mapping(address => uint) public dividendsPerTokenAdjustment is required to keep track of imbalances when transferring tokens with owning dividends.

In a transfer: transferWeight = trasnferAmount / recipientBalance (Fixed point) dividendsPerTokenDifferential = lastDividendsPerToken[sender]-lastDividendsPerToken[receiver] dividendsPerTokenAdjustment[account] = dividendsPerTokenAdjustment[account] + dividendsPerTokenDifferential * transferWeight

When calculating dividends owed: owedDividendsPerToken = dividendsPerToken - lastDividendsPerToken[account] + dividendsPerTokenAdjustment[account]

When claiming dividends: dividendsPerTokenAdjustment[account] = 0

alcueca avatar Feb 19 '20 22:02 alcueca

You can use these two test cases:

Test case 1: Transfers of dividend carrying tokens also transfer the dividends. Supply: 100 tokens, User 1 has 40, User 2 has 60. Distribute 10 ether. User 2 claims dividends. He's got 6 ether now. User 1 transfers 6 tokens to user 2. User 2 claims dividends again. He's got 6.6 ether now.

Test case 2: Transfers of non dividend carrying tokens don't transfer any dividends. Supply: 100 tokens, User 1 has 40, User 2 has 60. Distribute 10 ether. User 1 claims dividends. User 1 transfers 6 tokens to user 2. User 2 claims dividends again. He's got 6 ether now.

alcueca avatar Feb 20 '20 14:02 alcueca