Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ endif()
set( CMAKE_INCLUDE_CURRENT_DIR ON )

# find oracle header files
include_directories( program/src/ )
include_directories( program/c/src/ )

# gcc compiler/linker flags
add_compile_options( -ggdb -Wall -Wextra -Wsign-conversion -Werror -Wno-deprecated-declarations -m64 )
Expand All @@ -39,7 +39,7 @@ set( PC_SRC
pc/request.cpp;
pc/rpc_client.cpp;
pc/user.cpp;
program/src/oracle/model/price_model.c
program/c/src/oracle/model/price_model.c
)

set( PC_HDR
Expand Down Expand Up @@ -88,7 +88,7 @@ target_link_libraries( pyth_tx ${PC_DEP} )
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/src/oracle/oracle.h DESTINATION include/oracle )
install( FILES program/c/src/oracle/oracle.h DESTINATION include/oracle )

#
# test programs
Expand Down Expand Up @@ -147,4 +147,4 @@ function( add_bpf_lib targ )
endfunction()

# test_oracle.c includes oracle.c
add_bpf_lib( test-oracle-bpf program/src/oracle/test_oracle.c )
add_bpf_lib( test-oracle-bpf program/c/src/oracle/test_oracle.c )
20 changes: 14 additions & 6 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,29 +26,37 @@ RUN apt-get install -qq \
RUN echo "pyth ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
RUN useradd -m pyth

# Fixes a bug in the solana docker image
# https://github.com/solana-labs/solana/issues/20577
RUN mkdir /usr/bin/sdk/bpf/dependencies \
&& chmod 777 /usr/bin/sdk/bpf/dependencies


USER pyth
WORKDIR /home/pyth
COPY --chown=pyth:pyth . pyth-client/

RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs \
| sh -s -- -y


RUN echo "\n\
export PATH=\"\${PATH}:\${HOME}/pyth-client/build\"\n\
export PATH=\"\${PATH}:\${HOME}/pyth-client/build:\${HOME}/.cargo/bin\"\n\
export PYTHONPATH=\"\${PYTHONPATH:+\$PYTHONPATH:}\${HOME}/pyth-client\"\n\
" >> .profile

COPY --chown=pyth:pyth . pyth-client/

# Build off-chain binaries.
RUN cd pyth-client && ./scripts/build.sh

# Install rust and add ". ~/.cargo/env" to ~/.profile.
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs \
| sh -s -- -y --default-toolchain none

# Copy solana sdk and apply patch.
RUN mkdir solana
RUN cp -a /usr/bin/sdk solana
RUN ./pyth-client/scripts/patch-solana.sh

# Build and test the oracle program.
RUN cd pyth-client && ./scripts/build-bpf.sh program
RUN cd pyth-client && ./scripts/build-bpf.sh .
RUN /bin/bash -l -c "pytest-3 --pyargs pyth"

ENTRYPOINT []
Expand Down
5 changes: 5 additions & 0 deletions program/c/makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
OUT_DIR := ./target
SOLANA := ../../../solana
include $(SOLANA)/sdk/bpf/c/bpf.mk
cpyth:
bash -c "ar rcs target/libcpyth.a target/**/*.o"
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ static uint64_t dispatch( SolParameters *prm, SolAccountInfo *ka )
}
}

extern uint64_t entrypoint(const uint8_t *input)
extern uint64_t c_entrypoint(const uint8_t *input)
{
SolAccountInfo ka[4];
SolParameters prm[1];
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 0 additions & 3 deletions program/makefile

This file was deleted.

14 changes: 14 additions & 0 deletions program/rust/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
cargo-features = ["edition2021"]

[package]
name = "pyth-oracle"
version = "2.13.1"
edition = "2021"
license = "Apache 2.0"
publish = false

[dependencies]
solana-program = "=1.10.29"

[lib]
crate-type = ["cdylib", "lib"]
3 changes: 3 additions & 0 deletions program/rust/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
println!("cargo:rustc-link-search=../c/target");
}
11 changes: 11 additions & 0 deletions program/rust/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#[link(name = "cpyth")]
extern "C" {
fn c_entrypoint(input: *mut u8) -> u64;
}

#[no_mangle]
pub extern "C" fn entrypoint(input: *mut u8) -> u64 {
unsafe{
return c_entrypoint(input);
}
}
2 changes: 1 addition & 1 deletion pyth/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def solana_program_deploy(
cmd = [
'solana', 'program', 'deploy',
os.path.abspath(
os.path.join(__this_dir, '..', '..', 'target', 'oracle.so')
os.path.join(__this_dir, '..', '..', 'target', 'deploy','pyth_oracle.so')
),
'--commitment', 'finalized',
'--url', 'localhost',
Expand Down
47 changes: 31 additions & 16 deletions scripts/build-bpf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,45 @@

set -eu

BUILD_DIR="$( cd "${1:-.}" && pwd )"
PYTH_DIR=$( cd "${1:-.}" && pwd)

if [[ ! -f "${BUILD_DIR}/makefile" ]]
then
if [[ -f "${BUILD_DIR}/program/makefile" ]]
then
BUILD_DIR="${BUILD_DIR}/program"
else
>&2 echo "Not a makefile dir: ${BUILD_DIR}"
exit 1
fi
fi
#find the makefile in pyth-client
#ASSUMES THAT there is only one makefile there
C_DIR="$( find $PYTH_DIR | grep makefile)"
C_DIR=$(dirname $C_DIR)

#finds Cargo.toml in pyth-client
#ASSUMES THAT there is only one Cargo.toml there
RUST_DIR="$( find $PYTH_DIR | grep Cargo.toml )"
RUST_DIR=$(dirname $RUST_DIR)

if ! which cargo 2> /dev/null
then
# shellcheck disable=SC1090
source "${CARGO_HOME:-$HOME/.cargo}/env"
fi


set -x

cd "${BUILD_DIR}"
#build the C code and make an archive file out of it
cd "${C_DIR}"
export V="${V:-1}"
make clean
make "${@:2}"
sha256sum ../target/*.so
rm ../target/*-keypair.json
make clean
make "${@:2}"
make cpyth
rm ./target/*-keypair.json


#build Rust and link it with C
cd "${RUST_DIR}"
cargo clean
cargo build-bpf
sha256sum ./target/**/*.so
rm ./target/**/*-keypair.json
rm -r $PYTH_DIR/target || true
mv ./target $PYTH_DIR/target