-
Notifications
You must be signed in to change notification settings - Fork 1k
Add oracle pallet (part of Polkadot Stablecoin prerequisites) #9815
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 12 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
1895c1a
feat: Add pallet-oracle
indirection42 9df7d04
improve docs
indirection42 b9f596e
integrate oracle runtime api into kitchensink runtime
indirection42 2a3da59
cargo fmt
indirection42 01b352c
add prdoc
indirection42 46e9160
modify prdoc
indirection42 470b2f8
improve docs
indirection42 01e22ce
update license headers
xlc 30595df
fix
xlc c453bc3
fix
xlc ddc5794
Merge branch 'master' into honzon-oracle
xlc 2d0f184
fix
xlc 8f16896
refactor: streamline oracle pallet API by updating key functions and …
xlc 33cfdbc
feat: enhance oracle pallet with new PalletId and refine value retrie…
xlc 48cd4ef
fix
xlc f50fd10
Update substrate/frame/honzon/oracle/runtime-api/Cargo.toml
xlc 785fe89
Update substrate/frame/honzon/oracle/Cargo.toml
xlc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 hidden or 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 hidden or 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,19 @@ | ||
| # Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0 | ||
| # See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json | ||
|
|
||
| title: Introduce `pallet-oracle` | ||
|
|
||
| doc: | ||
| - audience: Runtime Dev | ||
| description: | | ||
| This PR is part of #9765 - Polkadot Stablecoin on AssetHub. It introduces `pallet-oracle`, a new FRAME pallet that provides a decentralized and trustworthy way to bring external, off-chain data onto the blockchain. The pallet allows a configurable set of oracle operators to feed data, such as prices, into the system, which can then be consumed by other pallets. | ||
|
|
||
| crates: | ||
| - name: kitchensink-runtime | ||
| bump: none | ||
| - name: pallet-oracle | ||
| bump: major | ||
| - name: pallet-oracle-runtime-api | ||
| bump: major | ||
| - name: polkadot-sdk | ||
| bump: minor |
This file contains hidden or 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 hidden or 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 hidden or 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,56 @@ | ||
| [package] | ||
| name = "pallet-oracle" | ||
| version = "1.0.0" | ||
| authors = ["Acala Developers"] | ||
| edition.workspace = true | ||
| license = "Apache-2.0" | ||
| homepage.workspace = true | ||
| repository.workspace = true | ||
| description = "FRAME oracle pallet for off-chain data" | ||
| readme = "README.md" | ||
|
|
||
| [lints] | ||
| workspace = true | ||
|
|
||
| [package.metadata.docs.rs] | ||
| targets = ["x86_64-unknown-linux-gnu"] | ||
|
|
||
| [dependencies] | ||
| codec = { features = ["derive"], workspace = true } | ||
| scale-info = { features = ["derive"], workspace = true } | ||
| serde = { workspace = true } | ||
|
|
||
| frame-benchmarking = { workspace = true, optional = true } | ||
| frame-support = { workspace = true } | ||
| frame-system = { workspace = true } | ||
| impl-trait-for-tuples = { workspace = true } | ||
| sp-application-crypto = { workspace = true } | ||
| sp-io = { workspace = true } | ||
| sp-runtime = { workspace = true } | ||
| sp-std = { workspace = true } | ||
|
|
||
| [features] | ||
| default = ["std"] | ||
| std = [ | ||
| "codec/std", | ||
| "frame-benchmarking?/std", | ||
| "frame-support/std", | ||
| "frame-system/std", | ||
| "scale-info/std", | ||
| "serde/std", | ||
| "sp-application-crypto/std", | ||
| "sp-io/std", | ||
| "sp-runtime/std", | ||
| "sp-std/std", | ||
| ] | ||
| runtime-benchmarks = [ | ||
| "frame-benchmarking/runtime-benchmarks", | ||
| "frame-support/runtime-benchmarks", | ||
| "frame-system/runtime-benchmarks", | ||
| "sp-runtime/runtime-benchmarks", | ||
| ] | ||
| try-runtime = [ | ||
| "frame-support/try-runtime", | ||
| "frame-system/try-runtime", | ||
| "sp-runtime/try-runtime", | ||
| ] | ||
This file contains hidden or 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,59 @@ | ||
| # pallet-oracle | ||
|
|
||
| ## Overview | ||
|
|
||
| The Oracle pallet provides a decentralized and trustworthy way to bring external, off-chain data onto the | ||
| blockchain. It allows a configurable set of oracle operators to feed data, such as prices, into the system. | ||
| This data can then be used by other pallets. | ||
|
|
||
| The pallet is designed to be flexible and can be configured to use different data sources and aggregation | ||
| strategies. | ||
|
|
||
| ## Key Concepts | ||
|
|
||
| - **Oracle Operators**: A set of trusted accounts that are authorized to submit data to the oracle. The pallet | ||
| uses the `frame_support::traits::SortedMembers` trait to manage the set of operators. This allows using pallets | ||
| like `pallet-membership` to manage the oracle members. | ||
| - **Data Feeds**: Operators feed data as key-value pairs. The `OracleKey` is used to identify the data being fed | ||
| (e.g., a specific currency pair), and the `OracleValue` is the data itself (e.g., the price). | ||
| - **Data Aggregation**: The pallet can be configured with a `CombineData` implementation to aggregate the raw | ||
| values submitted by individual operators into a single, trusted value. A default implementation | ||
| `DefaultCombineData` is provided, which takes the median of the values. | ||
| - **Timestamped Data**: All data submitted to the oracle is timestamped, allowing consumers of the data to know | ||
| how fresh it is. | ||
|
|
||
| ## Interface | ||
|
|
||
| ### Dispatchable Functions | ||
|
|
||
| - `feed_values` - Allows an authorized oracle operator to submit a set of key-value data points. | ||
|
|
||
| ### Public Functions | ||
|
|
||
| - `get` - Returns the aggregated and timestamped value for a given key. | ||
| - `get_all_values` - Returns all aggregated and timestamped values. | ||
| - `read_raw_values` - Returns the raw, un-aggregated values for a given key from all oracle operators. | ||
|
|
||
| ### Data Providers | ||
|
|
||
| The pallet implements the `DataProvider` and `DataProviderExtended` traits, allowing other pallets to easily | ||
| consume the oracle data. | ||
|
|
||
| ## Usage | ||
|
|
||
| To use the oracle pallet, you need to: | ||
|
|
||
| 1. **Add it to your runtime's `Cargo.toml`**. | ||
| 2. **Implement the `Config` trait** for the pallet in your runtime. This includes specifying: | ||
| - `OnNewData`: A hook to perform actions when new data is received. | ||
| - `CombineData`: The data aggregation strategy. | ||
| - `Time`: The time provider. | ||
| - `OracleKey`, `OracleValue`: The types for the data key and value. | ||
| - `RootOperatorAccountId`: An account with sudo-like permissions for the oracle. | ||
| - `Members`: The source of oracle operators. | ||
| 3. **Add the pallet to your runtime's `construct_runtime!` macro**. | ||
|
|
||
| Once configured, authorized operators can call `feed_values` to submit data, and other pallets can use the | ||
| `DataProvider` trait to read the aggregated data. | ||
|
|
||
| License: Apache-2.0 |
This file contains hidden or 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,25 @@ | ||
| [package] | ||
| name = "pallet-oracle-runtime-api" | ||
| version = "1.0.0" | ||
| authors = ["Acala Developers"] | ||
xlc marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| edition.workspace = true | ||
| license = "Apache-2.0" | ||
| homepage.workspace = true | ||
| repository.workspace = true | ||
| description = "Runtime API for the oracle pallet." | ||
|
|
||
| [dependencies] | ||
| codec = { workspace = true, features = ["derive"] } | ||
| scale-info = { workspace = true } | ||
| sp-api = { workspace = true } | ||
| sp-std = { workspace = true } | ||
|
|
||
|
|
||
| [features] | ||
| default = ["std"] | ||
| std = [ | ||
| "codec/std", | ||
| "scale-info/std", | ||
| "sp-api/std", | ||
| "sp-std/std", | ||
| ] | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.