The developed BalancerAggregator contract automatically compute the weighted average price of a Balancer pool token following the balances of the tokens listed in the pool. Please note that the same formula is used in exitPool to compute the exit value for each token listed in the balancer pool.
BalancerAggregator contract has to be used as a source for the pool token when setting up the ChainlinkProxyPriceProvider, the required chainlink feed sources must be set in BalancerAggregator.
----------------------------- -------------------- /== latestAnswer ==> ChainLinkAggregator 1
|ChainlinkProxyPriceProvider|==== latestAnswer =================>|BalancerAggregator|===========|== latestAnswer ==> ChainLinkAggregator 2
----------------------------- -------------------- \== latestAnswer ==> ChainLinkAggregator 3
|| ------------- ||
=== getAssetPrice == > |PriceOracle| <== getAssetPrice===
-------------
The implemented contract act as a middle aggregator between Aave and ChainLink feeds. BalancerAggregator uses the fallback price oracle managed by the Aave to get the token prices if the ChainLinks feeds return zero.
If a chainlink feed returns zero and the Aave managed price oracle returns zero for the same asset the BalancerAggregator for a specific balancer pool will return zero, even if all other tokens are set correctly. In the previous case ChainlinkProxyPriceProvider has to fallback to the managed price oracle to get the price of the pool token.
The implemented test shows the different deployment steps, the error cases and fallback cases to Aave price oracle.
- node v10.20.1
- npm 6.14.4
- truffle
$ git clone https://github.com/ridesolo/AaveBalancerAggregator.git
$ cd AaveBalancerAggregator
$ npm install
$ npm run test-coverage
$ npm run compile
$ npm run test
- BalancerAggregator contract.
- balancer.aggregator tests.