v3-periphery
v3-periphery copied to clipboard
Am I utilising `getChainedPrice` correctly?
Hello, I'm trying to utilise getChainedPrice
to get the TWAP of a token route and was just wondering if I'm using it correctly:
function getRouteTWAP(
address[] calldata pools,
address[] calldata tokens,
uint32 period,
uint128 baseAmount
) external view returns (uint256) {
uint256 poolsLength = pools.length;
int24[] memory tickRoute = new int24[](poolsLength);
for (uint256 i = 0; i < poolsLength; i++) {
(tickRoute[i], ) = OracleLibrary.consult(pools[i], period);
}
int256 chainedMeanTick = OracleLibrary.getChainedPrice(
tokens,
tickRoute
);
return
OracleLibrary.getQuoteAtTick(
int24(chainedMeanTick),
baseAmount,
tokens[0],
tokens[tokens.length - 1]
);
}
My uncertainty about this implementation stems from the fact that getChainedPrice
returns an int256
instead of a int24
that is required for getQuoteAtTick
.
My second question is: why is the synthetic tick returned by getChainedPrice
an int256
? Should I be asserting that the synthetic tick doesn't overflow before casting to an int24
?