You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
let (_, oracle_account_id) =AccountId::from_bech32(&oracle_bech32).unwrap();
197
202
198
203
// BTC/USD is identified by the faucet ID pair `1:0` (prefix 1, suffix 0).
@@ -322,16 +327,19 @@ The import `miden::tx` contains the `tx::execute_foreign_procedure` which we wil
322
327
#### Here's a breakdown of what the `get_price` procedure does:
323
328
324
329
1. Pushes the 16 foreign procedure inputs that `tx::execute_foreign_procedure` requires. The first four are the arguments to `get_median` — the BTC/USD faucet ID prefix `1`, suffix `0`, an `amount` of `0`, and a trailing `0` — and the remaining twelve are zero padding.
325
-
2. Pushes `0xd1aa2a8b38ccf58f37bb7aa490a8154c1cf89c537144ab23bd1111f13e5a28e8` onto the stack, which is the procedure root of the `get_median` procedure in the oracle.
330
+
2. Pushes `0xaa3a12d4e9de2dad37c50dba93809b9c17226d512e642d3d620c77088a85da71` onto the stack, which is the procedure root of the `get_median` procedure in the oracle.
326
331
3. Pushes the Pragma oracle account ID prefix and suffix.
327
332
4. Calls `tx::execute_foreign_procedure`, which invokes the `get_median` procedure via foreign procedure invocation. `get_median` returns `[is_tracked, median_price, amount]` on the stack.
328
333
329
334
Inside of the `masm/accounts/` directory, create the `oracle_reader.masm` file:
330
335
331
336
```masm
332
337
# The oracle account ID, procedure hash, and pair ID below reference
@@ -429,21 +437,21 @@ Stack state before step 11449:
429
437
├── 30: 0
430
438
└── 31: 0
431
439
432
-
View transaction on MidenScan: https://testnet.midenscan.com/tx/0x28dbb2ea1270884701e8f4875032db675ab9dfff13c3caaa5e53adfcf56e383b
440
+
View transaction on MidenScan: https://testnet.midenscan.com/tx/0xbf6048faa60c72c43ab5645d937d02d0d768ee4fdad3c64b736789fdf0ef6a44
433
441
```
434
442
435
-
The `get_median` procedure leaves three values on the stack. Index `0` holds `is_tracked` — `1` when Pragma tracks the requested pair. Index `1` holds the median price; in the output above it is `76307450000`, which is `$76307.45` once the 6 decimal places are applied. Index `2` holds the `amount` value that was passed into the call. Pragma publishes several price feeds on testnet; this tutorial reads the `BTC/USD` feed.
443
+
The `get_median` procedure leaves three values on the stack. Index `0` holds `is_tracked` — `1` when Pragma tracks the requested pair. Index `1` holds the median price as a raw fixed-point integer; in the output above it is `6439689500000`. The number of decimal places is defined by Pragma's feed (BTC/USD is published with 8 decimals), so this reading is about `$64,396.89`. Index `2` holds the `amount` value that was passed into the call. Pragma publishes several price feeds on testnet; this tutorial reads the `BTC/USD` feed.
436
444
437
445
### Running the tutorial
438
446
439
447
To run this tutorial end-to-end, navigate to the `rust-client` directory in the [miden-tutorials](https://github.com/0xMiden/miden-tutorials/) repository and run:
440
448
441
449
```bash
442
450
cd rust-client
443
-
cargo run --release --bin oracle_data_query -- <ORACLE_BECH32_ID>
451
+
cargo run --release --bin oracle_data_query
444
452
```
445
453
446
-
where `<ORACLE_BECH32_ID>` is Pragma's deployed oracleaccount ID on testnet.
454
+
This defaults to Pragma's current testnet oracle. To read from a different deployment, pass its bech32 account ID as an argument: `cargo run --release --bin oracle_data_query -- <ORACLE_BECH32_ID>`.
0 commit comments