Skip to content

Commit 15e7ddc

Browse files
authored
Update SDK for terra contract (#44)
* Update SDK for terra contract - Updates readme and docs according to the new price feed data format - Adds AsRef and some other traits to Identifier
1 parent 419ac1b commit 15e7ddc

File tree

7 files changed

+17
-9
lines changed

7 files changed

+17
-9
lines changed

examples/terra-contract/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ npm run query -- --network testnet --contract terra1fm4ssxq39m355pdv2wzxggf5uxs2
2525
If the query is successful, the output should look like:
2626
```
2727
{
28-
current_price: { price: 8704350000, conf: 3150000, expo: -8 },
29-
ema_price: { price: 8665158600, conf: 2965370, expo: -8 }
28+
current_price: { price: "8704350000", conf: "3150000", expo: -8 },
29+
ema_price: { price: "8665158600", conf: "2965370", expo: -8 }
3030
}
3131
```
3232

examples/terra-contract/src/contract.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ pub fn instantiate(
5151

5252
Ok(Response::new()
5353
.add_attribute("method", "instantiate")
54-
.add_attribute("price_id", format!("{:#x?}", msg.price_feed_id)))
54+
.add_attribute("price_id", format!("{}", msg.price_feed_id)))
5555
}
5656

5757
#[cfg_attr(not(feature = "library"), entry_point)]

examples/terra-contract/tools/deploy.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ if (argv.instantiate) {
181181
}
182182

183183
const contractAddress = await instantiate(codeId, {
184-
price_feed_id: Array.from(Buffer.from(pythPriceFeedId, "hex")),
184+
price_feed_id: pythPriceFeedId,
185185
pyth_contract_addr: pythContractAddress
186186
});
187187

pyth-sdk-terra/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "pyth-sdk-terra"
3-
version = "0.3.0"
3+
version = "0.3.1"
44
authors = ["Pyth Data Foundation"]
55
edition = "2018"
66
license = "Apache-2.0"
@@ -14,7 +14,7 @@ readme = "README.md"
1414
cosmwasm-std = { version = "0.16.0" }
1515
cosmwasm-storage = { version = "0.16.0" }
1616
serde = { version = "1.0.136", features = ["derive"] }
17-
pyth-sdk = { path = "../pyth-sdk", version = "0.4.0" }
17+
pyth-sdk = { path = "../pyth-sdk", version = "0.4.1" }
1818
schemars = "0.8.1"
1919

2020
[dev-dependencies]

pyth-sdk-terra/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Simply call the `query_price_feed` function in your Terra contract with a price
2222
// Pyth network testnet contract address
2323
pyth_contract_addr: string = "terra1hdc8q4ejy82kd9w7wj389dlul9z5zz9a36jflh";
2424
// Price feed id for BTC/USD on testnet
25-
price_feed_id: string = "0xf9c0172ba10dfa4d19088d94f5bf61d3b54d5bd7483a322a982e1373ee8ea31b";
25+
price_feed_id = PriceIdentifier::from_hex("f9c0172ba10dfa4d19088d94f5bf61d3b54d5bd7483a322a982e1373ee8ea31b");
2626

2727
let price_feed: PriceFeed = query_price_feed(deps.querier, pyth_contract_addr, price_feed_id)?.price_feed;
2828
let current_price: Price = price_feed.get_current_price().ok_or_else(|| StdError::not_found("price is not currently available"))?;
@@ -43,7 +43,7 @@ A typical query will look like:
4343
```
4444
{
4545
"price_feed": {
46-
"id": [249, 192, 23, ..., 163, 27] // id of the price feed as an array of bytes
46+
"id": "f9c0172ba10dfa4d19088d94f5bf61d3b54d5bd7483a322a982e1373ee8ea31b" // id of the price feed (in hex format)
4747
}
4848
}
4949
```

pyth-sdk/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "pyth-sdk"
3-
version = "0.4.0"
3+
version = "0.4.1"
44
authors = ["Pyth Data Foundation"]
55
edition = "2018"
66
license = "Apache-2.0"

pyth-sdk/src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ pub use price::Price;
1818
Default,
1919
PartialEq,
2020
Eq,
21+
PartialOrd,
22+
Ord,
23+
Hash,
2124
BorshSerialize,
2225
BorshDeserialize,
2326
serde::Serialize,
@@ -63,6 +66,11 @@ impl fmt::Display for Identifier {
6366
}
6467
}
6568

69+
impl AsRef<[u8]> for Identifier {
70+
fn as_ref(&self) -> &[u8] {
71+
&self.0[..]
72+
}
73+
}
6674

6775
/// Consists of 32 bytes and it is currently based on largest Public Key size on various
6876
/// blockchains.

0 commit comments

Comments
 (0)