Oracle Contract

//TODO: update//

To perform/validate the conversions between TOKENS, the Swap Contract, and the Fund Contract need to know the price of each Token in ADA. An Oracle will be used for this purpose.

A project wallet has permissions to mine an NFT (NFT ORACLE), create an UTxO at the contract address with that NFT and a DATUM (DATUM ORACLE) and consume that UTxO.

The DATUM contains a date and the price list on that date. The price list is a table of TOKEN / ADA pairs.

That DATUM remains INLINE in the UTxO in the contract and is accessible by reference in future transactions. When one of the contracts needs to validate conversions it will receive this DATUM and will verify that the NFT is present in that UTxO and that the date of the DATUM is not old (validity window).

When prices need to be updated that wallet is the only one that can consume the DATUM and create a new one with the updated values. This update must happen once per hour, to show on the site / front end an updated and on-demand price, before each transaction, with a validity window of 15 minutes.

If it is done 24 times a day, in cardan Fees will go about 0.5 ADA per transaction x 24 transactions = 12 ADA. Per month gives us: 12 * 31 = 372 ADA. That is our minimum value per month. But if there are many transactions, as the validity window is 15 minutes, we will have a maximum of 4 times per hour, per 24 hours = 4 * 24 * 0.5 = 48 ADA, which makes a month: 1488 ADA.

The oracle has two important points to take care of:

Price source:

A reliable source of prices. The community must consider those values as real.

That source must not be possible to alter and give us incorrect prices. This danger can be minimized if we have more than one price source and compare the prices that each one delivers. If they all agree, I can consider that price as valid.

A communication channel with that source that cannot be tampered with. If the channel is compromised it can cause us to store incorrect prices in our DATUM.

A first alternative is MinSwap BlockFrost Adapter (https://github.com/minswap/blockfrost-adapter).

Pricing sources to evaluate as an alternative:

Build our own "DEX Aggregator". Researching some of the most popular DEXs most of them have an API:

MinSwap: https://api-mainnet-prod.minswap.org/coinmarketcap/v2/pairs or the MinSwap BlockFrost Adapter. Source: https://forum.minswap.org/t/minswap-api-for-developers/738/3

MuesliSwap: https://docs.muesliswap.com/cardano/api/api-v1 and also https://twitter.com/cardanostra/status/1488522351985799173

SundaeSwap: https://stats.sundaeswap.finance/api/ example: curl --request GET --url https://stats.sundaeswap.finance/api/ticks/0029cb7c88c7567b63d1a512c0ed626aa169688ec980730c0473b913.70202d01/2022/09/02

WingRiders does not seem to have this service yet.

We would then have to create a service that pulls all that info from the different APIs, performs an aggregation to weight the price and post it on the blockchain as an inline datum according to what I commented in the previous point.

Last updated