Giveth / giv-token-contracts

GNU General Public License v3.0
27 stars 8 forks source link

Extract BaseUnipool and implement full suite of Unipool tests #35

Closed paxthemax closed 2 years ago

paxthemax commented 2 years ago

Resolves #34

Note that BaseUnipoolDistributor is abstract! Implementations should do the following:

  1. Inherit one of the provided LP Token implementations
  2. MUST override the virtual _distributionHook(address, uint256) internal function - to handle token distribution
  3. MUST override the _balanceOf(address) and _totalSupply() internal functions - to connect with token implementation
  4. If there are changes to the earnings logic from base unipool calculation, SHOULD override the _caculateEarned(address) internal function
  5. SHOULD proscribe a stake and withdraw interface - underlying internal _stake(address, amount) and _withdraw(address, amount) functions can be used to forward calls

The balance and total supply methods are left virtual to allow full decoupling from the LP token implementation.

The _distributionHook(address, uint256) is meant to call the TokenDistro. Likewise, _calculateEarned(address) can reference the TokenDistro implementation.

Stake and withdraw methods are not defined because implementations relying on TokenManager expect a different interface. This should allow maximum decoupling.

paxthemax commented 2 years ago

NOTE: this is all new stuff to prevent merge conflicts. If we are in agreement and push this, we can start dismantling the UnipoolTokenDistributor and GardenTokenDistributor contracts.