Files
sre-06-oracles/packages/hardhat/scripts/oracle-bot/price.ts
2026-01-23 20:20:58 +07:00

17 lines
659 B
TypeScript

import { getConfig } from "../utils";
export const getRandomPrice = async (nodeAddress: string, currentPrice: number): Promise<number> => {
const config = getConfig();
const nodeConfig = config.NODE_CONFIGS[nodeAddress] || config.NODE_CONFIGS.default;
// Calculate variance range based on the node's PRICE_VARIANCE
// PRICE_VARIANCE of 0 means no variance, higher values mean wider range
const varianceRange = Math.floor(currentPrice * nodeConfig.PRICE_VARIANCE);
// Apply variance to the base price
const finalPrice = currentPrice + (Math.random() * 2 - 1) * varianceRange;
// Round to nearest integer
return Math.round(finalPrice);
};