Skip to content

Commit e10ec85

Browse files
authored
Fix and improve terra sdk and example docs (#49)
* Fix and improve terra sdk and example docs * Update example contract to fix ui query
1 parent 5484ee5 commit e10ec85

File tree

7 files changed

+41
-15
lines changed

7 files changed

+41
-15
lines changed

examples/terra-contract/Developing.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ rustup target list --installed
1919
rustup target add wasm32-unknown-unknown
2020
```
2121

22+
This example uses relative paths in `Cargo.toml`; you must remove any `path` components within `Cargo.toml` dependencies if you intend to compile this code outside of the `pyth-sdk-terra` repository, otherwise this will fail to compile. For example:
23+
24+
```diff
25+
- pyth-sdk-terra = { version = "0.3.0", path = "../../pyth-sdk-terra" }
26+
+ pyth-sdk-terra = { version = "0.3.0" }
27+
```
28+
2229
## Compiling
2330

2431
After changing the contract, make sure you can compile and run it before
@@ -52,18 +59,20 @@ produce an extremely small build output in a consistent manner. The suggested wa
5259
to run it is this:
5360

5461
```sh
62+
cd path/to/cargo/root
5563
docker run --rm -v "$(pwd)":/code \
5664
--mount type=volume,source="$(basename "$(pwd)")_cache",target=/code/target \
5765
--mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \
58-
cosmwasm/rust-optimizer:0.12.4
66+
cosmwasm/rust-optimizer:0.12.6
5967
```
6068

6169
Or, If you're on an arm64 machine, you should use a docker image built with arm64.
6270
```sh
71+
cd path/to/cargo/root
6372
docker run --rm -v "$(pwd)":/code \
6473
--mount type=volume,source="$(basename "$(pwd)")_cache",target=/code/target \
6574
--mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \
66-
cosmwasm/rust-optimizer-arm64:0.12.4
75+
cosmwasm/rust-optimizer-arm64:0.12.6
6776
```
6877

6978
You must mount the contract code to `/code`. You can use a absolute path instead

examples/terra-contract/README.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ The example [contract](src/contract.rs) has two functions:
1010

1111
## Testnet Demo
1212

13-
This example contract is running on Terra testnet at `terra1fm4ssxq39m355pdv2wzxggf5uxs2ase4vga9qs`.
13+
This example contract is running on Terra testnet at `terra16h868tx50d3w37ry7c5lzzg648f7yetu39p5pd`.
1414
This contract has been instantiated to return the price of `Crypto.LUNA/USD`.
1515
You can query the contract from this repo by running:
1616

@@ -19,7 +19,14 @@ cd tools/
1919
# Install dependencies (if you haven't done so already)
2020
npm install
2121
# Query the contract
22-
npm run query -- --network testnet --contract terra1fm4ssxq39m355pdv2wzxggf5uxs2ase4vga9qs
22+
npm run query -- --network testnet --contract terra16h868tx50d3w37ry7c5lzzg648f7yetu39p5pd
23+
```
24+
25+
Or by going to the contract address in [Terra Finder](https://finder.terra.money/) you can query make a query like below:
26+
```
27+
{
28+
"fetch_price": {}
29+
}
2330
```
2431

2532
If the query is successful, the output should look like:
@@ -97,8 +104,8 @@ Storing WASM: ../artifacts/example_terra_contract.wasm (183749 bytes)
97104
Deploy fee: 44682uluna
98105
Code ID: 53227
99106
Sleeping for 10 seconds for store transaction to finalize.
100-
Migrating contract terra1rhjej5gkyelw23uh22nadqlyjvtl7s5527er97 to 53227
101-
Contract terra1rhjej5gkyelw23uh22nadqlyjvtl7s5527er97 code_id successfully updated to 53227
107+
Migrating contract terra123456789yelw23uh22nadqlyjvtl7s5527er97 to 53227
108+
Contract terra123456789yelw23uh22nadqlyjvtl7s5527er97 code_id successfully updated to 53227
102109
```
103110

104111
### Troubleshooting
Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
11
{
22
"$schema": "http://json-schema.org/draft-07/schema#",
33
"title": "QueryMsg",
4-
"type": "string",
5-
"enum": [
6-
"fetch_price"
4+
"oneOf": [
5+
{
6+
"type": "object",
7+
"required": [
8+
"fetch_price"
9+
],
10+
"properties": {
11+
"fetch_price": {
12+
"type": "object"
13+
}
14+
},
15+
"additionalProperties": false
16+
}
717
]
818
}

examples/terra-contract/src/contract.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ pub fn execute(
6868
#[cfg_attr(not(feature = "library"), entry_point)]
6969
pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult<Binary> {
7070
match msg {
71-
QueryMsg::FetchPrice => to_binary(&query_fetch_price(deps)?),
71+
QueryMsg::FetchPrice {} => to_binary(&query_fetch_price(deps)?),
7272
}
7373
}
7474

examples/terra-contract/src/msg.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub enum ExecuteMsg {}
2525
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2626
#[serde(rename_all = "snake_case")]
2727
pub enum QueryMsg {
28-
FetchPrice,
28+
FetchPrice {},
2929
}
3030

3131
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]

examples/terra-contract/tools/query.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,5 @@ const CONFIG = {
3333
const lcd = new LCDClient(CONFIG[argv.network].terraHost);
3434

3535

36-
let queryResult = await lcd.wasm.contractQuery(argv.contract, "fetch_price")
36+
let queryResult = await lcd.wasm.contractQuery(argv.contract, { "fetch_price": {} })
3737
console.log(queryResult)

pyth-sdk-terra/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ This struct also has some useful functions for manipulating and combining prices
3838
## Off-Chain Queries
3939

4040
You can use the provided schemas in the `schema` directory to directly query the terra contract from off-chain applications.
41-
A typical query will look like:
41+
A typical query requires to pass the price feed id as a hex string. it will look like:
4242

4343
```
4444
{
4545
"price_feed": {
46-
"id": "f9c0172ba10dfa4d19088d94f5bf61d3b54d5bd7483a322a982e1373ee8ea31b" // id of the price feed (in hex format)
46+
"id": "f9c0172ba10dfa4d19088d94f5bf61d3b54d5bd7483a322a982e1373ee8ea31b"
4747
}
4848
}
4949
```
@@ -56,7 +56,7 @@ Pyth is currently only available in Terra testnet.
5656

5757
### Testnet
5858

59-
The contract address is [`terra1hdc8q4ejy82kd9w7wj389dlul9z5zz9a36jflh`](https://finder.terra.money/testnet/address/terra1wzs3rgzgjdde3kg7k3aaz6qx7sc5dcwxqe9fuc).
59+
The contract address is [`terra1wzs3rgzgjdde3kg7k3aaz6qx7sc5dcwxqe9fuc`](https://finder.terra.money/testnet/address/terra1wzs3rgzgjdde3kg7k3aaz6qx7sc5dcwxqe9fuc).
6060

6161
List of available Price Feeds and their ids:
6262

0 commit comments

Comments
 (0)