Skip to content

Commit

Permalink
dapp: Move Band oracle to Tools section
Browse files Browse the repository at this point in the history
  • Loading branch information
aefhm committed Aug 30, 2024
1 parent 135c6c3 commit ea78598
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 20 deletions.
File renamed without changes
File renamed without changes
11 changes: 11 additions & 0 deletions docs/dapp/tools/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Tools & Services

Oasis integrates with a number of services and provides tooling support for
developers using [Remix] (*unencrypted transactions only*), [Sourcify],
[Docker][localnet], and more. Please reach out to us on [Discord][discord] if
you are using a tool that has problems integrating with Oasis.

[Remix]: https://remix.run/docs/en/main
[Sourcify]: /dapp/sapphire/guide/#contract-verification
[localnet]: /dapp/sapphire/guide/#running-a-private-oasis-network-locally
[discord]: https://oasis.io/discord
Original file line number Diff line number Diff line change
@@ -1,50 +1,93 @@
# Integrating BAND oracle smart contract
# Integrating BAND Oracle

<p style={{width: '100%'}}>
<iframe style={{margin: 'auto', display:'block'}} width="560" height="315" src="https://www.youtube.com/embed/cwe6P5MvIfk?si=4QFRA8yJ2PCZB5fq" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</p>

This guide will explain how to query the Band Protocol reference data smart
contract from another Solidity smart contract on Emerald.
contract from another Solidity smart contract on Oasis Sapphire, a confidential
EVM-compatible [Paratime][paratime].

:::tip

You can follow the same steps to integrate with Band on Oasis [Emerald][emerald]
, a non-confidential EVM. See Band [documentation][band-supported-blockchains]
for full list of deployed contract addresses.

:::

[paratime]: /general/oasis-network/faq#how-is-a-paratime-different-from-a-parachain
[emerald]: /dapp/emerald
[band-supported-blockchains]: https://docs.bandchain.org/develop/supported-blockchains

### What is the Band Protocol?

