Skip to content

Commit 4874e49

Browse files
authored
Add schema generation for pyth-sdk (#45)
* Add schema generation for pyth-sdk * Add comments + update action names
1 parent 15e7ddc commit 4874e49

File tree

6 files changed

+169
-4
lines changed

6 files changed

+169
-4
lines changed

.github/workflows/pyth-sdk-example-terra-contract.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ jobs:
3434
env:
3535
RUSTFLAGS: "-C link-arg=-s"
3636

37-
lints:
38-
name: Lints
37+
schema-check:
38+
name: Check schema changes are committed
3939
runs-on: ubuntu-latest
4040
defaults:
4141
run:

.github/workflows/pyth-sdk-terra.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ jobs:
2323
run: cargo build --verbose
2424
- name: Run tests
2525
run: cargo test --verbose
26-
lints:
27-
name: Lints
26+
schema-check:
27+
name: Check schema changes are committed
2828
runs-on: ubuntu-latest
2929
defaults:
3030
run:

.github/workflows/pyth-sdk.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,27 @@ jobs:
2525
run: cargo build --verbose
2626
- name: Run tests
2727
run: cargo test --verbose
28+
schema-check:
29+
name: Check schema changes are committed
30+
runs-on: ubuntu-latest
31+
defaults:
32+
run:
33+
working-directory: ./pyth-sdk
34+
steps:
35+
- name: Checkout sources
36+
uses: actions/checkout@v2
37+
38+
- name: Install stable toolchain
39+
uses: actions-rs/toolchain@v1
40+
with:
41+
profile: minimal
42+
toolchain: 1.58.1
43+
override: true
44+
components: clippy
45+
46+
- name: Generate Schema
47+
run: cargo run --example schema
48+
49+
- name: Schema Changes
50+
# fails if any changes not committed
51+
run: git diff --exit-code schema

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ Please see the documentation for the relevant crate to get started using Pyth Ne
2727
All crates in this repository can be built for either your native platform or blockchain-specific platforms.
2828
Use `cargo build` / `cargo test` to build and test natively.
2929

30+
### Schema Files
31+
32+
JSON Schema files are provided to allow others to work with the various Pyth structures in languages other than Rust. These are also used within Pyth’s own repositories, for example within the pyth-sdk-js repo. Every time these structures change, new Schema’s must be generated and committed via the cargo run --example schema command.
33+
34+
There is currently a CI check which ensures the schema files remain up-to-date.
35+
3036
### Creating a Release
3137

3238
To release a new version of any of these crates, perform the following steps within the crate being released:

pyth-sdk/examples/schema.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
use schemars::schema_for;
2+
use serde_json::to_string_pretty;
3+
use std::env::current_dir;
4+
use std::fs::{
5+
create_dir_all,
6+
write,
7+
};
8+
9+
use pyth_sdk::PriceFeed;
10+
11+
fn main() {
12+
let mut out_dir = current_dir().unwrap();
13+
out_dir.push("schema");
14+
create_dir_all(&out_dir).unwrap();
15+
16+
let schema = &schema_for!(PriceFeed);
17+
let json = to_string_pretty(schema).unwrap();
18+
let path = out_dir.join(format!("{}.json", "price_feed"));
19+
write(&path, json + "\n").unwrap();
20+
println!("Updated {}", path.to_str().unwrap());
21+
}

pyth-sdk/schema/price_feed.json

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-07/schema#",
3+
"title": "PriceFeed",
4+
"description": "Represents a current aggregation price from pyth publisher feeds.",
5+
"type": "object",
6+
"required": [
7+
"conf",
8+
"ema_conf",
9+
"ema_price",
10+
"expo",
11+
"id",
12+
"max_num_publishers",
13+
"num_publishers",
14+
"prev_conf",
15+
"prev_price",
16+
"prev_publish_time",
17+
"price",
18+
"product_id",
19+
"publish_time",
20+
"status"
21+
],
22+
"properties": {
23+
"conf": {
24+
"description": "Confidence interval around the current aggregation price.",
25+
"type": "string"
26+
},
27+
"ema_conf": {
28+
"description": "Exponentially moving average confidence interval.",
29+
"type": "string"
30+
},
31+
"ema_price": {
32+
"description": "Exponentially moving average price.",
33+
"type": "string"
34+
},
35+
"expo": {
36+
"description": "Price exponent.",
37+
"type": "integer",
38+
"format": "int32"
39+
},
40+
"id": {
41+
"description": "Unique identifier for this price.",
42+
"allOf": [
43+
{
44+
"$ref": "#/definitions/Identifier"
45+
}
46+
]
47+
},
48+
"max_num_publishers": {
49+
"description": "Maximum number of allowed publishers that can contribute to a price.",
50+
"type": "integer",
51+
"format": "uint32",
52+
"minimum": 0.0
53+
},
54+
"num_publishers": {
55+
"description": "Number of publishers that made up current aggregate.",
56+
"type": "integer",
57+
"format": "uint32",
58+
"minimum": 0.0
59+
},
60+
"prev_conf": {
61+
"description": "Confidence interval of previous aggregate with Trading status.",
62+
"type": "string"
63+
},
64+
"prev_price": {
65+
"description": "Price of previous aggregate with Trading status.",
66+
"type": "string"
67+
},
68+
"prev_publish_time": {
69+
"description": "Publish time of previous aggregate with Trading status.",
70+
"type": "integer",
71+
"format": "int64"
72+
},
73+
"price": {
74+
"description": "The current aggregation price.",
75+
"type": "string"
76+
},
77+
"product_id": {
78+
"description": "Product account key.",
79+
"allOf": [
80+
{
81+
"$ref": "#/definitions/Identifier"
82+
}
83+
]
84+
},
85+
"publish_time": {
86+
"description": "Current price aggregation publish time",
87+
"type": "integer",
88+
"format": "int64"
89+
},
90+
"status": {
91+
"description": "Status of price (Trading is valid).",
92+
"allOf": [
93+
{
94+
"$ref": "#/definitions/PriceStatus"
95+
}
96+
]
97+
}
98+
},
99+
"definitions": {
100+
"Identifier": {
101+
"type": "string"
102+
},
103+
"PriceStatus": {
104+
"description": "Represents availability status of a price feed.",
105+
"type": "string",
106+
"enum": [
107+
"Unknown",
108+
"Trading",
109+
"Halted",
110+
"Auction"
111+
]
112+
}
113+
}
114+
}

0 commit comments

Comments
 (0)