Say you are tasked with coding a smart contract with the following features:
- Users can deposit token A and receive liquidity shares in return.
- The contract starts selling token A for token B depending on some arbitrary rules. Every time there is a trade, all users receive a pro rata share of token B.
- Users can redeem their liquidity shares in exchange for both token A and token B.
- Other users can deposit token A and receive liquidity shares, but they are not eligible to withdraw token B earned by previous users.
In an ideal world, the protocol would do a multisender.app-style distribution of token B, but this is impossible because of block gas limits. Hence I must issue shares and let users retroactively claim their rewards.
Is there a framework or a protocol that I could use to implement this?
I looked at Set Protocol, but their Rebalancing Sets are out of scope for my use case - they depend on auctions to rebalance the composition of the Set.
I also looked at Balancer, which gets close, but their pooled model breaks feature no. 4 from above. Users who deposit late should not be eligible to withdraw tokens B that had been earned by previous depositors.
Is this smart contract design even possible? I personally can't see a way for the contract to selectively distribute token A and token B to users, on a pro-rata basis, while taking into account the times at which users deposited token A.