Developers Forum for XinFin XDC Network

Cover image for [Informative] Razor Network is now available on XDC Network
Rohit Dubey
Rohit Dubey

Posted on • Updated on

[Informative] Razor Network is now available on XDC Network

Razor Network, a decentralized and permissionless Oracle network, has been integrated into the XDC Network, a pioneering, carbon-neutral, and EVM-compatible Layer 1 blockchain known for its enterprise-grade features.

This integration allows developers to access and use trustless real-world price feeds for their applications, significantly enhancing the functionality and possibilities of decentralized applications on the XDC Network.

Deployment Details and Supported Chains

Image description

​​The official documentation provides detailed information on Razor Network's implementation on XDC Network and the other supported chains.

With the introduction of Razor Networks Bridge V2, the framework transitions to a Pull-based architecture. Unlike previous iterations where the oracle operator was responsible for updating price feeds on each blockchain directly, this version empowers users to retrieve prices on-chain as needed.

Once the Razor Network Oracle reaches consensus on the price feeds, this data is signed by a trustworthy entity, namely the Razor Oracle operator, and stored off-chain. Accompanying this release is a new REST API that makes this off-chain data accessible. When an on-chain update is required, users can execute a single transaction that updates the on-chain price and use it in subsequent protocols. The necessary data for this transaction is obtained from the off-chain service (REST API). This signed data is then authenticated on-chain, and the updated price is provided to the user.

This process allows Razor Network Oracle to efficiently update a vast number of price feeds across multiple blockchains, enhancing the security of existing protocols by mitigating the risk associated with delayed Oracle updates during periods of high or unpredictable gas prices.

For instructions on how to use these data feeds, visit the documentation.

About Razor Network

Razor Network is a blockchain-agnostic, truly decentralized Oracle platform designed to meet the diverse requirements of decentralized finance. At Razor Network, we have created the next-generation completely decentralized Oracle system.

-----------------------------------------------------------
The following is a brief example of how to interact with Razor Networks Oracle Bridge V2. We will go through the steps required to get the Oracle price feed data for a particular pair, in this case, the ETHUSD pair on-chain. The terms price feed and collection are used interchangeably.

Overview:
The Oracle results for each supported collection from the Razor Oracle Network are made available through a REST API. This calldata is then used to update the on-chain prices of a collection on any supported blockchain. A list of supported networks can be found here.

Note: For supported Mainnet networks the API endpoint is https://api-prod.razorscan.io/

Step 1: dapp/client will call the REST API:
Endpoint: /collection/:nameHash
Method: GET
Description:
This endpoint retrieves the call data associated with a specific collection, identified by its nameHash. This endpoint is used by applications that need to update or verify a specific collection’s data on a blockchain. The nameHash is unique for each collection.

nameHash: Corresponds to the keccak-256 hash of the collection name for eg, hash_("ETHUSD")=0x59102b37de83bdda9f38ac8254e596f0d9ac61d2035c07936675e87342817160._ A list of supported collections can be found here. An online tool could help hash collection names for this example.

Make sure to call the API to get the latest data. Copy the calldata value. We will need it to update the desired collections, in our case ETHUSD price on-chain.

curl -X GET 'https://api-staging.razorscan.io/collection/0x59102b37de83bdda9f38ac8254e596f0d9ac61d2035c07936675e87342817160'
Enter fullscreen mode Exit fullscreen mode

Example Response

{"id":2,"calldata":"0x9a6418e781a38f1d68cc498247395f794787e7e3a7d4caa3c82c355f18cd925500000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000259102b37de83bdda9f38ac8254e596f0d9ac61d2035c07936675e87342817160000000000000000000000000000000000000000000000000000000000006152e0000000000000000000000000000000000000000000000000000000065f29b320000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000000000000000131bd7b8805d3d67a502994da3ed1e8ae41d037015869ba7c251e60f60b404f5b0000000000000000000000000000000000000000000000000000000000000041a1278982788c83a66024771ad717b1ab2f8fd26a5e34a96f0e51a3a72055224532da8d09e82f26f012ad3b7375662fc9c3b3b3f785964ef588abb67718ba8ac51b00000000000000000000000000000000000000000000000000000000

000000","nameHash":"0x59102b37de83bdda9f38ac8254e596f0d9ac61d2035c07936675e87342817160","timestamp":1710398258}
Enter fullscreen mode Exit fullscreen mode

Step 2: Contract calls

The list of supported networks and their related contract address, named TransparentForwarder can be found here. The calldatareceived from the REST API is then passed to the on-chain client contract. The snippets below are examples of functions in a client contract that interact with the Razor Oracle Bridge V2 contract and return the collection data.
The following function is used to update the on-chain price and return the updated price to the requesting dapp/client.

/**
     * @notice Updates the result based on the provided data and returns the latest result
     * @dev The data will be updated only if the result is valid and is more recent than the previous result.
     * Updation will be done by the clients, though once the result is updated, it won't be updated till the latest results
     * are sent again. Regardless of the updation, the result will be returned.
     * @param _data bytes data required to update the result received from the REST API
     * @return result of the collection, its power and timestamp
     */
function updateAndGetResult(bytes calldata data) public payable returns (uint256, int8, uint256) {
        (uint256 result, int8 power, uint256 timestamp) = transparentForwarder.updateAndGetResult{value: msg.value}(data);
        return (result, power, timestamp);
}
Enter fullscreen mode Exit fullscreen mode

The following function requires the keccak-256 hash of the collection name. This function retrieves the last stored price of a specified collection but does not update it on-chain to the most recent value. Consequently, the price reported could be outdated.

/**
     * @dev using the hash of the 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) public returns (uint256, int8, uint256) {
  (uint256 result, int8 power, uint256 timestamp) = transparentForwarder.getResult(name);
        return (result, power, timestamp);
    }
Enter fullscreen mode Exit fullscreen mode
  • result (uint256): Indicates the price of the collection.
  • power (int8): Represents the power of the collection, which is used to determine the necessary decimal shifts on the result for accuracy.
  • lastUpdatedTimestamp (uint256): Marks the timestamp when the price feed was last updated.

Consider the following example:

If the result of the collection is 300050 and its power is 2, this essentially indicates that the price of the collection (asset) is $3000.50. This adds a higher level of precision.
We hope this guide provides you with a clear understanding of how to interact with Razor Network's Oracle Bridge V2 to fetch on-chain price feed data. For a more technical deep dive and to explore additional functionalities, we encourage you to visit our documentation. To witness the Razor Oracle in action and get inspired by what you can build, check out our examples repository.
Happy building!

Website | Twitter | Telegram| Discord | GitHub

Discussion (0)