Skip to content

Commit

Permalink
move sui-oracle move package to public repo (MystenLabs#12922)
Browse files Browse the repository at this point in the history
## Description 

Sui Oracle is a general purpose oracle that can be used to fetch data
from external sources and feed it to the Sui Chain.
It is designed to be modular and extensible, so that it can be easily
extended to support new data sources and new data types.

## Test Plan 

Move test + manual integration tests

## TODOs
We need to add more documentation to explain the design of this package
and turn it into an example.

---
If your changes are not user-facing and not a breaking change, you can
skip the following section. Otherwise, please indicate what changed, and
then add to the Release Notes section as highlighted during the release
process.

### Type of Change (Check all that apply)

- [ ] protocol change
- [ ] user-visible impact
- [ ] breaking change for a client SDKs
- [ ] breaking change for FNs (FN binary must upgrade)
- [ ] breaking change for validators or node operators (must upgrade
binaries)
- [ ] breaking change for on-chain data layout
- [ ] necessitate either a data wipe or data migration

### Release notes
  • Loading branch information
patrickkuo authored Jan 9, 2024
1 parent 5c8ac42 commit 89315cb
Show file tree
Hide file tree
Showing 10 changed files with 1,165 additions and 4 deletions.
9 changes: 7 additions & 2 deletions Cargo.lock

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

12 changes: 10 additions & 2 deletions crates/sui-oracle/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ prometheus = "0.13.3"
tokio = { workspace = true, features = ["full"] }
tracing = "0.1.36"
once_cell.workspace = true
reqwest = { version = "0.11.13", default_features= false, features = ["blocking", "json", "rustls-tls"] }
reqwest = { version = "0.11.13", default_features = false, features = ["blocking", "json", "rustls-tls"] }
serde = { version = "1.0.144", features = ["derive", "rc"] }
serde_json = { version = "1.0.1"}
serde_json = { version = "1.0.1" }
jsonpath_lib = "0.3.0"
chrono.workspace = true
tap.workspace = true
Expand All @@ -28,3 +28,11 @@ sui-types = { path = "../sui-types" }
mysten-metrics = { path = "../mysten-metrics" }
telemetry-subscribers.workspace = true
workspace-hack.workspace = true

[dev-dependencies]
sui-keys = { path = "../sui-keys" }
sui-move-build = { path = "../sui-move-build" }
shared-crypto = { path = "../shared-crypto" }
bcs = "0.1.5"
rand = "0.8.5"
dirs = "4.0.0"
10 changes: 10 additions & 0 deletions crates/sui-oracle/move/oracle/Move.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "sui-oracle"
version = "0.0.1"

[dependencies]
Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "9d0fba4a490e1cf80101bbd4019c7bb1ccfce99b" }

[addresses]
oracle = "0x0"
sui = "0x2"
52 changes: 52 additions & 0 deletions crates/sui-oracle/move/oracle/sources/data.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

module oracle::data {
use std::string::String;

struct Data<T> has drop, copy {
value: T,
metadata: Metadata,
}

struct Metadata has drop, copy {
ticker: String,
sequence_number: u64,
timestamp: u64,
oracle: address,
/// An identifier for the reading (for example real time of observation, or sequence number of observation on other chain).
identifier: String,
}

public fun new<T>(
value: T,
ticker: String,
sequence_number: u64,
timestamp: u64,
oracle: address,
identifier: String
): Data<T> {
Data {
value,
metadata: Metadata {
ticker,
sequence_number,
timestamp,
oracle,
identifier,
},
}
}

public fun value<T>(data: &Data<T>): &T {
&data.value
}

public fun oracle_address<T>(data: &Data<T>): &address {
&data.metadata.oracle
}

public fun timestamp<T>(data: &Data<T>): u64 {
data.metadata.timestamp
}
}
21 changes: 21 additions & 0 deletions crates/sui-oracle/move/oracle/sources/decimal_value.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

module oracle::decimal_value {
struct DecimalValue has store, drop, copy {
value: u64,
decimal: u8,
}

public fun new(value: u64, decimal: u8): DecimalValue {
DecimalValue { value, decimal }
}

public fun value(self: &DecimalValue): u64 {
self.value
}

public fun decimal(self: &DecimalValue): u8 {
self.decimal
}
}
Loading

0 comments on commit 89315cb

Please sign in to comment.