Skip to content

Commit 04e574f

Browse files
authored
Add pre-commit to the repo (#40)
1 parent 3c2bf31 commit 04e574f

File tree

13 files changed

+74
-35
lines changed

13 files changed

+74
-35
lines changed
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Check Formatting
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches: [main]
7+
8+
jobs:
9+
pre-commit:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v2
13+
- uses: actions/setup-python@v2
14+
- uses: actions-rs/toolchain@v1
15+
with:
16+
profile: minimal
17+
toolchain: nightly
18+
components: rustfmt
19+
- uses: pre-commit/[email protected]

.pre-commit-config.yaml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v3.2.0
4+
hooks:
5+
- id: trailing-whitespace
6+
- id: end-of-file-fixer
7+
- id: check-added-large-files
8+
- repo: local
9+
hooks:
10+
- id: cargo-fmt-nightly
11+
name: Cargo Fmt Nightly
12+
language: "rust"
13+
entry: cargo +nightly fmt
14+
pass_filenames: false

README.md

+5
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,8 @@ To release a new version of any of these crates, perform the following steps wit
3636
2. Merge your change into `main` on github.
3737
3. Create and publish a new github release.
3838
We currently don't have a Github Action to automatically push releases to [crates.io](https://crates.io), but should set one up.
39+
40+
### pre-commit hooks
41+
pre-commit is a tool that checks and fixes simple issues (formatting, ...) before each commit. You can install it by following [their website](https://pre-commit.com/). In order to enable checks for this repo run `pre-commit install` from command-line in the root of this repo.
42+
43+
The checks are also performed in the CI to ensure the code follows consistent formatting.

examples/terra-contract/README.md

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# Pyth SDK Example Contract for Terra
22

3-
This repository contains an example contract that demonstrates how to read the Pyth price from the Pyth on-chain contract.
4-
The example [contract](src/contract.rs) has two functions:
3+
This repository contains an example contract that demonstrates how to read the Pyth price from the Pyth on-chain contract.
4+
The example [contract](src/contract.rs) has two functions:
55

6-
* `instantiate` sets the Pyth contract address and price feed id that the contract uses.
6+
* `instantiate` sets the Pyth contract address and price feed id that the contract uses.
77
This function is intended to be called once when the contract is deployed.
8-
See the [Terra SDK README](../../pyth-sdk-terra/README.md) for the list of possible price feed ids.
9-
* `query` queries the Pyth contract to get the current price for the configured price feed id.
8+
See the [Terra SDK README](../../pyth-sdk-terra/README.md) for the list of possible price feed ids.
9+
* `query` queries the Pyth contract to get the current price for the configured price feed id.
1010

1111
## Testnet Demo
1212

@@ -40,7 +40,7 @@ rpc error: code = Unknown desc = Generic error: Current price is not available:
4040
If you would like to deploy a changed version of this contract, the process consists of two steps:
4141

4242
1. Build the WASM for the contract.
43-
2. Upload the code and instantiate a new contract.
43+
2. Upload the code and instantiate a new contract.
4444

4545
### Build WASM
4646

@@ -50,7 +50,7 @@ The instructions in that document will build a file called `example_terra_contra
5050
### Upload and Instantiate Contract
5151

5252
The tools directory contains a deployment script that will upload a WASM file and instantiate a new contract with it.
53-
You can run that script on the built WASM file as follows:
53+
You can run that script on the built WASM file as follows:
5454

5555
``` sh
5656
cd tools/
@@ -76,7 +76,7 @@ By default, the deployment script sets the price feed to `Crypto.LUNA/USD` but y
7676

7777
### Querying the Contract
7878

79-
Once the contract is instantiated, you can query it by running:
79+
Once the contract is instantiated, you can query it by running:
8080

8181
```sh
8282
npm run query -- --network testnet --contract <contract address>
@@ -106,4 +106,4 @@ Contract terra1rhjej5gkyelw23uh22nadqlyjvtl7s5527er97 code_id successfully updat
106106
When deploying the contract, you may encounter gateway timeout or account sequence mismatch errors.
107107
If this happens, check terra finder to determine if your transaction succeeded -- sometimes transactions succeed despite timing out.
108108
Note that the deployment script submits multiple transactions.
109-
If any of them fails, simply rerun the entire script; there is no problem re-running the successful transactions.
109+
If any of them fails, simply rerun the entire script; there is no problem re-running the successful transactions.

examples/terra-contract/src/contract.rs

+11-10
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ pub fn instantiate(
4040
_info: MessageInfo,
4141
msg: InstantiateMsg,
4242
) -> StdResult<Response> {
43-
// It is a good practice that your contract stores the pyth contract address and ids of the price feeds
44-
// it needs upon instantiation or by an authorized approach. This will ensure that a wrong address won't
45-
// be used.
43+
// It is a good practice that your contract stores the pyth contract address and ids of the
44+
// price feeds it needs upon instantiation or by an authorized approach. This will ensure
45+
// that a wrong address won't be used.
4646
let state = State {
4747
pyth_contract_addr: deps.api.addr_validate(msg.pyth_contract_addr.as_ref())?,
4848
price_feed_id: msg.price_feed_id,
@@ -76,9 +76,10 @@ fn query_fetch_price(deps: Deps) -> StdResult<FetchPriceResponse> {
7676
let state = STATE.load(deps.storage)?;
7777

7878
// query_price_feed is the standard way to read the current price from a Pyth price feed.
79-
// It takes the address of the Pyth contract (which is fixed for each network) and the id of the price feed.
80-
// The result is a PriceFeed object with fields for the current price and other useful information.
81-
// The function will fail if the contract address or price feed id are invalid.
79+
// It takes the address of the Pyth contract (which is fixed for each network) and the id of the
80+
// price feed. The result is a PriceFeed object with fields for the current price and other
81+
// useful information. The function will fail if the contract address or price feed id are
82+
// invalid.
8283
let price_feed = query_price_feed(
8384
&deps.querier,
8485
state.pyth_contract_addr.into_string(),
@@ -88,11 +89,11 @@ fn query_fetch_price(deps: Deps) -> StdResult<FetchPriceResponse> {
8889

8990
// Get the current price and confidence interval from the price feed.
9091
// This function returns None if the price is not currently available.
91-
// This condition can happen for various reasons. For example, some products only trade at specific times, or
92-
// network outages may prevent the price feed from updating.
92+
// This condition can happen for various reasons. For example, some products only trade at
93+
// specific times, or network outages may prevent the price feed from updating.
9394
//
94-
// The example code below throws an error if the price is not available. It is recommended that you handle
95-
// this scenario more carefully. Consult the [consumer best practices](https://docs.pyth.network/consumers/best-practices)
95+
// The example code below throws an error if the price is not available. It is recommended that
96+
// you handle this scenario more carefully. Consult the [consumer best practices](https://docs.pyth.network/consumers/best-practices)
9697
// for recommendations.
9798
let current_price = price_feed
9899
.get_current_price()

examples/terra-contract/src/msg.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use pyth_sdk_terra::{
22
Price,
3-
PriceIdentifier
3+
PriceIdentifier,
44
};
55
use schemars::JsonSchema;
66
use serde::{
@@ -31,5 +31,5 @@ pub enum QueryMsg {
3131
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
3232
pub struct FetchPriceResponse {
3333
pub current_price: Price,
34-
pub ema_price: Price,
34+
pub ema_price: Price,
3535
}

examples/terra-contract/tools/deploy.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -234,4 +234,4 @@ function convert_terra_address_to_hex(human_addr) {
234234

235235
function sleep(ms) {
236236
return new Promise(resolve => setTimeout(resolve, ms));
237-
}
237+
}

examples/terra-contract/tools/query.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const CONFIG = {
2929
},
3030
}
3131
}
32-
32+
3333
const lcd = new LCDClient(CONFIG[argv.network].terraHost);
3434

3535

pyth-sdk-solana/README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Pyth Network Solana SDK
1+
# Pyth Network Solana SDK
22

33
This crate provides utilities for reading price feeds from the [pyth.network](https://pyth.network/) oracle on the Solana network.
44
It also includes several [off-chain example programs](examples/).
@@ -74,7 +74,7 @@ This library also provides several `load_*` methods that allow users to translat
7474
```rust
7575
use pyth_sdk_solana::state::*;
7676

77-
// replace with account data, either passed to on-chain program or from RPC node
77+
// replace with account data, either passed to on-chain program or from RPC node
7878
let price_account_data: Vec<u8> = ...;
7979
let price_account: &PriceAccount = load_price_account( &price_account_data ).unwrap();
8080

@@ -140,6 +140,6 @@ product_account .. 6MEwdxe4g1NeAF9u6KDG14anJpFsVEa2cvr5H6iriFZ8
140140

141141
## Development
142142

143-
This library can be built for either your native platform or in BPF (used by Solana programs).
143+
This library can be built for either your native platform or in BPF (used by Solana programs).
144144
Use `cargo build` / `cargo test` to build and test natively.
145-
Use `cargo build-bpf` / `cargo test-bpf` to build in BPF for Solana; these commands require you to have installed the [Solana CLI tools](https://docs.solana.com/cli/install-solana-cli-tools).
145+
Use `cargo build-bpf` / `cargo test-bpf` to build in BPF for Solana; these commands require you to have installed the [Solana CLI tools](https://docs.solana.com/cli/install-solana-cli-tools).

pyth-sdk-solana/test-contract/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
This contract is used to test pyth-sdk-solana onchain.
33

44
## Development
5-
Use `cargo build-bpf` / `cargo test-bpf` to build in BPF for Solana; these commands require you to have installed the [Solana CLI tools](https://docs.solana.com/cli/install-solana-cli-tools).
5+
Use `cargo build-bpf` / `cargo test-bpf` to build in BPF for Solana; these commands require you to have installed the [Solana CLI tools](https://docs.solana.com/cli/install-solana-cli-tools).
66

77
The BPF tests will also run an instruction count program that logs the resource consumption
88
of various library functions.

pyth-sdk-solana/test-contract/tests/stale_price.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ use common::test_instr_exec_ok;
1616

1717
fn price_account_all_zero() -> PriceAccount {
1818
PriceAccount {
19-
magic: MAGIC,
20-
ver: VERSION_2,
21-
atype: AccountType::Price as u32,
19+
magic: MAGIC,
20+
ver: VERSION_2,
21+
atype: AccountType::Price as u32,
2222
..Default::default()
2323
}
2424
}

pyth-sdk-terra/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,10 @@ List of available Price Feeds and their ids:
6565
| Crypto.BTC/USD | `0xf9c0172ba10dfa4d19088d94f5bf61d3b54d5bd7483a322a982e1373ee8ea31b` |
6666
| Crypto.ETH/USD | `0xca80ba6dc32e08d06f1aa886011eed1d77c77be9eb761cc10d72b7d0a2fd57a6` |
6767
| Crypto.LUNA/USD | `0x6de025a4cf28124f8ea6cb8085f860096dbc36d9c40002e221fc449337e065b2` |
68-
| Crypto.UST/USD | `0x026d1f1cf9f1c0ee92eb55696d3bd2393075b611c4f468ae5b967175edc4c25c` |
68+
| Crypto.UST/USD | `0x026d1f1cf9f1c0ee92eb55696d3bd2393075b611c4f468ae5b967175edc4c25c` |
6969
| Crypto.ALGO/USD | `0x08f781a893bc9340140c5f89c8a96f438bcfae4d1474cc0f688e3a52892c7318` |
7070

7171
Testnet price feeds update once per minute.
7272

7373
#### Notes
74-
- :warning: `num_publishers` and `max_num_publishers` in `PriceFeed` are currently unavailable and set to 0.
74+
- :warning: `num_publishers` and `max_num_publishers` in `PriceFeed` are currently unavailable and set to 0.

pyth-sdk/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Once you have a `PriceFeed`, you can call one of the methods below to get the pr
1616

1717
### Get the Current Price
1818

19-
Get the current price of the product from its `PriceFeed`:
19+
Get the current price of the product from its `PriceFeed`:
2020

2121
```rust
2222
let current_price: Price = price_feed.get_current_price().ok_or(StdError::not_found("Current price is not available"))?;
@@ -53,7 +53,7 @@ Applications can combine two USD prices to price an asset in a different quote c
5353
```rust
5454
let btc_usd: Price = ...;
5555
let eth_usd: Price = ...;
56-
// -8 is the desired exponent for the result
56+
// -8 is the desired exponent for the result
5757
let btc_eth: Price = btc_usd.get_price_in_quote(&eth_usd, -8);
5858
println!("BTC/ETH price: ({} +- {}) x 10^{}", price.price, price.conf, price.expo);
5959
```

0 commit comments

Comments
 (0)