Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ERC20DividendableEth for transfers. #215

Open
alcueca opened this issue Feb 19, 2020 · 1 comment
Open

Fix ERC20DividendableEth for transfers. #215

alcueca opened this issue Feb 19, 2020 · 1 comment
Assignees

Comments

@alcueca
Copy link
Contributor

alcueca commented Feb 19, 2020

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
Copy link
Contributor Author

alcueca commented Feb 20, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants