Skip to content
Merged
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
32 changes: 30 additions & 2 deletions Cargo.lock

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

8 changes: 7 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ members = [
"ata/core",
"ata",
"ata/methods",
"twap_oracle/core",
"twap_oracle",
"twap_oracle/methods",
"stablecoin/core",
"stablecoin",
"stablecoin/methods",
Expand All @@ -20,6 +23,7 @@ exclude = [
"amm/methods/guest",
"ata/methods/guest",
"stablecoin/methods/guest",
"twap_oracle/methods/guest"
]
resolver = "2"

Expand All @@ -32,10 +36,12 @@ amm_core = { path = "amm/core" }
amm_program = { path = "amm" }
ata_core = { path = "ata/core" }
ata_program = { path = "ata" }
twap_oracle_core = { path = "twap_oracle/core" }
twap_oracle_program = { path = "twap_oracle" }
stablecoin_core = { path = "stablecoin/core" }
stablecoin_program = { path = "stablecoin" }
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"] }
Expand Down
32 changes: 32 additions & 0 deletions artifacts/stablecoin-idl.json
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,38 @@
}
]
}
},
{
"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_id",
"type": "string"
},
{
"name": "confidence_interval",
"type": "u128"
}
]
}
}
],
"types": [
Expand Down
46 changes: 46 additions & 0 deletions artifacts/twap_oracle-idl.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"version": "0.1.0",
"name": "twap_oracle",
"instructions": [
{
"name": "noop",
"accounts": [],
"args": []
}
],
"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_id",
"type": "string"
},
{
"name": "confidence_interval",
"type": "u128"
}
]
}
}
],
"instruction_type": "twap_oracle_core::Instruction"
}
1 change: 1 addition & 0 deletions stablecoin/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ edition = "2021"
nssa_core = { git = "https://github.com/logos-blockchain/logos-execution-zone.git", tag = "v0.2.0-rc3", features = ["host"] }
borsh = { version = "1.5", features = ["derive"] }
serde = { version = "1.0", features = ["derive"] }
twap_oracle_core = { path = "../../twap_oracle/core" }
risc0-zkvm = { version = "=3.0.5", default-features = false }
spel-framework-macros = { git = "https://github.com/logos-co/spel.git", tag = "v0.3.0", package = "spel-framework-macros" }
16 changes: 14 additions & 2 deletions stablecoin/methods/guest/Cargo.lock

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

1 change: 1 addition & 0 deletions stablecoin/methods/guest/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ path = "src/bin/stablecoin.rs"
spel-framework = { git = "https://github.com/logos-co/spel.git", tag = "v0.3.0", package = "spel-framework" }
nssa_core = { git = "https://github.com/logos-blockchain/logos-execution-zone.git", tag = "v0.2.0-rc3" }
risc0-zkvm = { version = "=3.0.5", default-features = false }
twap_oracle_core = { path = "../../../twap_oracle/core" }
stablecoin_core = { path = "../../core" }
stablecoin_program = { path = "../..", package = "stablecoin_program" }
token_core = { path = "../../../token/core" }
Expand Down
8 changes: 8 additions & 0 deletions twap_oracle/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "twap_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"] }
twap_oracle_core = { path = "core" }
10 changes: 10 additions & 0 deletions twap_oracle/core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "twap_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"] }
borsh = { version = "1.5", features = ["derive"] }
serde = { version = "1.0", features = ["derive"] }
spel-framework-macros = { git = "https://github.com/logos-co/spel.git", tag = "v0.3.0", package = "spel-framework-macros" }
53 changes: 53 additions & 0 deletions twap_oracle/core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
use borsh::{BorshDeserialize, BorshSerialize};
use nssa_core::account::{AccountId, Data};
use serde::{Deserialize, Serialize};
use spel_framework_macros::account_type;

/// TWAP Oracle Program Instruction.
#[derive(Debug, Serialize, Deserialize)]
pub enum Instruction {
/// No-op instruction. Does nothing and returns no state changes.
Noop,
}

/// Canonical oracle price account consumed by LEZ programs.
///
/// Oracle producers own how this account is written; consumers only read and validate it.
#[account_type]
#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize, BorshSerialize, BorshDeserialize)]
pub struct OraclePriceAccount {
/// 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.
///
/// `u128` keeps the consumer-side interface non-negative; zero is rejected on read.
pub price: u128,
/// Price observation timestamp. Consumers choose the time unit by matching this with
/// `max_age`.
pub timestamp: u64,
/// Identifier of the source that populated this account, such as a TWAP or external adaptor.
pub source_id: String,
/// Source-provided confidence interval, or zero when the source does not provide one.
pub confidence_interval: u128,
}

impl TryFrom<&Data> for OraclePriceAccount {
type Error = std::io::Error;

fn try_from(data: &Data) -> Result<Self, Self::Error> {
Self::try_from_slice(data.as_ref())
}
}

impl From<&OraclePriceAccount> for Data {
fn from(price_account: &OraclePriceAccount) -> Self {
let serialized_len =
borsh::object_length(price_account).expect("Oracle price account length must be known");
let mut data = Vec::with_capacity(serialized_len);
BorshSerialize::serialize(price_account, &mut data)
.expect("Serialization to Vec should not fail");
Self::try_from(data).expect("Oracle price account encoded data should fit into Data")
}
}
14 changes: 14 additions & 0 deletions twap_oracle/methods/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[package]
name = "twap-oracle-methods"
version = "0.1.0"
edition = "2021"

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

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

[package.metadata.risc0]
methods = ["guest"]
3 changes: 3 additions & 0 deletions twap_oracle/methods/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
risc0_build::embed_methods();
}
Loading
Loading