Pavel Strakhov 71d6a89aea chore: Rust toolchain/CI update and workspace setup (#2830) пре 4 месеци
..
.cargo ee21688c45 feat(target_chains/ethereum): add arbirum stylus sdk (#2041) пре 9 месеци
benches ee21688c45 feat(target_chains/ethereum): add arbirum stylus sdk (#2041) пре 9 месеци
contracts 71d6a89aea chore: Rust toolchain/CI update and workspace setup (#2830) пре 4 месеци
examples ee21688c45 feat(target_chains/ethereum): add arbirum stylus sdk (#2041) пре 9 месеци
pyth-mock-solidity 74d1fc89b0 chore(js): update fix:fmt config (#2514) пре 8 месеци
scripts 71d6a89aea chore: Rust toolchain/CI update and workspace setup (#2830) пре 4 месеци
.gitignore ee21688c45 feat(target_chains/ethereum): add arbirum stylus sdk (#2041) пре 9 месеци
Cargo.lock ee21688c45 feat(target_chains/ethereum): add arbirum stylus sdk (#2041) пре 9 месеци
Cargo.toml ee21688c45 feat(target_chains/ethereum): add arbirum stylus sdk (#2041) пре 9 месеци
GUIDELINES.md ee21688c45 feat(target_chains/ethereum): add arbirum stylus sdk (#2041) пре 9 месеци
README.md ee21688c45 feat(target_chains/ethereum): add arbirum stylus sdk (#2041) пре 9 месеци

README.md

Pyth Stylus SDK

This package provides utilities for consuming prices from the Pyth Network Oracle in Rust with Stylus. It also includes the Pyth Interface ABI, which can be used in your libraries to interact with the Pyth contract.

It is strongly recommended to follow the consumer best practices when consuming data from Pyth.

Features

  • Integrates with the [pyth-solidity-contracts] library for external calls to Pyth smart contracts.
  • Provides first-class no_std support.
  • Includes Solidity constructors powered by [koba].
  • Supports both [unit] and [integration] test affordances for thorough testing.

Installation

To add the Stylus Contracts from crates.io, add the following line to your Cargo.toml (pinning to a specific version is recommended):

[dependencies]
pyth-stylus = "0.1.0"

For the latest changes from the main branch, you can also specify a git dependency:

[dependencies]
pyth-stylus = { git = "https://github.com/pyth-network/pyth-crosschain.git" }

Example Usage

To consume prices, use the functions interface. Be sure to read the function documentation to ensure safe use of price data.

For example, to read the latest price, call getPriceNoOlderThan with the Price ID of the price feed you are interested in:

You can interact directly with the Pyth contract, which implements the IPyth functions, instead of using call functions:

#![cfg_attr(not(test), no_std, no_main)]
extern crate alloc;

use stylus_sdk::prelude::{entrypoint, public, sol_storage};
use pyth_stylus::pyth::pyth_contract::PythContract;

sol_storage! {
    #[entrypoint]
    struct ProxyCallsExample {
        #[borrow]
        PythContract pyth;
    }
}

#[public]
#[inherit(PythContract)]
impl ProxyCallsExample {
}

Mocking Pyth

MockPyth is a mock contract that can be deployed locally to simulate Pyth contract behavior. To set and update price feeds, call updatePriceFeeds and provide an array of encoded price feeds as the argument. Encoded price feeds can be created using the create_price_feed_update_data function in the mock contract, which is also available in the functions module.

Test Documentation

Running Unit Tests for pyth-stylus

To run all the unit tests for the pyth-stylus package with all its features enabled, use the following command:

cargo test -p pyth-stylus --all-features

This command will:

  • Target the pyth-stylus package specifically (-p pyth-stylus).
  • Enable all features defined in the package during the test run (--all-features).

Running End-to-End Tests

To run the end-to-end tests for pyth-stylus, follow these steps:

  1. Start the test node:

    ./scripts/nitro-testnode.sh
    
  2. Run the end-to-end tests:

    ./scripts/e2e-tests.sh
    

Releases

We use Semantic Versioning for our releases. To release a new version of this package and publish it to npm, follow these steps:

  1. Run npm version <new version number> --no-git-tag-version to update the package version, then push your changes to GitHub.
  2. Once the change is merged into main, create a release with the tag v<new version number>, such as v1.5.2. A GitHub action will automatically publish the new version of the package to npm.