How can one ensure that an ERC20 token holder can’t send/transfer/other more than X token in given period Y where Y could an hour, day, week, month etc.
Would be better if this can be done without taking up any more storage space.
Ethereum Stack Exchange is a question and answer site for users of Ethereum, the decentralized application platform and smart contract enabled blockchain. It only takes a minute to sign up.Sign up to join this community
You could implement coarse control and allow up to X token transfers within period Y. You can have period start on first transfer and expire after Y seconds. This will cost you few storage transfers only, but will release the block later than it should.
To solve the problem if full, you have to store a log (amount + timestamp or block number) of all recent transactions, in an array. On transfer you have to go through that array and check the transfer rate constraint. You have to keep separate array per token holder. This might be expensive and, if sender makes too many transfers, there is a risk of transfer rate check operation exceeding block gas limit. There should be a way to code it in a way to avoid permanent freeze though.
You might find some middle ground, by keeping counts in daily/hourly slots.
You might also investigate this https://github.com/figs999/Ethereum/blob/master/EventStorage.sol.