Potential first oracle on Miden (DRAFT) #915
Replies: 2 comments 2 replies
-
Looks great! A few comments:
It is not clear to me if we need the
I think for now this can be done by directly executing a transaction against the oracle. And also, it doesn't really have to be the operator to make these updates. In fact, it might be better is an oracle is owned by some 3rd party service which periodically submits a transaction to update the oracle.
I think something between 5 - 10 blocks between updates should be OK - though, I'd probably keep it to 10 blocks to be on the safe side. In the future, we can investigate lowering this to potentially as little as 3 blocks.
I think anyone should be able to read the oracle directly using foreign procedure invocation (e.g., no need to send notes). For example, an oracle account could expose a procedure One key consideration for this procedure is how it will set transaction recency condition. For example, if the oracle is updated every 10 blocks, we may want to make sure that It may also be possible to implement "whitelists" for oracles - e.g., we can limit which accounts can call |
Beta Was this translation helpful? Give feedback.
-
Here are a couple of hints, how you can build the oracle and execute it. You can follow how a faucet is being created and executed. Oracle account code:The Oracle account can expose at minimum two functions, miden-base/miden-tx/tests/integration/scripts/faucet.rs Lines 234 to 252 in 6f54100 As for the account code, here is a simple example. You need to use the account procedures The "real" contract would look a bit more complex, but this could be a good start to see how things work.
Pushing data to the oracle:I would follow the integration test for minting tokens on a faucet, see miden-base/miden-tx/tests/integration/scripts/faucet.rs Lines 33 to 107 in 6f54100 The data provider can use a transaction script to push the data. It would look like this
whereas Reading data from the oracle:In a transaction, any account can read a certain storage slit using foreign procedure invocation. The final format will be defined next week. |
Beta Was this translation helpful? Give feedback.
-
An Oracle on Miden
Miden is supposed to be home to innovative DeFi solutions. Most DeFi solutions need price Oracles to query prices from other chains. For example, Perp Markets need frequent updates on the prices of the underlying assets.
Simple design
We hope to host many different Oracles in the future. A semi-mocked oracle will suffice for the current testnet. So, the design will be rather simple, but it should still serve as a PoC to see if the protocol can already support an oracle.
The Oracle account
A public account will serve as the Oracle account. In its storage, the asset prices will be stored. As long as there are not more than 254 different assets, we can use storage slots for simplicity. Later, storage maps can be used. Every storage slot can store a
Word
.Prices and assets can be encoded as
Word
in many ways, e.g.,(Base Asset / code Asset, price, publisher Id / decimals, timestamp)
. Every asset can have a certain ID, we can denominate the prices in $ or BTC, and the block height describes how old the information is.Miden operator pushes new prices
For now, we want a trusted Oracle source. The Miden operator will push new price updates at certain intervals. We need to figure our how exactly this will work.
Miden users can read account state
Once #847 is fully implemented, any Miden account can read the Oracle storage during transaction execution.
Open questions
Beta Was this translation helpful? Give feedback.
All reactions