1

02 Plugin (PLI) oracle feeds on XDC

2

What a consumer sees

interface IPluginFeed {
    function decimals() external view returns (uint8);
    function description() external view returns (string memory);
    function latestRoundData() external view returns (
        uint80 roundId, int256 answer, uint256 startedAt,
        uint256 updatedAt, uint80 answeredInRound);
}
3

Gotchas observed on mainnet feeds

4

The five checks every consumer needs

Optional: min/max bounds, max deviation vs. last accepted price

5

Scaling to 18 decimals

uint256 p = latestPrice();
if (feedDecimals < 18) return p * 10 ** (18 - feedDecimals);
return p / 10 ** (feedDecimals - 18);
6

Testing feeds

XDC_FORK_RPC=https://rpc.xinfin.network forge test --match-path 'test/fork/*'

→ Lab 2

All workshop material