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

[UniswapPairPriceAdapter] getPrice check wrong address #161

Open
Kealman opened this issue Nov 11, 2021 · 1 comment
Open

[UniswapPairPriceAdapter] getPrice check wrong address #161

Kealman opened this issue Nov 11, 2021 · 1 comment

Comments

@Kealman
Copy link

Kealman commented Nov 11, 2021

Hello! I'm facing issue with UniswapPairPriceAdapter. I've add the pools but getPrice returns always false.
I think this is because of a bug in the contract.

addPool function saves into uniswapPoolsToSettings by the pool address

function addPool(address _poolAddress) external onlyOwner {
        require (
            !uniswapPoolsToSettings[_poolAddress].isValid,
            "Uniswap pool address already added"
        );
        IUniswapV2Pair poolToken = IUniswapV2Pair(_poolAddress);

        uniswapPoolsToSettings[_poolAddress].tokenOne = poolToken.token0();
        uniswapPoolsToSettings[_poolAddress].tokenTwo = poolToken.token1();
        uint256 tokenOneDecimals = ERC20(uniswapPoolsToSettings[_poolAddress].tokenOne).decimals();
        uniswapPoolsToSettings[_poolAddress].tokenOneBaseUnit = 10 ** tokenOneDecimals;
        uint256 tokenTwoDecimals = ERC20(uniswapPoolsToSettings[_poolAddress].tokenTwo).decimals();
        uniswapPoolsToSettings[_poolAddress].tokenTwoBaseUnit = 10 ** tokenTwoDecimals;
        uniswapPoolsToSettings[_poolAddress].isValid = true;

        allowedUniswapPools.push(_poolAddress);
    }

But getPrice function check by the assets addresses

function getPrice(address _assetOne, address _assetTwo) external view returns (bool, uint256) {
        require(controller.isSystemContract(msg.sender), "Must be system contract");

        bool isAllowedUniswapPoolOne = uniswapPoolsToSettings[_assetOne].isValid;
        bool isAllowedUniswapPoolTwo = uniswapPoolsToSettings[_assetTwo].isValid;

        // If assetOne and assetTwo are both not Uniswap pools, then return false
        if (!isAllowedUniswapPoolOne && !isAllowedUniswapPoolTwo) {
            return (false, 0);
        }

        IPriceOracle priceOracle = controller.getPriceOracle();
        address masterQuoteAsset = priceOracle.masterQuoteAsset();

        uint256 assetOnePriceToMaster;
        if(isAllowedUniswapPoolOne) {
            assetOnePriceToMaster = _getUniswapPrice(priceOracle, _assetOne, masterQuoteAsset);
        } else {
            assetOnePriceToMaster = priceOracle.getPrice(_assetOne, masterQuoteAsset);
        }

        uint256 assetTwoPriceToMaster;
        if(isAllowedUniswapPoolTwo) {
            assetTwoPriceToMaster = _getUniswapPrice(priceOracle, _assetTwo, masterQuoteAsset);
        } else {
            assetTwoPriceToMaster = priceOracle.getPrice(_assetTwo, masterQuoteAsset);
        }

        return (true, assetOnePriceToMaster.preciseDiv(assetTwoPriceToMaster));
    }

So this will be return always false

// If assetOne and assetTwo are both not Uniswap pools, then return false
        if (!isAllowedUniswapPoolOne && !isAllowedUniswapPoolTwo) {
            return (false, 0);
        }

Am I missing something?

@gzliudan
Copy link
Contributor

gzliudan commented Feb 19, 2022

UniswapV2Pair is ERC20 also. So when _assetOne or _assetTwo is a UniSwap pool address, the function getPrice will not retrun (false, 0).

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

2 participants