A contract implementing PushAdapter that integrates with uniswap TWAP oracle.
This adapter did not exist in AspisLiquidityCalculatorV2
Configuring Token Pairs:
Each token must be configured with an array of uniswap v3 pairs:
mapping(address => address[]) public tokenToPools;
It could be one pair to n number of pairs if there is not a direct connection between the source and target token.
For example, if we want to fetch the price of token X in terms of token Y but there is a not an X/Y pair, we will need to search for a connector pool to convert X into Y. lets assume that token Z has liquidity with both X and Y, then to convert X into Y we can:
X ⇒ Z ⇒ Y
and that means we need to add 2 pairs for token X, this is how tokenToPools for X will look like:
tokenToPools[x] = [X_Z_Pool, Z_Y_POOL]
To configure a pairs for a token we can use setTokenPools or setTokensPools (for batch) functions (limited to Guardian):
function setTokenPools(
address _token,
address[] memory _pools) external onlyGuardian {
tokenToPools[_token] = _pools;
emit TokenPoolUpdated(_token, _pools);
}
_tokens: ERC-20 token address_pools: An array of uniswap v3 poolsSince we need to convert all tokens into their USD equivalent, the last element in _pools is a pair for a connector token (the Z in above example) with an stable coin (the Y token).
The function emits an event to notify off-chain services of the updates:
event TokenPoolUpdated(address _token, address[] _pool);
The TWAP period:
the period storage variable defines the duration of time (in seconds) for which we want to calculate the average price. Currently this is hardcoded to 10 minutes, however it can be updated using setPeriod (limited to guardian):