OpenZeppelin / openzeppelin-contracts

OpenZeppelin Contracts is a library for secure smart contract development.
https://openzeppelin.com/contracts
MIT License
24.92k stars 11.79k forks source link

ERC20 Extension: "ERC20Deferred" #4873

Open alexbabits opened 9 months ago

alexbabits commented 9 months ago

Description

Extension of ERC20.sol with an opt-in deferred mechanism for all received tokens. If a user chooses to set their manual claim status to ON, then all incoming tokens from transfers AND mints are re-directed to the _pendingBalance mapping. An accurate description of this mapping is the user's "inert balance until revived". Until the user calls either claimAll() or claimSpecificAmount(), the token's remain dead.

The default for all users manual claim status is 0 (UNINITIALIZED), which means users that do not enable their manual claim status receive tokens just like normal.

Code

Details

Design Note

Benefits

Drawbacks

Options & Expansions

Thought Experiment

Someone wants to give you $1,000,000 but you refuse to claim it. The person insists that this donation is something they must do. You once again remind the person that you are NOT currently the type of person to accept ANY donation of {insert fiat name} from ANYONE. In this universe, the person cannot force you to hold the cash in your physical hands, or personal savings account for that matter. Despite your refusal of the donation, the person does the next best thing they can imagine, and forcefully donates $1,000,000 in cash to your local banks vault on behalf of your name. The bank sends you a notice saying, "If you call our number, this cash will be instantly added to your personal savings account."

You go visit your friends working at a fine dining establishment and attempt to purchase a sandwich composed of three buns, 2 patties, and a delicious secret sauce. Because your personal savings account has $1.32 your card gets declined and your friends laugh at you to mask the stench of their own poverty. Walking out of the establishment with an empty stomach, you briefly consider giving the bank a call, but remain steadfast in your morals to pave your own path in life without any donations or help.

Time goes by and you forget about the donation. You lost the banks number and thus ability to call the bank and claim those funds. Even if you changed your mind and heart, you would have no way of retrieving the money. Unless someone reminded you about the donation fiasco and your consciousness and senses were coherent enough to understand the situation, the money remains indefinitely inert inside the vault.

Amxx commented 9 months ago

Hello @alexbabits and that you for raising that issue.

I feel like this idea would require a community discussion and a standard interface. This should be achieved through the ERC process.

There are likelly multiple implementation of this, both with their own spcificities. A consequence of this "fragmentation" is that wallets don't support these workflow nativelly. Additionnally, conflicts with the ERC20 standard are not resolves (how should the transfer event be handled so that movement are correctly reported?)

We don't want to be one more non-standard implementation of this workflow. We strongly encourage you to review existing solution, discuss that with project that would use this pattern and with wallet providers that would have to interract with it, and submit an ERC. If/when community support crystallizes on a standard interface, than we would implement it.

alexbabits commented 9 months ago

I appreciate you taking the time to look at this and give feedback and advice!! @Amxx

The deferred idea natively built into tokens might be a desired feature, but it does seem to span too far beyond a smooth ERC20 extension right now for the reasons you mentioned. If wallets and communities are excited about it then an ERC process could be imagined over time, rather than for example trying to immediately force it into ERC20 standard which might be impossible/too clunky/not a good fit.

A consequence of this "fragmentation" is that wallets don't support these workflow natively.

There are zero wallets that currently support displaying a pending balance or custom events for ERC20... That's a big user friendly obstacle. (Although project front ends would probably be happy to, I'm guessing wallets like MM would never implement displaying pending balances unless it became very mainstream).

conflicts with the ERC20 standard are not resolved (how should the transfer event be handled so that movement are correctly reported?)

If it were to adhere to ERC20 all _update() actions should still emit the transfer event in all cases of token movement, but within this idea that would be misleading and inappropriate because some actions are not traditional transfers, so this is a problem as well for adhering to ERC20 standard.

There are likely multiple implementation of this

Right... Pending balances could be updated for just non-mint transfers, or just mints, or transfers and mints... Along with many other things. So those options would all be on the table. And other oddities of how it might interact with other common customized ERC20s/protocols/things/etc.