有人知道为什么 Chainlink 的 PriceFeed 返回“int”类型的价格值,而价格应该始终 >= 0?

Cry*_*o D 7 chainlink

PriceFeed中获取最新价格的代码是:


pragma solidity ^0.6.7;

import "@chainlink/contracts/src/v0.6/interfaces/AggregatorV3Interface.sol";

contract PriceConsumerV3 {

    AggregatorV3Interface internal priceFeed;

    /**
     * Network: Kovan
     * Aggregator: ETH/USD
     * Address: 0x9326BFA02ADD2366b30bacB125260Af641031331
     */
    constructor() public {
        priceFeed = AggregatorV3Interface(0x9326BFA02ADD2366b30bacB125260Af641031331);
    }

    /**
     * Returns the latest price
     */
    function getThePrice() public view returns (int) {
        (
            uint80 roundID, 
            int price,
            uint startedAt,
            uint timeStamp,
            uint80 answeredInRound
        ) = priceFeed.latestRoundData();
        return price;
    }
}
Run Code Online (Sandbox Code Playgroud)

请注意,在 function 中getThePrice,为什么 Chainlink在价格上int price使用类型?int为什么不直接uint打字呢?Chainlink PriceFeed 是否有可能获得负价格?

Pat*_*ins 11

Chainlink 数据源使用int而不是uint因为某些价格可能为负,例如当石油期货跌破 0时。