Dynamic payees & shares in PaymentSplitter
🧐 Motivation
Simple _addPayee is not enough to manage complex splitting logic
📝 Details
Right now there is only _addPayee(payee, shares) function. It's not possible to add more shares, remove shares or remove a payee altogether. Since adding a payee is like adding more shares and removing a payee is like removing all of his/her shares, adding these two function should be enough: _increaseShares(address payee, uint256 shares), _decreaseShares(address payee, uint256 shares).
Also, requiring to specify payees in the constructor limits my use case. I want to be able to make a payment splitter without payees and add payees later(e.g., using something like function addPayee(...) onlyOwner.
Just noticed that _addPayee is a private function, so it is only possible to set payees in the constructor. My proposal is still valid.
EDIT: so my proposal is to change _addPayee() private to _increaseShares() internal:
- mapping(address => uint256) private _shares;
+ EnumerableMap.AddressToUintMap private _shares;
- function _addPayee(address account, uint256 shares_) private {
+ function _increaseShares(address account, uint256 shares_) internal {
// *require checks hidden*
- _payees.push(account);
- _shares[account] = shares_;
+ _shares.set(account, _shares.get(account) + shares_);
_totalShares = _totalShares + shares_;
emit PayeeAdded(account, shares_);
}
adding a payee and shares would change all payees releasable amount since totalshares increased but they still have the same ... imagine scenario where i agree with u to get 20% royalties which are 2000 shares out of 10000 and u added 1 more beneficiary with 2000 shares ... so now i have 2000 out of 12000 .. if its fine for u , u still have to solve the issue of updating before the payees release them releasable amount !! before update i can have 1000 tokens but i still didnt claim ... after ur update i can claim 800 tokens !! so i believe u have to release all eth and erc20 tokens before update !!
I think it's possible to solve the issues you outlined using the code from sushiswap's MasterChef. They have dynamically updated shares and rewards for those shares.
relevant issue: #2896