Explorar el Código

fix(pyth-lazer-puiblisher-sdk): Add Deployment Script (#2587)

* output publisher update types

* run publish script to test imports

* update publish script

* Update export paths

* Return files to normal

* fix rm build command

* add publish command

* update publish ci

* bump publisher sdk version

* remove build from cargo.toml and use python for updating lib

* fix rust test suite

* add build sbf

* pin 94 for proc macro and update toolchain

* try v94 again for proc macro 2

* update workflow again

* try using later toolchain for anchor install

* update solana version

* try 95

* revert some changes to workflow and pin v95 there too

* try no idl

* use 82 on anchor and try suggestion

* undo changes to solana test workflow

* add impl for timestampus

* undo change to proc macro version

* remove build sbf step

* address pr comment
Darun Seethammagari hace 7 meses
padre
commit
7d5f8918fc

+ 1 - 1
.github/workflows/ci-lazer-rust.yml

@@ -30,7 +30,7 @@ jobs:
       - name: install extra tools
         run: |
           cargo install --locked taplo-cli@0.9.3
-          sudo apt-get install -y protobuf-compiler
+          sudo apt-get update && sudo apt-get install -y protobuf-compiler
       - name: Install Solana Cli
         run: |
           sh -c "$(curl -sSfL https://release.anza.xyz/stable/install)"

+ 1 - 1
.github/workflows/publish-rust-lazer-publisher-sdk.yml

@@ -13,7 +13,7 @@ jobs:
       - name: Checkout sources
         uses: actions/checkout@v2
 
-      - run: cargo publish --token ${CARGO_REGISTRY_TOKEN}
+      - run: publish.sh
         env:
           CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
         working-directory: "lazer/publisher_sdk/rust"

+ 2 - 1
lazer/Cargo.lock

@@ -3856,6 +3856,7 @@ dependencies = [
  "hex",
  "itertools 0.13.0",
  "libsecp256k1 0.7.1",
+ "protobuf",
  "rust_decimal",
  "serde",
  "serde_json",
@@ -3863,7 +3864,7 @@ dependencies = [
 
 [[package]]
 name = "pyth-lazer-publisher-sdk"
-version = "0.1.0"
+version = "0.1.1"
 dependencies = [
  "protobuf",
  "protobuf-codegen",

+ 1 - 2
lazer/publisher_sdk/rust/Cargo.toml

@@ -1,11 +1,10 @@
 [package]
 name = "pyth-lazer-publisher-sdk"
-version = "0.1.0"
+version = "0.1.1"
 edition = "2021"
 description = "Pyth Lazer Publisher SDK types."
 license = "Apache-2.0"
 repository = "https://github.com/pyth-network/pyth-crosschain"
-build = "build.rs"
 
 [dependencies]
 protobuf = "3.7.2"

+ 38 - 0
lazer/publisher_sdk/rust/publish.sh

@@ -0,0 +1,38 @@
+#!/bin/bash
+set -e
+
+PACKAGE_DIR="."
+
+echo "building package to generate type files"
+OUT_DIR=$(cargo build --message-format=json | jq -r 'select(.reason == "build-script-executed") | .out_dir' | grep "pyth-lazer-publisher-sdk")
+
+echo "using output directory: ${OUT_DIR}"
+
+echo "copying files from protobuf output to package directory"
+cp -r "${OUT_DIR}/protobuf" "${PACKAGE_DIR}/src/"
+
+echo "deleting build.rs file"
+rm -f "${PACKAGE_DIR}/build.rs"
+
+echo "updating lib.rs to export local protobuf files"
+python3 -c "
+import re
+
+def replace_mod_protobuf(file_path):
+    with open(file_path, 'r') as f:
+        content = f.read()
+
+    pattern = re.compile(r'mod\s+protobuf\s*\{.*?\}', re.DOTALL)
+
+    replacement = 'mod protobuf;'
+
+    new_content = pattern.sub(replacement, content)
+
+    with open(file_path, 'w') as f:
+        f.write(new_content)
+
+replace_mod_protobuf('${PACKAGE_DIR}/src/lib.rs')
+"
+
+echo "publishing package"
+cargo publish --token ${CARGO_REGISTRY_TOKEN}

+ 4 - 0
lazer/publisher_sdk/rust/src/lib.rs

@@ -2,6 +2,10 @@ pub mod transaction {
     pub use crate::protobuf::pyth_lazer_transaction::*;
 }
 
+pub mod publisher_update {
+    pub use crate::protobuf::publisher_update::*;
+}
+
 mod protobuf {
     include!(concat!(env!("OUT_DIR"), "/protobuf/mod.rs"));
 }

+ 1 - 0
lazer/sdk/rust/protocol/Cargo.toml

@@ -15,6 +15,7 @@ derive_more = { version = "1.0.0", features = ["from"] }
 itertools = "0.13.0"
 rust_decimal = "1.36.0"
 base64 = "0.22.1"
+protobuf = "3.7.2"
 
 [dev-dependencies]
 bincode = "1.3.3"

+ 11 - 0
lazer/sdk/rust/protocol/src/router.rs

@@ -4,6 +4,7 @@ use {
     crate::payload::AggregatedPriceFeedData,
     anyhow::{bail, Context},
     itertools::Itertools,
+    protobuf::well_known_types::timestamp::Timestamp,
     rust_decimal::{prelude::FromPrimitive, Decimal},
     serde::{de::Error, Deserialize, Serialize},
     std::{
@@ -26,6 +27,16 @@ pub struct ChannelId(pub u8);
 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)]
 pub struct TimestampUs(pub u64);
 
+impl TryFrom<&Timestamp> for TimestampUs {
+    type Error = anyhow::Error;
+
+    fn try_from(timestamp: &Timestamp) -> anyhow::Result<Self> {
+        let seconds_in_micros: u64 = (timestamp.seconds * 1_000_000).try_into()?;
+        let nanos_in_micros: u64 = (timestamp.nanos / 1_000).try_into()?;
+        Ok(TimestampUs(seconds_in_micros + nanos_in_micros))
+    }
+}
+
 impl TimestampUs {
     pub fn now() -> Self {
         let value = SystemTime::now()