Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 40 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@ members = [
"ata/core",
"ata",
"ata/methods",
"oracle/core",
"stablecoin/core",
"stablecoin",
"stablecoin/methods",
"mock_oracle/core",
"mock_oracle",
"mock_oracle/methods",
"integration_tests",
"tools/idl-gen",
]
Expand All @@ -20,6 +24,7 @@ exclude = [
"amm/methods/guest",
"ata/methods/guest",
"stablecoin/methods/guest",
"mock_oracle/methods/guest",
]
resolver = "2"

Expand All @@ -32,10 +37,13 @@ amm_core = { path = "amm/core" }
amm_program = { path = "amm" }
ata_core = { path = "ata/core" }
ata_program = { path = "ata" }
oracle_core = { path = "oracle/core" }
stablecoin_core = { path = "stablecoin/core" }
stablecoin_program = { path = "stablecoin" }
mock_oracle_core = { path = "mock_oracle/core" }
mock_oracle_program = { path = "mock_oracle" }
serde = { version = "1.0", features = ["derive"] }
borsh = { version = "1.0", features = ["derive"] }
borsh = { version = "1.5", features = ["derive"] }
risc0-zkvm = { version = "=3.0.5" }
serde_json = "1.0"
tokio = { version = "1.28.2", features = ["net", "rt-multi-thread", "sync", "macros"] }
78 changes: 78 additions & 0 deletions artifacts/mock_oracle-idl.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{
"version": "0.1.0",
"name": "mock_oracle",
"instructions": [
{
"name": "set_price",
"accounts": [
{
"name": "price_account",
"writable": false,
"signer": false,
"init": false
}
],
"args": [
{
"name": "base_asset",
"type": "account_id"
},
{
"name": "quote_asset",
"type": "account_id"
},
{
"name": "price",
"type": "u128"
},
{
"name": "timestamp",
"type": "u64"
},
{
"name": "source_identifier",
"type": "string"
},
{
"name": "confidence_interval",
"type": "u128"
}
]
}
],
"accounts": [
{
"name": "OraclePriceAccount",
"type": {
"kind": "struct",
"fields": [
{
"name": "base_asset",
"type": "account_id"
},
{
"name": "quote_asset",
"type": "account_id"
},
{
"name": "price",
"type": "u128"
},
{
"name": "timestamp",
"type": "u64"
},
{
"name": "source_identifier",
"type": "string"
},
{
"name": "confidence_interval",
"type": "u128"
}
]
}
}
],
"instruction_type": "mock_oracle_core::Instruction"
}
32 changes: 32 additions & 0 deletions artifacts/stablecoin-idl.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,38 @@
}
],
"accounts": [
{
"name": "OraclePriceAccount",
"type": {
"kind": "struct",
"fields": [
{
"name": "base_asset",
"type": "account_id"
},
{
"name": "quote_asset",
"type": "account_id"
},
{
"name": "price",
"type": "u128"
},
{
"name": "timestamp",
"type": "u64"
},
{
"name": "source_identifier",
"type": "string"
},
{
"name": "confidence_interval",
"type": "u128"
}
]
}
},
{
"name": "Position",
"type": {
Expand Down
9 changes: 9 additions & 0 deletions mock_oracle/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "mock_oracle_program"
version = "0.1.0"
edition = "2021"

[dependencies]
nssa_core = { git = "https://github.com/logos-blockchain/logos-execution-zone.git", tag = "v0.2.0-rc3", features = ["host"] }
mock_oracle_core = { path = "core" }
oracle_core = { path = "../oracle/core" }
9 changes: 9 additions & 0 deletions mock_oracle/core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "mock_oracle_core"
version = "0.1.0"
edition = "2021"

[dependencies]
nssa_core = { git = "https://github.com/logos-blockchain/logos-execution-zone.git", tag = "v0.2.0-rc3", features = ["host"] }
oracle_core = { path = "../../oracle/core" }
serde = { version = "1.0", features = ["derive"] }
55 changes: 55 additions & 0 deletions mock_oracle/core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
//! Core data structures for the Mock Oracle Program.

use nssa_core::account::AccountId;
use oracle_core::OraclePriceAccount;
use serde::{Deserialize, Serialize};

/// Source identifier written by default examples and tests for this mock oracle.
pub const MOCK_ORACLE_SOURCE_IDENTIFIER: &str = "mock-oracle";

/// Mock Oracle Program instruction.
#[derive(Debug, Serialize, Deserialize)]
pub enum Instruction {
/// Write a price into an authorized mock oracle account.
///
/// Required accounts (1):
/// - Price account (authorized, uninitialized or already owned by the Mock Oracle Program)
SetPrice {
base_asset: AccountId,
quote_asset: AccountId,
price: u128,
timestamp: u64,
source_identifier: String,
confidence_interval: u128,
},
}

/// Price payload accepted by the Mock Oracle Program.
#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]
pub struct PriceUpdate {
/// Canonical identifier for the priced asset.
pub base_asset: AccountId,
/// Canonical identifier for the quote asset that denominates `price`.
pub quote_asset: AccountId,
/// Amount of `quote_asset` one unit of `base_asset` is worth.
pub price: u128,
/// Price observation timestamp.
pub timestamp: u64,
/// Identifier of the mock source publishing this price.
pub source_identifier: String,
/// Source-provided confidence interval, or zero when unavailable.
pub confidence_interval: u128,
}

impl From<&PriceUpdate> for OraclePriceAccount {
fn from(update: &PriceUpdate) -> Self {
Self {
base_asset: update.base_asset,
quote_asset: update.quote_asset,
price: update.price,
timestamp: update.timestamp,
source_identifier: update.source_identifier.clone(),
confidence_interval: update.confidence_interval,
}
}
}
14 changes: 14 additions & 0 deletions mock_oracle/methods/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[package]
name = "mock-oracle-methods"
version = "0.1.0"
edition = "2021"

[build-dependencies]
risc0-build = "=3.0.5"

[dependencies]
risc0-zkvm = { version = "=3.0.5", features = ["std"] }
mock_oracle_core = { path = "../core" }

[package.metadata.risc0]
methods = ["guest"]
4 changes: 4 additions & 0 deletions mock_oracle/methods/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
//! Build script that embeds the mock oracle RISC Zero guest ELF as host-side constants.
fn main() {
risc0_build::embed_methods();
}
Loading
Loading