For the complete documentation index, see llms.txt. This page is also available as Markdown.

การอ่านราคา

ค้นหาที่อยู่ PriceFeed contract เชื่อมต่อโดยใช้ Chainlink interface และอ่านราคาปัจจุบันพร้อมการตรวจสอบที่ถูกต้อง

ขั้นตอนที่ 1: ค้นหา Oracle Address

สามวิธีในการค้นหาที่อยู่ PriceFeed contract สำหรับคู่ที่กำหนด:

  • Price Oracle Tracker (ง่ายที่สุดในระหว่างการพัฒนา): price-oracle-tracker.vercel.app — แสดงคู่ที่ deploy แล้วทั้งหมด ราคาสด decimals heartbeat และที่อยู่

  • On-chain ผ่าน OracleFactory: เรียก pairToOracle(string pair) สัญลักษณ์คู่ต้องส่งเป็นตัวพิมพ์ใหญ่ (เช่น "PSG/USDT") — factory ไม่ normalize input ในการอ่าน

  • Bulk on-chain ผ่าน OracleFactoryReader: เรียก getActiveOracles() เพื่อดึงคู่ที่ใช้งานได้ทั้งหมดและที่อยู่ในการเรียกครั้งเดียว

interface IOracleFactory {
    function pairToOracle(string memory pair) external view returns (address);
    function getOracleCount() external view returns (uint256);
}

function resolveFeed(address factory, string memory pair)
    external view returns (address)
{
    // Pair symbol must be passed in uppercase (e.g. "PSG/USDT").
    return IOracleFactory(factory).pairToOracle(pair);
}

ขั้นตอนที่ 2: เชื่อมต่อโดยใช้ Interface

PriceFeed contract รองรับ Chainlink IAggregatorV3Interface มาตรฐาน รวมถึงส่วนขยายเฉพาะของ Chiliz สำหรับสถานะสุขภาพและสถานะหยุดชั่วคราว

ขั้นตอนที่ 3: อ่านราคา

ฟังก์ชันหลักคือ latestRoundData() ซึ่งคืนค่าราคาปัจจุบันพร้อมข้อมูล round และ timestamp

หากโปรโตคอลของคุณใช้ decimals native ของ feed แทนการ normalize เป็น 18:

ข้อมูลย้อนหลัง

oracle เก็บข้อมูล round ย้อนหลังทั้งหมดไว้ใน on-chain การอัปเดตราคาแต่ละครั้งจะสร้าง round ใหม่พร้อม roundId ที่เพิ่มขึ้น

view helper เพิ่มเติมที่ Chiliz feed เปิดเผย:

ฟังก์ชัน
คืนค่า

latestAnswer()

ราคาล่าสุด หรือ 0 หากไม่มี

latestTimestamp()

updatedAt ล่าสุด หรือ 0 หากไม่มี

latestRound()

round ID ปัจจุบัน

getAnswer(uint80 roundId)

ราคาสำหรับ round ที่กำหนด หรือ 0

getTimestamp(uint80 roundId)

timestamp สำหรับ round ที่กำหนด หรือ 0

getRoundsData(uint80[] roundIds)

array RoundData แบบ bulk

roundExists(uint80 roundId)

true หาก updatedAt > 0

Events

PriceFeed contract แต่ละรายการปล่อย:

  • AnswerUpdated(int256 indexed current, uint80 indexed roundId, uint256 updatedAt): ปล่อยในทุกการอัปเดตราคา กรองตามราคาหรือ round

  • NewRound(uint80 indexed roundId, address indexed startedBy, uint256 startedAt): ปล่อยเมื่อ round ใหม่เริ่มต้น กรองตาม round หรือ address ที่เริ่ม

ฟังก์ชันค้นหา (OracleFactoryReader)

ฟังก์ชัน
คำอธิบาย

getActiveOracles()

คืนค่าคู่ที่ใช้งานได้ทั้งหมดพร้อม oracle address

getAllOracles()

คืนค่า oracle ทั้งหมด รวมถึงที่ไม่ได้ใช้งาน

getOraclesByPairs(string[] pairs)

แก้ไขชื่อคู่หลายคู่เป็น oracle address ในการเรียกครั้งเดียว

getOracleHealthStatus(address oracle)

สถานะสุขภาพสำหรับ oracle เดียว

getAllOracleHealthStatus()

สถานะสุขภาพสำหรับทุก oracle ในระบบ

อัปเดตล่าสุด

สิ่งนี้มีประโยชน์หรือไม่?