enzymefinance / protocol

Enzyme Protocol Implementation
https://enzyme.finance
GNU General Public License v3.0
375 stars 156 forks source link

Refactor: replace exchange adapters with integrations framework #977

Closed SeanJCasey closed 4 years ago

SeanJCasey commented 4 years ago

Addresses issue (epic) #971 .

Also heavily refactors Registry to make it more abstract, which should help reduce the need to upgrade a Registry between fund factory, adapter, price feed, and other functionality releases.

This PR also contains the basic implementation of price calculations for "derivative" (as in cTokens and Chai) assets. This includes:

^This is all abstract at this stage, and a concrete implementation will come next with the Chai integration PR

Some notes about changes to various contracts:

Registry

Shares

FundFactory

KyberPriceFeed

Tests

SeanJCasey commented 4 years ago

@travs For the Registry, we also could be setting more state in the constructor (mlnToken, nativeAsset, assets, derivatives, etc). Is there a reason we prefer for the Council to do this rather than including it in deployment? If not, we can add those in there.

SeanJCasey commented 4 years ago

@travs Another note re: the way Shares uses IDerivativePriceSource: getPrice is just a simple first implementation, because derivatives can have a basket of underlying assets (e.g., Uniswap LPs, Balancer pool tokens, etc). For those, we will actually need to refactor this function to something like getUnderlyingAssetRates, and then loop through each of the return values to add to the gav.

It gets even trickier when you consider that these underlying assets can themselves be derivative assets (e.g., a Uniswap LP with cDai).

Anyways, I thought that it would be better to just start with the simplified case of 1 underlying asset.

https://github.com/melonproject/protocol/blob/fe753552dadddd325e908673b0f0b7a93b4b690f/src/fund/shares/Shares.sol#L178