Oracle Price Deviation

Check if Pyth oracle price for BTC is deviated by 10% for a price feed on Arbitrum.

use Call, Aggregate, Max, Min from hexagate;

/* Binance Oracle */
source oracle: address = 0xC8e027C40B25C4Cd0c059763D042e79466D7bBB6; 

/* BTC */
source assetId: integer = 1;

/* Get the price of snBNB as reported by the oracle over 10 blocks */
source price: list<integer> = Aggregate {
  source: Call {
    contract: oracle,
    signature: "function getPythLastPrice(uint256 assetId, bool requireFreshness) returns (uint256)",
    params: tuple(assetId, false)
  },
  blocks: 10
};

/* Get max and min price */
source maxPrice: integer = Max { sequence: price };
source minPrice: integer = Min { sequence: price };

/* Check the price deviation (in integers) */
source priceDeviation: integer = 1000 - (minPrice * 1000) / maxPrice;

/* Make sure the price. is not deviated by 10% */ 
rule {
  description: "Pyth oracle deviated by 10% for Binance price feed",
  condition: priceDeviation < 10
};

Last updated