💱Exchange rate canister
Powered by HTTPS outcalls, the Exchange Rate Canister (XRC) on the Internet Computer, is a crucial feature living entirely on-chain. The XRC fetches data from Web 2.0 servers and interacts with major cryptocurrency exchanges to retrieve real-time or historical pricing information via their public APIs. It also periodically queries public APIs of foreign exchange data providers around the world to get forex rates. This feature makes it possible to integrate the XRC into Decentralized Exchanges (DEXs) to compare exchange rates against market rates and determine the value of assets held under management in a canister smart contract, for instance, with respect to a fiat currency.
HTTPS Outcalls: Breaking Barriers
Canister smart contracts on the Internet Computer can make direct calls to any Web 2.0 data source via HTTPS outcalls. These outcalls fetch data from regular web servers in a deterministic and decentralized manner, thereby eradicating the need for additional trust assumptions. By enabling this functionality, HTTPS outcalls have transformed smart contracts into a more potent tool, capable of utilizing a wealth of data from the traditional Web 2.0 world.
However, it's essential to understand that HTTPS outcalls provide access to Web 2.0 resources but do not in themselves provide oracle functionality. Despite this, they are an invaluable building block for developing oracles that operate entirely on-chain.
The Exchange Rate Canister
At the heart of this revolution is the Exchange Rate Canister (XRC). Developed by DFINITY, the XRC is an on-chain pricing oracle that fetches and provides exchange rates for any pair of base and quote assets. These assets can either be a cryptocurrency or a fiat currency. The XRC also enables the retrieval of both current rates and rates from the past.
This canister smart contract interacts with the major cryptocurrency exchanges through public APIs to get current or historical pricing information. Additionally, it periodically queries public APIs of foreign exchange data providers around the world to get forex rates.
When the XRC receives a request via the get_exchange_rate endpoint, it triggers the necessary HTTPS outcalls to gather rates. It then filters out outliers and returns the median of the remaining rates to the caller, along with pertinent metadata about the request.
Robust and Secure Operation
Developing such an oracle is not a trivial task. It requires a series of optimizations and enhancements to ensure the desired level of performance and security. Some notable optimizations include using a least-recently-used cache to store recent query results, thereby reducing HTTPS outcall repetitions. There is also a rate-limiting system to protect the subnet against a flood of requests.
Moreover, the XRC charges a fair price for its service in cycles, depending on the actual number of HTTPS outcalls that it makes to serve a request. This pricing not only makes the system more efficient but also provides a certain level of protection against denial-of-service attacks.
Practical Use Cases
There are numerous potential applications for a pricing oracle like the XRC. It's a desirable feature for DEXs, enabling them to compare the exchange rates against the market rate. Canisters holding certain funds can also leverage the XRC to determine the value of the assets under management.
Most notably, the XRC plays a significant role in the Internet Computer's Network Nervous System (NNS). The cycle-minting canister (CMC) requires an accurate ICP/XDR conversion rate to convert ICP into cycles, and it retrieves this rate from the XRC, making exchange rate proposals obsolete.
The Future of Oracle Capabilities
The Exchange Rate Canister is a pivotal first step towards the next generation of canister smart contracts with oracle capabilities. It exemplifies how a smart contract can harness the power of HTTPS outcalls to offer an oracle service that runs entirely on-chain. This innovative approach could be extended to various types of Web 2.0 data, paving the way for more on-chain oracles that provide rates for different asset classes such as stocks or ETFs.
Indeed, the advent of the Exchange Rate Canister signals a thrilling future for the Internet Computer ecosystem, where canister smart contracts reach unprecedented levels of reliability, accuracy, and trustworthiness.
Last updated