Skip to content

Commit 9d8c271

Browse files
committed
feat(near): accumulators
1 parent 16832ab commit 9d8c271

File tree

17 files changed

+4414
-162
lines changed

17 files changed

+4414
-162
lines changed

target_chains/near/example/Cargo.lock

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

target_chains/near/example/Cargo.toml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
[package]
2+
name = "pyth-near-example"
3+
version = "0.1.0"
4+
authors = ["Pyth Data Association"]
5+
edition = "2021"
6+
description = "A Pyth Receiver for Near"
7+
8+
[lib]
9+
name = "pyth_example"
10+
crate-type = ["cdylib", "lib"]
11+
12+
[dependencies]
13+
byteorder = { version = "1.4.3" }
14+
hex = { version = "0.4.3" }
15+
near-sdk = { version = "4.1.1" }
16+
num-traits = { version = "0.2.15" }
17+
num-derive = { version = "0.3.3" }
18+
pythnet-sdk = { path = "../../../pythnet/pythnet_sdk" }
19+
pyth-near = { path = "../receiver", features = ["library"] }
20+
strum = { version = "0.24.1", features = ["derive"] }
21+
thiserror = { version = "1.0.38" }
22+
wormhole-core = { git = "https://github.com/wormhole-foundation/wormhole", rev = "4ddeca4dbdba50e2cbf6e603242f8c75d9246e2a" }
23+
24+
[patch.crates-io]
25+
serde_wormhole = { git = "https://github.com/wormhole-foundation/wormhole", rev = "4ddeca4dbdba50e2cbf6e603242f8c75d9246e2a" }
26+
27+
[dev-dependencies]
28+
lazy_static = { version = "1.4.0" }
29+
serde_json = { version = "1.0.91" }
30+
serde = { version = "1.0.152", features = ["derive"] }
31+
tokio = { version = "1.23.0", features = ["full"] }
32+
workspaces = { version = "0.7.0" }
33+
34+
[profile.release]
35+
codegen-units = 1
36+
opt-level = 3
37+
lto = "fat"
38+
debug = false
39+
panic = "abort"
40+
overflow-checks = true
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1.69.0-x86_64-unknown-linux-gnu

target_chains/near/example/src/lib.rs

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
use {
2+
near_sdk::{
3+
borsh::{
4+
self,
5+
BorshDeserialize,
6+
BorshSerialize,
7+
},
8+
env,
9+
is_promise_success,
10+
near_bindgen,
11+
AccountId,
12+
Gas,
13+
PanicOnDefault,
14+
Promise,
15+
PromiseError,
16+
},
17+
pyth::state::PriceIdentifier,
18+
};
19+
20+
#[near_bindgen]
21+
#[derive(BorshDeserialize, BorshSerialize, PanicOnDefault)]
22+
pub struct PythExample {
23+
pyth: AccountId,
24+
}
25+
26+
#[near_bindgen]
27+
impl PythExample {
28+
#[init]
29+
#[allow(clippy::new_without_default)]
30+
pub fn new(pyth: AccountId) -> Self {
31+
Self { pyth }
32+
}
33+
34+
/// Get a Pyth Price Feed Result.
35+
#[payable]
36+
pub fn example_price_usage(&mut self, identifier: PriceIdentifier, data: String) -> Promise {
37+
pyth::ext::ext_pyth::ext(self.pyth.clone())
38+
.with_static_gas(Gas(30_000_000_000_000))
39+
.with_attached_deposit(env::attached_deposit())
40+
.update_price_feeds(data)
41+
.then(
42+
pyth::ext::ext_pyth::ext(self.pyth.clone())
43+
.get_price(identifier)
44+
.then(
45+
Self::ext(env::current_account_id())
46+
.with_static_gas(Gas(10_000_000_000))
47+
.handle_example_price_usage(),
48+
),
49+
)
50+
}
51+
52+
#[payable]
53+
#[private]
54+
#[handle_result]
55+
pub fn handle_example_price_usage(
56+
&mut self,
57+
#[callback_result] _r: Result<Option<pyth::state::Price>, PromiseError>,
58+
) {
59+
if !is_promise_success() {
60+
return;
61+
}
62+
63+
// Do things with Price Feed Result.
64+
}
65+
}

0 commit comments

Comments
 (0)