This repository contains the Java code for Band Protocol's StdReference contracts. The live contract addresses can be found in our documentation.
To compile all contracts, run the following script in the repo root.
$ ./gradlew build
$ ./gradlew optimizedJarThe optimized jar files can be found in std-reference-basic/build/libs/ and std-reference-proxy/build/libs/ directory.
To query the prices from Band Protocol's StdReference contracts, the contract looking to use the price values should
query Band Protocol's std_reference_proxy contract.
Acceptable query functions for the std_reference_proxy contract are as follows:
public Map<String, BigInteger> get_reference_data(String base, String quote) {
return (Map<String, BigInteger>) Context.call(Map.class, this.ref, "getReferenceData", base, quote);
}
public List<Map<String, BigInteger>> get_reference_data_bulk(String[] bases, String[] quotes) {
return (List<Map<String, BigInteger>>) Context.call(List.class, this.ref, "getReferenceDataBulk", bases,
quotes);
}The result data is defined as mapping:
Map.of(
"rate", value1,
"last_update_base", value2,
"last_update_quote", value3
)where each field:
rateis defined as the base/quote exchange rate multiplied by 1e18.last_update_baseis defined as the UNIX epoch of the last time the base price was updated.last_update_quoteis defined as the UNIX epoch of the last time the quote price was updated.
- The base symbol as type
String - The quote symbol as type
String
- The base quote pair result as mapping of
ReferenceData's field and its value
For example, if we wanted to query the price of BTC/USD, the demo function below shows how this can be done.
public Map<String, BigInteger> demo(Address proxyAddr, String _base, String _quote) {
return (Map<String, BigInteger>) Context.call(Map.class, proxyAddr, "get_reference_data", _base, _quote);
}Where the result from demo(proxy_address, "BTC", "USD") would yield as hexadecimal string value:
{
"rate": "0x4E5F2DB564771E70000",
"last_update_base": "0x62EB4E85",
"last_update_quote": "0x62EB5379"
}and the results can be interpreted as:
- BTC/USD
rate = 23131.27 BTC/USDlastUpdatedBase = 1659588229lastUpdatedQuote = 1659589497
- A array of base symbols as type
String - A array of quote symbol as type
String
- A array of the base quote pair mapping results as type
List<Map<String, BigInteger>>
For example, if we wanted to query the price of BTC/USD and ETH/BTC, the demo contract below shows how this can be
done.
public List<Map<String, BigInteger>> demo(Address proxyAddr, String _bases, String _quotes) {
return (List<Map<String, BigInteger>>) Context.call(List.class, proxyAddr, "get_reference_data_bulk", _bases,
_quotes);
}Where the result from demo(proxy_address, "BTC,ETH", "USD,BTC"]) would yield:
[
{
"rate": "0x4E5F2DB564771E70000",
"last_update_base": "0x62EB4E85",
"last_update_quote": "0x62EB5379"
},
{
"rate": "0xFE616F75EB639A",
"last_update_base": "0x62EB4E85",
"last_update_quote": "0x62EB5379"
}
]and the results can be interpreted as:
- BTC/USD
rate = 23131.27 BTC/USDlast_update_base = 1659588229last_update_quote = 1659589497
- ETH/BTC
rate = 0.07160177543213148 ETH/BTClast_update_base = 1659588229last_update_quote = 1659589497