### Install Pyth Client Components (CMake) Source: https://github.com/pyth-network/pyth-client/blob/main/CMakeLists.txt This snippet configures the installation of the Pyth client components. It specifies the destination directories for the library, executables, and header files. ```cmake # # install # install( TARGETS pc DESTINATION lib ) install( TARGETS pyth pyth_admin pythd pyth_csv pyth_tx DESTINATION bin ) install( FILES ${PC_HDR} DESTINATION include/pc ) install( FILES program/c/src/oracle/oracle.h DESTINATION include/oracle ) ``` -------------------------------- ### Install Pre-commit Hooks Source: https://github.com/pyth-network/pyth-client/blob/main/README.md Installs pre-commit hooks to check and fix code formatting before commits. This is particularly relevant for the `program/` directory and may require the nightly Rust toolchain. ```Shell pre-commit install rustup toolchain install nightly ``` -------------------------------- ### Build pythd using Docker Environment Source: https://github.com/pyth-network/pyth-client/blob/main/README.md Alternative method to build pythd by starting a Docker build environment script and then running the Cargo build command within the pyth-client directory. ```Shell ./scripts/start-docker-build-env.sh && cd pyth-client && cargo build --release ``` -------------------------------- ### Create Pyth Development Docker Container Source: https://github.com/pyth-network/pyth-client/blob/main/README.md Creates and starts a detached Docker container for development. It mounts user home directories, SSH configuration, and the Pyth repository for development access. ```bash docker run --name pyth-dev -d \ --volume "${HOME}:/home/pyth/home" \ --volume "${HOME}/.config:/home/pyth/.config" \ --volume "${HOME}/.ssh:/home/pyth/.ssh" \ --mount "type=bind,src=${PYTH_REPO},target=/home/pyth/pyth-client" \ --platform linux/amd64 \ $IMAGE \ /bin/bash -c "while [ true ]; do sleep 1000; done" ``` -------------------------------- ### Rust: Fetch and Display Pyth Product and Price Data Source: https://github.com/pyth-network/pyth-client/blob/main/doc/aggregate_price.md This Rust program utilizes the Solana RPC API to retrieve and display all Pyth product and price data. It starts by bootstrapping from a root mapping account key. The output includes details like symbol, asset type, price, confidence interval, and status for each product and its associated price accounts. ```rust product_account .. 4SxmcsbJWVBWvuP2cRQDjFtAgdqzWWLbHESnUTH4CegT symbol.......... AAPL/USD asset_type...... Equity country......... US quote_currency.. USD tenor........... Spot description..... APPLE INC cms_symbol...... AAPL cqs_symbol...... AAPL nasdaq_symbol... AAPL price_account .. CeLD8TC7Ktv2o57EHP7rddh6TZBHXkAhTyfWgxsTYs21 price_type ... price exponent ..... -5 status ....... trading corp_act ..... nocorpact price ........ 12276250 conf ......... 1500 valid_slot ... 55519683 publish_slot . 55519684 product_account .. 9BQ2WKSVbfzpSJYyLCJuxVuiUFxHmQvkhhez94AdffEZ symbol.......... BTC/USD asset_type...... Crypto country......... US quote_currency.. USD tenor........... Spot jlqd_symbol..... BTCUSD price_account .. FCLf9N8xcN9HBA9Cw68FfEZoSBr4bYYJtyRxosNzswMH price_type ... price exponent ..... -9 status ....... trading corp_act ..... nocorpact price ........ 55233535000000 conf ......... 81650000000 valid_slot ... 55519684 publish_slot . 55519685 ... ``` -------------------------------- ### Build Oracle Program (Rust/BPF) Source: https://github.com/pyth-network/pyth-client/blob/main/README.md Instructions to build the Pyth oracle program. It can be compiled as a native binary using `cargo build` or as a BPF binary for the blockchain using `cargo build-bpf`. The BPF build produces a program binary `target/deploy/pyth_oracle.so`. ```Shell cargo build cargo build-bpf ``` -------------------------------- ### Write Buffer to Solana Source: https://github.com/pyth-network/pyth-client/blob/main/README.md Writes the Pythnet oracle program binary to a buffer on the Solana network and obtains the buffer address. This is part of the deployment process. ```bash solana program write-buffer pyth_oracle_pythnet.so ``` -------------------------------- ### Run Pyth Fuzz Test (Add) Source: https://github.com/pyth-network/pyth-client/blob/main/README.md Executes the 'add' fuzz test using a Docker container. It mounts a 'findings' directory for saving crash outputs and specifies the test cases and binary path. ```bash docker run -t \ --platform linux/amd64 \ -v "$(pwd)"/findings:/home/pyth/pyth-client/findings \ pyth-fuzz \ sh -c "./afl/afl-fuzz -i ./pyth-client/pyth/tests/fuzz/add/testcases -o ./pyth-client/findings ./pyth-client/build/fuzz add" ``` -------------------------------- ### Build Pyth Client Tests (CMake) Source: https://github.com/pyth-network/pyth-client/blob/main/CMakeLists.txt This snippet sets up the build for various unit and network tests for the Pyth client. It defines executables for tests like `test_unit`, `test_net`, `test_pd`, and `leader_stats`, linking them against the necessary dependencies. ```cmake # # test programs # enable_testing() add_executable( test_unit pctest/test_unit.cpp ) target_link_libraries( test_unit ${PC_DEP} ) add_executable( test_net pctest/test_net.cpp ) target_link_libraries( test_net ${PC_DEP} ) # This doesn't build on the bullseye base image, due to a packaging bug # in the newer version of libqt5websockets5-dev for Debian. The below build instructions # are left in for completeness, and work with libqt5websockets5-dev=5.11.3-5 (buster). # find_package(Qt5 COMPONENTS Core Network WebSockets) # add_executable( test_publish_websocket pctest/test_publish_websocket.cpp ) # target_link_libraries( test_publish_websocket Qt5::Core Qt5::Network Qt5::WebSockets /usr/local/lib/libjcon.so) add_executable( test_pd pctest/test_pd.cpp ) target_link_libraries( test_pd ${PC_DEP} ) add_executable( leader_stats pctest/leader_stats.cpp ) target_link_libraries( leader_stats ${PC_DEP} ) add_test( test_unit test_unit ) add_test( test_net test_net ) add_test( test_pd test_pd ) ``` -------------------------------- ### Test Oracle Program (Rust/BPF) Source: https://github.com/pyth-network/pyth-client/blob/main/README.md Commands to run tests for the Pyth oracle program. `cargo test` executes unit, simulated transaction, and exhaustive/randomized tests. `cargo test-bpf` runs the same tests but is slightly slower. ```Shell cargo test cargo test-bpf ``` -------------------------------- ### Build Pyth Applications (CMake) Source: https://github.com/pyth-network/pyth-client/blob/main/CMakeLists.txt This snippet defines several executable applications for the Pyth client, including `pythd`, `pyth`, `pyth_admin`, `pyth_csv`, and `pyth_tx`. Each application is linked against the core Pyth client library and its dependencies. ```cmake # # applications # add_executable( pythd pcapps/pythd.cpp ) target_link_libraries( pythd ${PC_DEP} ) add_executable( pyth pcapps/pyth.cpp ) target_link_libraries( pyth ${PC_DEP} ) add_executable( pyth_admin pcapps/admin_rpc_client.cpp pcapps/admin_request.cpp pcapps/pyth_admin.cpp ) target_link_libraries( pyth_admin ${PC_DEP} ) add_executable( pyth_csv pcapps/pyth_csv.cpp ) target_link_libraries( pyth_csv ${PC_DEP} ) add_executable( pyth_tx pcapps/tx_rpc_client.cpp pcapps/tx_svr.cpp pcapps/pyth_tx.cpp ) target_link_libraries( pyth_tx ${PC_DEP} ) ``` -------------------------------- ### Build pythd (Off-chain Client API) Source: https://github.com/pyth-network/pyth-client/blob/main/README.md Build instructions for pythd, the off-chain client API. It requires dependencies like openssl, zlib, and zstd, and uses cmake for building. The default build is a release build. ```Shell # depends on openssl apt install libssl-dev # depends on libz apt install zlib1g zlib1g-dev # depends on libzstd apt install libzstd-dev # uses cmake to build apt install cmake # default is release build ./scripts/build.sh ``` -------------------------------- ### Build Pyth Fuzz Docker Image Source: https://github.com/pyth-network/pyth-client/blob/main/README.md Builds a Docker image for running fuzz tests on the Pyth client. This image is used to execute fuzzing commands. ```bash docker build . --platform linux/amd64 -f docker/fuzz/Dockerfile -t pyth-fuzz ``` -------------------------------- ### C++ Batch Price Updates with pyth-client Source: https://github.com/pyth-network/pyth-client/blob/main/doc/cpp-batching-upgrade.md This snippet demonstrates how to send batched price updates using the C++ bindings of the pyth-client. Instead of individual updates, you now call `pc::price::send` with a vector of `pc::price` objects in response to `on_slot_publish` callbacks. This approach batches updates into transactions. ```cpp void on_slot_publish(const std::vector& prices) { // Instead of sending individual price updates, // call pc::price::send with a vector of pc::price objects. pc::price::send(prices); } ``` -------------------------------- ### Build Pyth Fuzz Testing Application (CMake) Source: https://github.com/pyth-network/pyth-client/blob/main/CMakeLists.txt This snippet defines the executable for fuzz testing the Pyth client. It links the `fuzz` executable against the project's dependencies. ```cmake # # fuzz testing application # add_executable( fuzz pctest/fuzz.cpp ) target_link_libraries( fuzz ${PC_DEP} ) ``` -------------------------------- ### Run pythd Build in Docker Source: https://github.com/pyth-network/pyth-client/blob/main/README.md Command to run the pyth-client build environment within a Linux Docker container. This is useful for cross-platform builds or running BPF binaries. It mounts the local pyth-client directory and uses a specified Docker image. ```Shell export PYTH_REPO=/path/to/host/pyth-client export IMAGE=... docker run -it \ --volume "${HOME}:/home/pyth/home" \ --volume "${HOME}/.config:/home/pyth/.config" \ --mount "type=bind,src=${PYTH_REPO},target=/home/pyth/pyth-client" \ --userns=host \ --user="$( id -ur ):$( id -gr )" \ --platform linux/amd64 \ $IMAGE \ /bin/bash -l ``` -------------------------------- ### Build Pyth Client Library (CMake) Source: https://github.com/pyth-network/pyth-client/blob/main/CMakeLists.txt This snippet defines the core Pyth client library using CMake. It specifies source files, header files, and external dependencies like OpenSSL, Crypto, Zlib, and Zstd. ```cmake cmake_minimum_required( VERSION 3.13 ) # project pyth-client project( pyth-client ) # default build convention if( NOT CMAKE_BUILD_TYPE ) set( CMAKE_BUILD_TYPE Release ) endif() # use root directory as include set( CMAKE_INCLUDE_CURRENT_DIR ON ) # find oracle header files include_directories( program/c/src/ ) # gcc compiler/linker flags add_compile_options( -ggdb -Wall -Wextra -Wsign-conversion -Werror -Wno-deprecated-declarations -m64 ) set( CMAKE_CXX_STANDARD 14) set( CMAKE_CXX_FLAGS -std=c++14 ) set( CMAKE_C_FLAGS -std=c99 ) set( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pthread") # # pyth client API library # set( PC_SRC pc/attr_id.cpp; pc/capture.cpp; pc/key_pair.cpp; pc/key_store.cpp; pc/jtree.cpp; pc/log.cpp; pc/manager.cpp; pc/mem_map.cpp; pc/misc.cpp; pc/net_socket.cpp; pc/pub_stats.cpp; pc/replay.cpp; pc/request.cpp; pc/rpc_client.cpp; pc/user.cpp; program/c/src/oracle/model/price_model.c ) set( PC_HDR pc/attr_id.hpp; pc/capture.hpp; pc/dbl_list.hpp; pc/error.hpp; pc/jtree.hpp; pc/key_pair.hpp; pc/key_store.hpp; pc/hash_map.hpp; pc/log.hpp; pc/manager.hpp; pc/mem_map.hpp; pc/misc.hpp; pc/net_socket.hpp; pc/replay.hpp; pc/request.hpp; pc/rpc_client.hpp pc/user.hpp ) add_library( pc STATIC ${PC_SRC} ) # dependencies set( PC_DEP pc ssl crypto z zstd ) ``` -------------------------------- ### Set Solana CLI Network Configuration Source: https://github.com/pyth-network/pyth-client/blob/main/README.md Configures the Solana CLI to target a specific network, such as devnet. This is a prerequisite for deploying programs. ```bash solana config set --url https://api.devnet.solana.com ``` -------------------------------- ### BPF Library Configuration Function (CMake) Source: https://github.com/pyth-network/pyth-client/blob/main/CMakeLists.txt This CMake function, `add_bpf_lib`, is designed to configure libraries for BPF (Berkeley Packet Filter) development. It sets C standard versions, compile definitions, and include directories specific to BPF targets. ```cmake # # bpf static analysis (CLion) # function( add_bpf_lib targ ) if( SOLANA AND NOT BPF ) set( BPF ${SOLANA}/sdk/bpf ) endif() if( BPF ) add_library( ${targ} STATIC ${ARGN} ) if( ${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.21" ) # bpf.mk uses --std=c17 set_property( TARGET ${targ} PROPERTY C_STANDARD 17 ) else() set_property( TARGET ${targ} PROPERTY C_STANDARD 11 ) endif() set_property( TARGET ${targ} PROPERTY C_STANDARD_REQUIRED ON ) set_property( TARGET ${targ} PROPERTY C_EXTENSIONS OFF ) target_compile_definitions( ${targ} PRIVATE __bpf__=1 ) target_include_directories( ${targ} SYSTEM PRIVATE ${BPF}/c/inc ${BPF}/dependencies/criterion/include ) endif() endfunction() # test_oracle.c includes oracle.c add_bpf_lib( test-oracle-bpf program/c/src/oracle/test_oracle.c ) ``` -------------------------------- ### Configure User Permissions in Docker Container Source: https://github.com/pyth-network/pyth-client/blob/main/README.md Commands to execute inside a Docker container to adjust user and group IDs for file access permissions. This ensures the 'pyth' user can access mounted host directories. ```bash host@host$ id $USER # Shows user_id, group_id, and group names host@host$ docker exec -ti pyth-dev bash pyth@pyth-dev$ sudo su root@pyth-dev# groupadd -g 1004 1004 root@pyth-dev# usermod -u 1002 -g 1004 -s /bin/bash pyth ``` -------------------------------- ### Investigate Failing Fuzz Input Source: https://github.com/pyth-network/pyth-client/blob/main/README.md Runs a specific failing input against the fuzzing binary within a Docker container to investigate crashes. It uses the 'findings' directory to access the failing input file. ```bash docker run -t \ --platform linux/amd64 \ -v "$(pwd)"/findings:/home/pyth/pyth-client/findings \ pyth-fuzz \ sh -c "./pyth-client/build/fuzz add < ./pyth-client/findings/crashes/id\:000000\,sig\:06\,src\:000000\,op\:flip1\,pos\:0" ``` -------------------------------- ### Verify Oracle Program Buffer Source: https://github.com/pyth-network/pyth-client/blob/main/README.md Verifies the integrity of the Oracle program buffer by comparing its SHA256 hash with a reference hash. This ensures the deployed code matches the expected version. ```bash solana program dump temp_file && shasum -a 256 temp_file && rm temp_file ``` -------------------------------- ### Assign Upgrade Authority to Buffer Source: https://github.com/pyth-network/pyth-client/blob/main/README.md Assigns the upgrade authority of the current program to a new buffer address. This is a crucial step before upgrading the program. ```bash solana program set-buffer-authority --new-buffer-authority ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.