Oracle Implementation Guide
Glittr contracts can require an oracle commitment to verify an off-chain agreement. Oracle commitments can be leveraged in any contract type, and serve as a modifier to that contract. There is a liveness assumption on part of the designated oracle signer, as these commitments are pre-signed and included directly in the Glittr transaction. See the oracle commitment page for more overview.
Oracle CommitmentsThe data format of the oracle commitment contains the signature (Schnorr) and the oracle message. Represented in typescript format, it looks like this:
The signature is Schnorr signature of sha256(bytes(JSON.stringified(message)))
.
The oracle message contains the following, which field you need to fill is entirely dependent on the application. The OracleMessage below is a structure of a simple price oracle, e.g. the oracle is saying that 1 BTC = $100,000. The asset_id is optional here for the dApp to verify if the ratio is for the correct currency pair.
Example:
At blockheight 878000 the price of 1 MeowToken is 80 USD. The oracle message is:
The dApp then will wrap the whole message into a part of a valid Glittr transaction and use this for example to mint a MeowToken-collateralized USD.
Example implementation
The example below is written using TypeScript and imports the glittr-sdk package and @noble/secp256k1 for the digital signature. The oracle here informs how much sats (bitcoin) is worth in USD. The glittr contract can use this to create collateralized USD, see the USD Contract
example for more.
Result:
The method to communicate between Oracle and dApp is not standardized, Oracle can for example provide an API or even communicate using other channels. As long as the message and signature are correct, dApp can use the oracle message as price information on glittr.
During contract execution, the glittr contract must specify which oracle public key to trust, so make sure as an Oracle you have published the public key.
Last updated