-
Notifications
You must be signed in to change notification settings - Fork 11.7k
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
Adding tokens/ERC20/PreserveBalancesOnTransferToken.sol #1100
Conversation
Hi @AnthonyAkentiev, thanks for your contribution! We already have something along these lines in progress (#991), would that suit these needs? |
Hi, @nventuro. One
Two
Yes, seems like in #991 is about the same. I haven't seen it when we started to implement the PreserveBalancesOnTransferToken :-( However, we have a different design and i think that our implementation (+tests, +code coverage, etc) is little better. How to deal with that? Is there any way we could move forward with the code review? p.s. I will fix the build little bit later (within 1-2 days) |
Hi @AnthonyAkentiev! It's great to see that we felt the need for the same feature. I actually like the implementation in #991 a lot more. It was only a prototype so it doesn't have any tests, as you noted, or documentation. However, I think it is a lot simpler and easier to understand, which is important to verify correctness and security. There is no arbitrary limit to the number of snapshots in #991, like the limit of 20 concurrent events here. This means there's no need for a notion of stopping and starting events, reducing the conceptual complexity, and no need to restrict taking snapshots to an owner account to prevent attacks. This is accomplished by using a binary search to get past balances, which does add some complexity to the implementation, but it is definitely justified by the resulting simplicity of the rest of the contract. The idea of the auxiliary As for how to move forward with this PR, I'm afraid I have a strong preference for #991. If you're interested in collaborating on getting this feature included in OpenZeppelin, we would definitely welcome tests and documentation over there. |
@frangio Thx for the reply.
I can refactor the code so that no limit will be set.
Yes, this is a mandatory feature (in case of our DAO Framework for example). You can pass this snapshot token to any method/contract that is ERC20-compatible-only and get the balances right at the time event is started. There is no need to pass any interface and rewrite the code. Just pass an address of the Snapshot and everything will work fine. I think that it's great and simplifies everything. Under the hood code is a bit more complex of course, but the clients will not see that. So what we have now:
Of course guys from 991 can add tests and improve the code. So comparison will be then like this:
So if comparing like that, is there any possibility so that i should continue the 1100 and fix everything? Thx! |
@frangio Ah, you are the 991 creator? No stopSnapshot in 991Also, i wanted to say about the limit to 20 snapshots. This is just in order to reduce gas costs. Still: |
The loop doesn't move through all snapshots. Because it's a binary search it will only move through O(log(snapshot count)) snapshots, and in practice it will be much lower than that. Crucially, though, this relatively expensive loop is only done in the special function balanceOfAt, whereas the normal ERC20 operations have only a constant overhead compared to the standard token implementation: I went through your implementation in more detail. It potentially loops over all snapshots in every transfer operation, which is why you initially capped it to 20. Removing the cap is not a good idea because the loop can eventually become arbitrarily large resulting in prohibitive gas costs for using the token. The cap was the right choice for this implementation, but while it may be enough for a particular use case, it's not quite enough for a general-purpose library like OpenZeppelin. The point about minting and burning is a good one. There was no way for #991 to correctly handle that, but after #1197 is merged it will be simple to fix because of the new internal I can't deny that #991 is way behind this PR in terms of tests and documentation. But unfortunately there is problems in the implementation here that I think will be too much work to fix compared to taking #991 to completion. I'm closing this because of everything explained. Thank you for taking the time to contribute, regardless! |
@frangio Thank you for the reply. Still i don't agree with you and think that our implementation is better (it REMOVES the unused snapshots from the array, supports parallel snapshots, has SnapshotToken ERC20 wrapper, tests are ready, _mint and _burn already supported, etc). Ok, we will just continue to use our code and it will be the part of the Thetta DAO Framework. I hope that your decision is not based of "politics" but only on the technical side. Still looking forward for cooperation. |
🚀 Description
Adding files:
What is PreserveBalancesOnTransferToken?
Please see this Rationale with example here - https://medium.com/thetta/how-non-blocking-votings-work-in-thetta-46706f05b382
PreserveBalancesOnTransferToken can be used to preserve the ERC20 balances after some EVENT happens (voting is started, didivends are calculated, etc) without blocking the token transfers! Please notice that EVENT in this case has nothing to do with Ethereum events.
How do we use that in Thetta?
Please see https://github.com/Thetta/Thetta-DAO-Framework/blob/dev2/contracts/tokens/StdDaoToken.sol
We need PreserveBalancesOnTransferToken because we should not block transfers when new voting is started.
p.s. Also, i don't like the name of the PreserveBalancesOnTransferToken, but still has no other ideas((
Maybe NonBlockingToken?
===
npm run lint:all:fix
).