Skip to content

Commit 18b1479

Browse files
author
Dev Kalra
authored
[cosmwasm] generate schema (#515)
* schema gen * include bin for schema gen * update cosmwasm compiler * update compiler version * update their sha digest
1 parent a7accad commit 18b1479

File tree

8 files changed

+387
-18
lines changed

8 files changed

+387
-18
lines changed

target-chains/cosmwasm/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
artifacts/
2+
!bin

target-chains/cosmwasm/Cargo.lock

Lines changed: 25 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

target-chains/cosmwasm/build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ docker run --rm -v "$(pwd)":/code \
44
-v $(cd ../../third_party; pwd):/third_party \
55
--mount type=volume,source="$(basename "$(pwd)")_cache",target=/code/target \
66
--mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \
7-
cosmwasm/workspace-optimizer:0.12.6
7+
cosmwasm/workspace-optimizer:0.12.11

target-chains/cosmwasm/contracts/pyth/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ bigint = "4"
3131
p2w-sdk = { path = "../../../../third_party/pyth/p2w-sdk/rust" }
3232
pyth-sdk = "0.7.0"
3333
byteorder = "1.4.3"
34+
cosmwasm-schema = "1.1.9"
3435

3536
[dev-dependencies]
3637
cosmwasm-vm = { version = "1.0.0", default-features = false }
Lines changed: 319 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,319 @@
1+
{
2+
"contract_name": "pyth-cosmwasm",
3+
"contract_version": "0.1.0",
4+
"idl_version": "1.0.0",
5+
"instantiate": {
6+
"$schema": "http://json-schema.org/draft-07/schema#",
7+
"title": "InstantiateMsg",
8+
"type": "object",
9+
"required": [
10+
"chain_id",
11+
"data_sources",
12+
"fee",
13+
"governance_sequence_number",
14+
"governance_source",
15+
"governance_source_index",
16+
"valid_time_period_secs",
17+
"wormhole_contract"
18+
],
19+
"properties": {
20+
"chain_id": {
21+
"type": "integer",
22+
"format": "uint16",
23+
"minimum": 0.0
24+
},
25+
"data_sources": {
26+
"type": "array",
27+
"items": {
28+
"$ref": "#/definitions/PythDataSource"
29+
}
30+
},
31+
"fee": {
32+
"$ref": "#/definitions/Coin"
33+
},
34+
"governance_sequence_number": {
35+
"type": "integer",
36+
"format": "uint64",
37+
"minimum": 0.0
38+
},
39+
"governance_source": {
40+
"$ref": "#/definitions/PythDataSource"
41+
},
42+
"governance_source_index": {
43+
"type": "integer",
44+
"format": "uint32",
45+
"minimum": 0.0
46+
},
47+
"valid_time_period_secs": {
48+
"type": "integer",
49+
"format": "uint16",
50+
"minimum": 0.0
51+
},
52+
"wormhole_contract": {
53+
"type": "string"
54+
}
55+
},
56+
"additionalProperties": false,
57+
"definitions": {
58+
"Binary": {
59+
"description": "Binary is a wrapper around Vec<u8> to add base64 de/serialization with serde. It also adds some helper methods to help encode inline.\n\nThis is only needed as serde-json-{core,wasm} has a horrible encoding for Vec<u8>",
60+
"type": "string"
61+
},
62+
"Coin": {
63+
"type": "object",
64+
"required": ["amount", "denom"],
65+
"properties": {
66+
"amount": {
67+
"$ref": "#/definitions/Uint128"
68+
},
69+
"denom": {
70+
"type": "string"
71+
}
72+
}
73+
},
74+
"PythDataSource": {
75+
"type": "object",
76+
"required": ["chain_id", "emitter"],
77+
"properties": {
78+
"chain_id": {
79+
"type": "integer",
80+
"format": "uint16",
81+
"minimum": 0.0
82+
},
83+
"emitter": {
84+
"$ref": "#/definitions/Binary"
85+
}
86+
}
87+
},
88+
"Uint128": {
89+
"description": "A thin wrapper around u128 that is using strings for JSON encoding/decoding, such that the full u128 range can be used for clients that convert JSON numbers to floats, like JavaScript and jq.\n\n# Examples\n\nUse `from` to create instances of this and `u128` to get the value out:\n\n``` # use cosmwasm_std::Uint128; let a = Uint128::from(123u128); assert_eq!(a.u128(), 123);\n\nlet b = Uint128::from(42u64); assert_eq!(b.u128(), 42);\n\nlet c = Uint128::from(70u32); assert_eq!(c.u128(), 70); ```",
90+
"type": "string"
91+
}
92+
}
93+
},
94+
"execute": {
95+
"$schema": "http://json-schema.org/draft-07/schema#",
96+
"title": "ExecuteMsg",
97+
"oneOf": [
98+
{
99+
"type": "object",
100+
"required": ["update_price_feeds"],
101+
"properties": {
102+
"update_price_feeds": {
103+
"type": "object",
104+
"required": ["data"],
105+
"properties": {
106+
"data": {
107+
"type": "array",
108+
"items": {
109+
"$ref": "#/definitions/Binary"
110+
}
111+
}
112+
},
113+
"additionalProperties": false
114+
}
115+
},
116+
"additionalProperties": false
117+
},
118+
{
119+
"type": "object",
120+
"required": ["execute_governance_instruction"],
121+
"properties": {
122+
"execute_governance_instruction": {
123+
"type": "object",
124+
"required": ["data"],
125+
"properties": {
126+
"data": {
127+
"$ref": "#/definitions/Binary"
128+
}
129+
},
130+
"additionalProperties": false
131+
}
132+
},
133+
"additionalProperties": false
134+
}
135+
],
136+
"definitions": {
137+
"Binary": {
138+
"description": "Binary is a wrapper around Vec<u8> to add base64 de/serialization with serde. It also adds some helper methods to help encode inline.\n\nThis is only needed as serde-json-{core,wasm} has a horrible encoding for Vec<u8>",
139+
"type": "string"
140+
}
141+
}
142+
},
143+
"query": {
144+
"$schema": "http://json-schema.org/draft-07/schema#",
145+
"title": "QueryMsg",
146+
"oneOf": [
147+
{
148+
"type": "string",
149+
"enum": ["get_valid_time_period"]
150+
},
151+
{
152+
"type": "object",
153+
"required": ["price_feed"],
154+
"properties": {
155+
"price_feed": {
156+
"type": "object",
157+
"required": ["id"],
158+
"properties": {
159+
"id": {
160+
"$ref": "#/definitions/Identifier"
161+
}
162+
},
163+
"additionalProperties": false
164+
}
165+
},
166+
"additionalProperties": false
167+
},
168+
{
169+
"type": "object",
170+
"required": ["get_update_fee"],
171+
"properties": {
172+
"get_update_fee": {
173+
"type": "object",
174+
"required": ["vaas"],
175+
"properties": {
176+
"vaas": {
177+
"type": "array",
178+
"items": {
179+
"$ref": "#/definitions/Binary"
180+
}
181+
}
182+
},
183+
"additionalProperties": false
184+
}
185+
},
186+
"additionalProperties": false
187+
}
188+
],
189+
"definitions": {
190+
"Binary": {
191+
"description": "Binary is a wrapper around Vec<u8> to add base64 de/serialization with serde. It also adds some helper methods to help encode inline.\n\nThis is only needed as serde-json-{core,wasm} has a horrible encoding for Vec<u8>",
192+
"type": "string"
193+
},
194+
"Identifier": {
195+
"type": "string"
196+
}
197+
}
198+
},
199+
"migrate": {
200+
"$schema": "http://json-schema.org/draft-07/schema#",
201+
"title": "MigrateMsg",
202+
"type": "object",
203+
"additionalProperties": false
204+
},
205+
"sudo": null,
206+
"responses": {
207+
"get_update_fee": {
208+
"$schema": "http://json-schema.org/draft-07/schema#",
209+
"title": "Coin",
210+
"type": "object",
211+
"required": ["amount", "denom"],
212+
"properties": {
213+
"amount": {
214+
"$ref": "#/definitions/Uint128"
215+
},
216+
"denom": {
217+
"type": "string"
218+
}
219+
},
220+
"definitions": {
221+
"Uint128": {
222+
"description": "A thin wrapper around u128 that is using strings for JSON encoding/decoding, such that the full u128 range can be used for clients that convert JSON numbers to floats, like JavaScript and jq.\n\n# Examples\n\nUse `from` to create instances of this and `u128` to get the value out:\n\n``` # use cosmwasm_std::Uint128; let a = Uint128::from(123u128); assert_eq!(a.u128(), 123);\n\nlet b = Uint128::from(42u64); assert_eq!(b.u128(), 42);\n\nlet c = Uint128::from(70u32); assert_eq!(c.u128(), 70); ```",
223+
"type": "string"
224+
}
225+
}
226+
},
227+
"get_valid_time_period": {
228+
"$schema": "http://json-schema.org/draft-07/schema#",
229+
"title": "Duration",
230+
"type": "object",
231+
"required": ["nanos", "secs"],
232+
"properties": {
233+
"nanos": {
234+
"type": "integer",
235+
"format": "uint32",
236+
"minimum": 0.0
237+
},
238+
"secs": {
239+
"type": "integer",
240+
"format": "uint64",
241+
"minimum": 0.0
242+
}
243+
}
244+
},
245+
"price_feed": {
246+
"$schema": "http://json-schema.org/draft-07/schema#",
247+
"title": "PriceFeedResponse",
248+
"type": "object",
249+
"required": ["price_feed"],
250+
"properties": {
251+
"price_feed": {
252+
"$ref": "#/definitions/PriceFeed"
253+
}
254+
},
255+
"additionalProperties": false,
256+
"definitions": {
257+
"Identifier": {
258+
"type": "string"
259+
},
260+
"Price": {
261+
"description": "A price with a degree of uncertainty at a certain time, represented as a price +- a confidence interval.\n\nPlease refer to the documentation at https://docs.pyth.network/consumers/best-practices for using this price safely.\n\nThe confidence interval roughly corresponds to the standard error of a normal distribution. Both the price and confidence are stored in a fixed-point numeric representation, `x * 10^expo`, where `expo` is the exponent. For example:\n\n``` use pyth_sdk::Price; Price { price: 12345, conf: 267, expo: -2, publish_time: 100 }; // represents 123.45 +- 2.67 published at UnixTimestamp 100 Price { price: 123, conf: 1, expo: 2, publish_time: 100 }; // represents 12300 +- 100 published at UnixTimestamp 100 ```\n\n`Price` supports a limited set of mathematical operations. All of these operations will propagate any uncertainty in the arguments into the result. However, the uncertainty in the result may overestimate the true uncertainty (by at most a factor of `sqrt(2)`) due to computational limitations. Furthermore, all of these operations may return `None` if their result cannot be represented within the numeric representation (e.g., the exponent is so small that the price does not fit into an i64). Users of these methods should (1) select their exponents to avoid this problem, and (2) handle the `None` case gracefully.",
262+
"type": "object",
263+
"required": ["conf", "expo", "price", "publish_time"],
264+
"properties": {
265+
"conf": {
266+
"description": "Confidence interval.",
267+
"type": "string"
268+
},
269+
"expo": {
270+
"description": "Exponent.",
271+
"type": "integer",
272+
"format": "int32"
273+
},
274+
"price": {
275+
"description": "Price.",
276+
"type": "string"
277+
},
278+
"publish_time": {
279+
"description": "Publish time.",
280+
"type": "integer",
281+
"format": "int64"
282+
}
283+
}
284+
},
285+
"PriceFeed": {
286+
"description": "Represents a current aggregation price from pyth publisher feeds.",
287+
"type": "object",
288+
"required": ["ema_price", "id", "price"],
289+
"properties": {
290+
"ema_price": {
291+
"description": "Exponentially-weighted moving average (EMA) price.",
292+
"allOf": [
293+
{
294+
"$ref": "#/definitions/Price"
295+
}
296+
]
297+
},
298+
"id": {
299+
"description": "Unique identifier for this price.",
300+
"allOf": [
301+
{
302+
"$ref": "#/definitions/Identifier"
303+
}
304+
]
305+
},
306+
"price": {
307+
"description": "Price.",
308+
"allOf": [
309+
{
310+
"$ref": "#/definitions/Price"
311+
}
312+
]
313+
}
314+
}
315+
}
316+
}
317+
}
318+
}
319+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
use {
2+
cosmwasm_schema::write_api,
3+
pyth_cosmwasm::msg::{
4+
ExecuteMsg,
5+
InstantiateMsg,
6+
MigrateMsg,
7+
QueryMsg,
8+
},
9+
};
10+
11+
fn main() {
12+
write_api! {
13+
instantiate: InstantiateMsg,
14+
execute: ExecuteMsg,
15+
migrate: MigrateMsg,
16+
query: QueryMsg
17+
}
18+
}

0 commit comments

Comments
 (0)