forked from MystenLabs/sui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move sui-oracle move package to public repo (MystenLabs#12922)
## 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
1 parent
5c8ac42
commit 89315cb
Showing
10 changed files
with
1,165 additions
and
4 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
Oops, something went wrong.