Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Am I utilising getChainedPrice correctly? #325

Open
acemasterjb opened this issue Nov 10, 2022 · 0 comments
Open

Am I utilising getChainedPrice correctly? #325

acemasterjb opened this issue Nov 10, 2022 · 0 comments

Comments

@acemasterjb
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant