Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hermes: Add prv publish time metadata #1061

Merged
merged 2 commits into from
Sep 22, 2023
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
27 changes: 15 additions & 12 deletions hermes/src/aggregate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,11 @@ pub enum Update {

#[derive(Debug, PartialEq)]
pub struct PriceFeedUpdate {
pub price_feed: PriceFeed,
pub slot: Option<Slot>,
pub received_at: Option<UnixTimestamp>,
pub update_data: Option<Vec<u8>>,
pub price_feed: PriceFeed,
pub slot: Option<Slot>,
pub received_at: Option<UnixTimestamp>,
pub update_data: Option<Vec<u8>>,
pub prev_publish_time: Option<UnixTimestamp>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realise we can't change it at this point but It's a shame this isn't last_publish_time like other last_ fields we have in our codebases.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think here prev is more clear than last.

}

#[derive(Debug, PartialEq)]
Expand Down Expand Up @@ -333,7 +334,7 @@ where
.iter()
.map(|message_state| match message_state.message {
Message::PriceFeedMessage(price_feed) => Ok(PriceFeedUpdate {
price_feed: PriceFeed::new(
price_feed: PriceFeed::new(
Copy link
Contributor

@cctdaniel cctdaniel Sep 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the extra spacing seems weird but seems like it passes pre-commit 🤔

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah it is the rust formatter config that we have :D

PriceIdentifier::new(price_feed.feed_id),
Price {
price: price_feed.price,
Expand All @@ -348,14 +349,15 @@ where
publish_time: price_feed.publish_time,
},
),
received_at: Some(message_state.received_at),
slot: Some(message_state.slot),
update_data: Some(
received_at: Some(message_state.received_at),
slot: Some(message_state.slot),
update_data: Some(
construct_update_data(vec![message_state.clone().into()])?
.into_iter()
.next()
.ok_or(anyhow!("Missing update data for message"))?,
),
prev_publish_time: Some(price_feed.prev_publish_time),
}),
_ => Err(anyhow!("Invalid message state type")),
})
Expand Down Expand Up @@ -574,7 +576,7 @@ mod test {
assert_eq!(
price_feeds_with_update_data.price_feeds,
vec![PriceFeedUpdate {
price_feed: PriceFeed::new(
price_feed: PriceFeed::new(
PriceIdentifier::new(price_feed_message.feed_id),
Price {
price: price_feed_message.price,
Expand All @@ -589,11 +591,12 @@ mod test {
publish_time: price_feed_message.publish_time,
}
),
slot: Some(10),
received_at: price_feeds_with_update_data.price_feeds[0].received_at, // Ignore checking this field.
update_data: price_feeds_with_update_data.price_feeds[0]
slot: Some(10),
received_at: price_feeds_with_update_data.price_feeds[0].received_at, // Ignore checking this field.
update_data: price_feeds_with_update_data.price_feeds[0]
.update_data
.clone(), // Ignore checking this field.
prev_publish_time: Some(9),
}]
);

Expand Down
3 changes: 3 additions & 0 deletions hermes/src/api/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ pub struct RpcPriceFeedMetadata {
pub emitter_chain: u16,
#[schema(value_type = Option<i64>, example=doc_examples::timestamp_example)]
pub price_service_receive_time: Option<UnixTimestamp>,
#[schema(value_type = Option<i64>, example=doc_examples::timestamp_example)]
pub prev_publish_time: Option<UnixTimestamp>,
}

#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, ToSchema)]
Expand Down Expand Up @@ -98,6 +100,7 @@ impl RpcPriceFeed {
emitter_chain: Chain::Pythnet.into(),
price_service_receive_time: price_feed_update.received_at,
slot: price_feed_update.slot,
prev_publish_time: price_feed_update.prev_publish_time,
}),
vaa: match binary {
false => None,
Expand Down
1 change: 1 addition & 0 deletions hermes/src/state/benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ impl TryFrom<BenchmarkUpdates> for PriceFeedsWithUpdateData {
slot: None,
received_at: None,
update_data: None,
prev_publish_time: None, // TODO: Set this field when Benchmarks API supports it.
})
.collect::<Vec<_>>(),
update_data: benchmark_updates.binary.try_into()?,
Expand Down
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion price_service/client/js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pythnetwork/price-service-client",
"version": "1.7.0",
"version": "1.8.0",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌 on the respecting semver

"description": "Pyth price service client",
"author": {
"name": "Pyth Data Association"
Expand Down
2 changes: 1 addition & 1 deletion price_service/sdk/js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pythnetwork/price-service-sdk",
"version": "1.3.0",
"version": "1.4.0",
"description": "Pyth price service SDK",
"homepage": "https://pyth.network",
"main": "lib/index.js",
Expand Down
8 changes: 8 additions & 0 deletions price_service/sdk/js/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,19 +100,25 @@ export class PriceFeedMetadata {
* Pythnet slot number of the price
*/
slot?: number;
/**
* The time that the previous price was published
*/
prevPublishTime?: number;

constructor(metadata: {
attestationTime?: number;
emitterChain: number;
receiveTime?: number;
sequenceNumber?: number;
slot?: number;
prevPublishTime?: number;
}) {
this.attestationTime = metadata.attestationTime;
this.emitterChain = metadata.emitterChain;
this.priceServiceReceiveTime = metadata.receiveTime;
this.sequenceNumber = metadata.sequenceNumber;
this.slot = metadata.slot;
this.prevPublishTime = metadata.prevPublishTime;
}

static fromJson(json: any): PriceFeedMetadata | undefined {
Expand All @@ -126,6 +132,7 @@ export class PriceFeedMetadata {
receiveTime: jsonFeed.price_service_receive_time,
sequenceNumber: jsonFeed.sequence_number,
slot: jsonFeed.slot,
prevPublishTime: jsonFeed.prev_publish_time,
});
}

Expand All @@ -136,6 +143,7 @@ export class PriceFeedMetadata {
price_service_receive_time: this.priceServiceReceiveTime,
sequence_number: this.sequenceNumber,
slot: this.slot,
prev_publish_time: this.prevPublishTime,
};
// this is done to avoid sending undefined values to the server
return Convert.priceFeedMetadataToJson(jsonFeed);
Expand Down
9 changes: 9 additions & 0 deletions price_service/sdk/js/src/schemas/PriceFeed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ export interface PriceFeedMetadata {
* Chain of the emitter
*/
emitter_chain: number;
/**
* The time that the previous price was published
*/
prev_publish_time?: number;
/**
* The time that the price service received the price
*/
Expand Down Expand Up @@ -294,6 +298,11 @@ const typeMap: any = {
typ: u(undefined, 0),
},
{ json: "emitter_chain", js: "emitter_chain", typ: 0 },
{
json: "prev_publish_time",
js: "prev_publish_time",
typ: u(undefined, 0),
},
{
json: "price_service_receive_time",
js: "price_service_receive_time",
Expand Down
5 changes: 5 additions & 0 deletions price_service/sdk/js/src/schemas/price_feed.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@
"description": "Pythnet slot number of the price",
"type": "integer",
"format": "int64"
},
"prev_publish_time": {
"description": "The time that the previous price was published",
"type": "integer",
"format": "int64"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion target_chains/aptos/sdk/js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pythnetwork/pyth-aptos-js",
"version": "1.3.0",
"version": "1.4.0",
"description": "Pyth Network Aptos Utilities",
"homepage": "https://pyth.network",
"author": {
Expand Down
2 changes: 1 addition & 1 deletion target_chains/cosmwasm/sdk/js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pythnetwork/pyth-terra-js",
"version": "1.4.0",
"version": "1.5.0",
"description": "Pyth Network Terra Utils in JS",
"homepage": "https://pyth.network",
"author": {
Expand Down
2 changes: 1 addition & 1 deletion target_chains/ethereum/sdk/js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pythnetwork/pyth-evm-js",
"version": "1.28.0",
"version": "1.29.0",
"description": "Pyth Network EVM Utils in JS",
"homepage": "https://pyth.network",
"author": {
Expand Down
2 changes: 1 addition & 1 deletion target_chains/sui/sdk/js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pythnetwork/pyth-sui-js",
"version": "1.1.0",
"version": "1.2.0",
"description": "Pyth Network Sui Utilities",
"homepage": "https://pyth.network",
"author": {
Expand Down
7 changes: 3 additions & 4 deletions target_chains/sui/sdk/js/src/examples/SuiRelay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ const argvPromise = yargs(hideBin(process.argv))
type: "array",
demandOption: true,
})
.option("price-service", {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a minor change to move to hermes

description:
"Endpoint URL for the price service. e.g: https://xc-mainnet.pyth.network",
.option("hermes", {
description: "Endpoint URL for Hermes. e.g: https://hermes.pyth.network",
type: "string",
demandOption: true,
})
Expand Down Expand Up @@ -52,7 +51,7 @@ async function run() {
const argv = await argvPromise;

// Fetch the latest price feed update data from the Price Service
const connection = new SuiPriceServiceConnection(argv["price-service"]);
const connection = new SuiPriceServiceConnection(argv["hermes"]);
const feeds = argv["feed-id"] as string[];
const priceFeedUpdateData = await connection.getPriceFeedsUpdateData(feeds);

Expand Down
Loading