-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
4,414 additions
and
162 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
[package] | ||
name = "pyth-near-example" | ||
version = "0.1.0" | ||
authors = ["Pyth Data Association"] | ||
edition = "2021" | ||
description = "A Pyth Receiver for Near" | ||
|
||
[lib] | ||
name = "pyth_example" | ||
crate-type = ["cdylib", "lib"] | ||
|
||
[dependencies] | ||
byteorder = { version = "1.4.3" } | ||
hex = { version = "0.4.3" } | ||
near-sdk = { version = "4.1.1" } | ||
num-traits = { version = "0.2.15" } | ||
num-derive = { version = "0.3.3" } | ||
pythnet-sdk = { path = "../../../pythnet/pythnet_sdk" } | ||
pyth-near = { path = "../receiver", features = ["library"] } | ||
strum = { version = "0.24.1", features = ["derive"] } | ||
thiserror = { version = "1.0.38" } | ||
wormhole-core = { git = "https://github.com/wormhole-foundation/wormhole", rev = "4ddeca4dbdba50e2cbf6e603242f8c75d9246e2a" } | ||
|
||
[patch.crates-io] | ||
serde_wormhole = { git = "https://github.com/wormhole-foundation/wormhole", rev = "4ddeca4dbdba50e2cbf6e603242f8c75d9246e2a" } | ||
|
||
[dev-dependencies] | ||
lazy_static = { version = "1.4.0" } | ||
serde_json = { version = "1.0.91" } | ||
serde = { version = "1.0.152", features = ["derive"] } | ||
tokio = { version = "1.23.0", features = ["full"] } | ||
workspaces = { version = "0.7.0" } | ||
|
||
[profile.release] | ||
codegen-units = 1 | ||
opt-level = 3 | ||
lto = "fat" | ||
debug = false | ||
panic = "abort" | ||
overflow-checks = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
1.69.0-x86_64-unknown-linux-gnu |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
use { | ||
near_sdk::{ | ||
borsh::{ | ||
self, | ||
BorshDeserialize, | ||
BorshSerialize, | ||
}, | ||
env, | ||
is_promise_success, | ||
near_bindgen, | ||
AccountId, | ||
Gas, | ||
PanicOnDefault, | ||
Promise, | ||
PromiseError, | ||
}, | ||
pyth::state::PriceIdentifier, | ||
}; | ||
|
||
#[near_bindgen] | ||
#[derive(BorshDeserialize, BorshSerialize, PanicOnDefault)] | ||
pub struct PythExample { | ||
pyth: AccountId, | ||
} | ||
|
||
#[near_bindgen] | ||
impl PythExample { | ||
#[init] | ||
#[allow(clippy::new_without_default)] | ||
pub fn new(pyth: AccountId) -> Self { | ||
Self { pyth } | ||
} | ||
|
||
/// Get a Pyth Price Feed Result. | ||
#[payable] | ||
pub fn example_price_usage(&mut self, identifier: PriceIdentifier, data: String) -> Promise { | ||
pyth::ext::ext_pyth::ext(self.pyth.clone()) | ||
.with_static_gas(Gas(30_000_000_000_000)) | ||
.with_attached_deposit(env::attached_deposit()) | ||
.update_price_feeds(data) | ||
.then( | ||
pyth::ext::ext_pyth::ext(self.pyth.clone()) | ||
.get_price(identifier) | ||
.then( | ||
Self::ext(env::current_account_id()) | ||
.with_static_gas(Gas(10_000_000_000)) | ||
.handle_example_price_usage(), | ||
), | ||
) | ||
} | ||
|
||
#[payable] | ||
#[private] | ||
#[handle_result] | ||
pub fn handle_example_price_usage( | ||
&mut self, | ||
#[callback_result] _r: Result<Option<pyth::state::Price>, PromiseError>, | ||
) { | ||
if !is_promise_success() { | ||
return; | ||
} | ||
|
||
// Do things with Price Feed Result. | ||
} | ||
} |
Oops, something went wrong.