[Band Protocol](https://bandprotocol.com) is a cross-chain data oracle
platform that aggregates and connects real-world data and APIs to smart
contracts. You can read more about the specific details of the protocol
contracts. You can read more about details of the protocol
[here](https://docs.bandchain.org).

### Deploy Oracle

1. Follow [this link][demooracle-remix] to Remix. The link contains an encoded example `DemoOracle.sol` contract.
1. Follow [this link][demooracle-remix] to Remix. The link contains an encoded
example `DemoOracle.sol` contract.
2. Compile the contract with compiler version `0.6.11`.
3. Switch to the Deploy tab of Remix.
1. Select "Injected Web3" in the Environment dropdown in the top left to connect Metamask.
2. Make sure that Metamask is connected to the Emerald (Testnet/Mainnet) network. You can read about adding Emerald network to Metamask [here](../../general/manage-tokens/#metamask).
1. Select "Injected Web3" in the Environment dropdown in the top left to
connect Metamask.
2. Make sure that Metamask is connected to the Sapphire Paratime
(Testnet/Mainnet) network. You can read about adding a network to Metamask [here](../../general/manage-tokens/#metamask).

![Setting up the environment in Remix](../images/emerald/band_demooracle_smartcontract.png)
![Setting up the environment in Remix](../images/tools/band_demooracle_smartcontract.png)

4. Enter the Emerald Testnet Band reference data aggregator contract address (`0x61704EFB8b8120c03C210cAC5f5193BF8c80852a`) to the `DemoOracle` constructor and deploy the contract. You can access the reference data aggregator contract on mainnet at `0xDA7a001b254CD22e46d3eAB04d937489c93174C3`.
4. Enter the Testnet Band reference data aggregator contract address
(`0x61704EFB8b8120c03C210cAC5f5193BF8c80852a`) to the `DemoOracle` constructor
and deploy the contract. You can access the reference data aggregator contract
on the Sapphire Mainnet at `0xDA7a001b254CD22e46d3eAB04d937489c93174C3`.

![Deploying DemoOracle](../images/emerald/band_deploy_demooracle_smartcontact.png)
![Deploying DemoOracle](../images/tools/band_deploy_demooracle_smartcontact.png)

An interface to interact with the contract will appear in the bottom left corner of Remix.
An interface to interact with the contract will appear in the bottom left
corner of Remix.

### Get Rates

Clicking the `getPrice` button will return the current price of WBTC in USD. This function calls `getReferenceData(string memory _base, string memory _quote)` on the Band reference data contract, passing "WBTC" and "USD", indicating WBTC as the base and USD as the quote. The rate returned is base/quote multiplied by 1e18.
Clicking the `getPrice` button will return the current price of WBTC in USD.
This function calls `getReferenceData(string memory _base, string memory _quote)`
on the Band reference data contract, passing "WBTC" and "USD", indicating WBTC
as the base and USD as the quote. The rate returned is base/quote multiplied by
1e18.

![Get Rates](../images/emerald/band_get_rates.png)
![Get Rates](../images/tools/band_get_rates.png)

Note that the `DemoOracle` contract only returns the latest rate, but the reference contract also returns values of the last time the base and quote references were updated.
Note that the `DemoOracle` contract only returns the latest rate, but the
reference contract also returns values of the last time the base and quote
references were updated.

The price is offset by 1e18. The returned value at the time of testing is `39567000000000000000000`. Multiplying by 1e-18 gives the current USD price given by the reference contract, 39567.00 WBTC/USD.
The price is offset by 1e18. The returned value at the time of testing is
`39567000000000000000000`. Multiplying by 1e-18 gives the current USD price
given by the reference contract, 39567.00 WBTC/USD.

Clicking the `getMultiPrices` button returns multiple quotes in the same call, WBTC/USD and ETH/USD in this case. This function calls `getReferenceDataBulk(string[] memory _bases, string[] memory _quotes)` on the Band reference data contract, passing "WBTC" and "ETH" as the base and "USD" for the quote. This will return the current WBTC and ETH prices in USD, as an array of integers. The call also returns just the exchange rates (multipilied by 1e18), but can be modified to return the last updated times for the bases and quotes.
Clicking the `getMultiPrices` button returns multiple quotes in the same call,
WBTC/USD and ETH/USD in this case. This function calls
`getReferenceDataBulk(string[] memory _bases, string[] memory _quotes)` on the
Band reference data contract, passing "WBTC" and "ETH" as the base and "USD"
for the quote. This will return the current WBTC and ETH prices in USD, as an
array of integers. The call also returns just the exchange rates (multipilied
by 1e18), but can be modified to return the last updated times for the bases
and quotes.

The `savePrice` function will save any base/quote rate that is passed to it in the storage variable named `price`. This storage data will only be updated when the “savePrice” function is called, so the saved `price` value will go stale unless this function is called repeatedly.
The `savePrice` function will save any base/quote rate that is passed to it in
the storage variable named `price`. This storage data will only be updated when
the “savePrice” function is called, so the saved `price` value will go stale
unless this function is called repeatedly.

![Save Price](../images/emerald/band_saveprice.png)
![Save Price](../images/tools/band_saveprice.png)

### Mainnet Reference Data Contract

You can access the reference data aggregator contract on Mainnet at [0xDA7a001b254CD22e46d3eAB04d937489c93174C3](https://explorer.oasis.io/mainnet/emerald/address/0xDA7a001b254CD22e46d3eAB04d937489c93174C3).
You can access the reference data aggregator contract on the Sapphire Mainnet
at [0xDA7a001b254CD22e46d3eAB04d937489c93174C3](https://explorer.oasis.io/mainnet/sapphire/address/0xDA7a001b254CD22e46d3eAB04d937489c93174C3).

### Available Reference Data

Expand All @@ -56,6 +99,9 @@ You can view the available reference data on the [Band Standard Dataset site her

### Bandchain.js {#bandchain}

Band also has a JavaScript library that makes it easy to interact with BandChain directly from JavaScript or TypeScript applications. The library provides classes and methods for convenient to send transactions, query data, OBI encoding, and wallet management. You can read more about it [here](https://docs.bandchain.org/develop/developer-tools/bandchain.js/getting-started).
Band also has a JavaScript library that makes it easy to interact with
BandChain directly from JavaScript or TypeScript applications. The library
provides classes and methods for convenient to send transactions, query data,
OBI encoding, and wallet management. You can read more about it [here](https://docs.bandchain.org/develop/developer-tools/bandchain.js/getting-started).

[demooracle-remix]: https://remix.ethereum.org/?#code=cHJhZ21hIHNvbGlkaXR5IDAuNi4xMTsKcHJhZ21hIGV4cGVyaW1lbnRhbCBBQklFbmNvZGVyVjI7CgppbnRlcmZhY2UgSVN0ZFJlZmVyZW5jZSB7CiAgICAvLy8gQSBzdHJ1Y3R1cmUgcmV0dXJuZWQgd2hlbmV2ZXIgc29tZW9uZSByZXF1ZXN0cyBmb3Igc3RhbmRhcmQgcmVmZXJlbmNlIGRhdGEuCiAgICBzdHJ1Y3QgUmVmZXJlbmNlRGF0YSB7CiAgICAgICAgdWludDI1NiByYXRlOyAvLyBiYXNlL3F1b3RlIGV4Y2hhbmdlIHJhdGUsIG11bHRpcGxpZWQgYnkgMWUxOC4KICAgICAgICB1aW50MjU2IGxhc3RVcGRhdGVkQmFzZTsgLy8gVU5JWCBlcG9jaCBvZiB0aGUgbGFzdCB0aW1lIHdoZW4gYmFzZSBwcmljZSBnZXRzIHVwZGF0ZWQuCiAgICAgICAgdWludDI1NiBsYXN0VXBkYXRlZFF1b3RlOyAvLyBVTklYIGVwb2NoIG9mIHRoZSBsYXN0IHRpbWUgd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mF0ZTsKICAgIH0KCiAgICBmdW5jdGlvbiBnZXRNdWx0aVByaWNlcygpIGV4dGVybmFsIHZpZXcgcmV0dXJucyAodWludDI1NltdIG1lbW9yeSl7CiAgICAgICAgc3RyaW5nW10gbWVtb3J5IGJhc2VTeW1ib2xzID0gbmV3IHN0cmluZ1tdKDIpOwogICAgICAgIGJhc2VTeW1ib2xzWzBdID0gIldCVEMiOwogICAgICAgIGJhc2VTeW1ib2xzWzFdID0gIkVUSCI7CgogICAgICAgIHN0cmluZ1tdIG1lbW9yeSBxdW90ZVN5bWJvbHMgPSBuZXcgc3RyaW5nW10oMik7CiAgICAgICAgcXVvdGVTeW1ib2xzWzBdID0gIlVTRCI7CiAgICAgICAgcXVvdGVTeW1ib2xzWzFdID0gIlVTRCI7CiAgICAgICAgSVN0ZFJlZmVyZW5jZS5SZWZlcmVuY2VEYXRhW10gbWVtb3J5IGRhdGEgPSByZWYuZ2V0UmVmZXJlbmNlRGF0YUJ1bGsoYmFzZVN5bWJvbHMscXVvdGVTeW1ib2xzKTsKCiAgICAgICAgdWludDI1NltdIG1lbW9yeSBwcmljZXMgPSBuZXcgdWludDI1NltdKDIpOwogICAgICAgIHByaWNlc1swXSA9IGRhdGFbMF0ucmF0ZTsKICAgICAgICBwcmljZXNbMV0gPSBkYXRhWzFdLnJhdGU7CgogICAgICAgIHJldHVybiBwcmljZXM7CiAgICB9CgogICAgZnVuY3Rpb24gc2F2ZVByaWNlKHN0cmluZyBtZW1vcnkgYmFzZSwgc3RyaW5nIG1lbW9yeSBxdW90ZSkgZXh0ZXJuYWwgewogICAgICAgIElTdGRSZWZlcmVuY2UuUmVmZXJlbmNlRGF0YSBtZW1vcnkgZGF0YSA9IHJlZi5nZXRSZWZlcmVuY2VEYXRhKGJhc2UscXVvdGUpOwogICAgICAgIHByaWNlID0gZGF0YS5yYXRlOwogICAgfQp9Cg==
4 changes: 4 additions & 0 deletions redirects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,10 @@ export const redirectsOptions: Options = {
to: 'https://api.docs.oasis.io/sol/sapphire-contracts',
from: '/dapp/sapphire/precompiles' // #688 Migrate dapp/sapphire/precompiles chapter to api.docs.oasis.io
},
{
to: '/dapp/tools/band',
from: '/dapp/emerald/integrating-band-oracle-smart-contract', // #907 Move Band oracle to Tools section
}
],
createRedirects(existingPath) {
// #119 Add /oasis-core/adr/* -> /adrs/* redirection
Expand Down
12 changes: 11 additions & 1 deletion sidebarDapp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,17 @@ export const sidebarDapp: SidebarsConfig = {
},
items: [
'dapp/emerald/writing-dapps-on-emerald',
'dapp/emerald/integrating-band-oracle-smart-contract',
],
},
{
type: 'category',
label: 'Tools & Services',
link: {
type: 'doc',
id: 'dapp/tools/README',
},
items: [
'dapp/tools/band',
],
},
],
Expand Down

0 comments on commit ea78598

Please sign in to comment.