Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Braindump: Onchain price oracle from Order Book DEX #194

Open
JoshOrndorff opened this issue Mar 16, 2024 · 0 comments
Open

Braindump: Onchain price oracle from Order Book DEX #194

JoshOrndorff opened this issue Mar 16, 2024 · 0 comments

Comments

@JoshOrndorff
Copy link
Contributor

AMM style DEXes are well known to provide an on-chain price oracle between the assets that trade in them. This price oracle acts as a positive externality for the entire ecosystem.

AMMs are not that well suited for UTXO chains and Order Books are naturally better. This concept is explored further in our order book dex tutorial.

So then the natural question is whether an order book dex can provide a price oracle as well. My intuition is that it can. Consider a centralized exchange. By looking at its spread and perhaps other order data, you get a good sense of what the market price is. The trick is that in the UTXO world it is only easy to "look" at all that data from off-chain.

Here I sketch out a simple on-chain price oracle built on top of the dex. It has some problems including incentivizing people to update it, but I think it may be the basis of something workable.


You build the order book in the usual way.
Then you also have a piece of state in a single utxo that is the "current oracle price".
Any transaction can peek at this "current oracle price" utxo when interacting with some defi thing that needs the price.
The price is updated by a transaction that peeks at some currently open offer and mutates the price accordingly. For example if the current oracle price is 1012 X/Y, but I see an open offer for 1015 X/Y then I can peek at that offer, consume to old oracle, and produce a new oracle with the same price.

It might be nice to have some way to indicate how wide the spread is too, but I'm not sure how to do that yet. My description above just guarantees that the price in somewhere in the spread assuming there is someone willing to diligently watch the book and update the spread.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant