skalenetwork / docs.skale.space

https://docs.skale.space/
MIT License
1 stars 2 forks source link

Razor Network #21

Closed manuelbarbas closed 5 months ago

manuelbarbas commented 11 months ago

Razor Network

Razor Network is a decentralized oracle network offering price-feed data to applications. This can be utilized in various actions throughout DeFi and other more general Web3 use cases. Razor is available on the Calypso, Nebula, Titan Mainnet, and Testnets.

Implementation Example

To consume the Razor Network price feeds, your contract should reference ITransparentForwarder. This is an interface that defines the external functions implemented by Data Feeds

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

interface ITransparentForwarder {
    /**
     * @dev using the hash of collection name, clients can query the result of that collection
     * @param _name bytes32 hash of the collection name
     * @return result of the collection and its power
     */
    function getResult(bytes32 _name) external payable returns (uint256, int8);
}

contract DataFeed {
    ITransparentForwarder public transparentForwarder;
    uint256 public latestResult;
    int8 public latestPower;

    constructor() {
        transparentForwarder = ITransparentForwarder(
            /* Transparent Forwarder contract address deployed on respective chains */
        );
    }

    /// @notice fetch collection result by name
    /// @param name bytes32 hash of the collection name
    /// @return result of the collection and its power
    /// @return power
    function getResult(bytes32 name) public payable returns (uint256, int8) {
        (uint256 result, int8 power) = transparentForwarder.getResult{
            value: msg.value
        }(name);
        latestResult = result;
        latestPower = power;
        return (result, power);
    }
}

For more information go to the Razor data feed documentation.