Skip to content

Contracts and related for integration with Band protocol Oracle Network

License

Notifications You must be signed in to change notification settings

onflow/band-oracle-contracts

Band Oracle Contract

The Cadence smart contract enabling integration of the Band Protocol Oracle network. The oracle network offers ~100 cryptocurrency price quotes available to any Cadence applications, contracts or transactions.

To learn more about Band Protocol please refer to: https://faq.bandprotocol.com/

Contract Addresses

Name Testnet Mainnet
BandOracle 0x4772ee0aba864de9

How it works?

The contract keeps a record of symbols and the corresponding financial price data for them. While financial data are only updated by authorized BandChain relayers, they can be queried via a script by any user or application on the Flow blockchain.

Storing the data

Market for each symbol is stored on a dictionary as a contract level field access(contract) let symbolsRefData: {String: RefData}. The RefData structs stores the following information:

    pub struct RefData {
        // USD-rate, multiplied by 1e9.
        pub var rate: UInt64
        // UNIX epoch when data is last resolved. 
        pub var timestamp: UInt64
        // BandChain request identifier for this data.
        pub var requestID: UInt64
    }

This struct provides the caller with the data received from the oracle network for the symbol in question. Keep in mind that all data is normalized and stored using a USD conversion rate, meaning that conversions into other symbols will derive from that.

Updating the data

The account where the contract is deployed will be granted an OracleAdmin resource. This resource can create DataUpdater resources and publish a {&RelayUpdate} capability to them. An authorized account - belonging to a relayer - can claim said capability at the time of creating a Relay resource. This resource will grant the ability to call the updateData method that will call contract function access(contract) fun updateRefData (symbolsRates: {String: UInt64}, resolveTime: UInt64, requestID: UInt64) which in turn updates the symbolsRefData dictionary.

Querying the data

When invoking the public function pub fun getReferenceData (baseSymbol: String, quoteSymbol: String): RefData? calling contracts or scripts would be provided the price corresponding to quoteSymbol in the baseSymbol currency. If there are no entries registered for either the base or quote symbols the function will return nil.

Fees

[TBD]

About

Contracts and related for integration with Band protocol Oracle Network

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published