-
Notifications
You must be signed in to change notification settings - Fork 334
lazer/sui: Update V2 API #3680
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
Draft
matej-douro
wants to merge
5
commits into
main
Choose a base branch
from
matej/sui-lazer-channel-v2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
lazer/sui: Update V2 API #3680
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
3ad7d76
lazer/sui: add `pyth_lazer::channel_v2`, deprecate `pyth_lazer::channel`
matej-douro 7dd1f19
lazer/sui: add `pyth_lazer::update_v2`, deprecate `pyth_lazer::update`
matej-douro dabe835
lazer/sui: update tests, fix warnings
matej-douro d84b655
lazer/sui: test 1000ms channel, check v1 behavior
matej-douro 37748d7
lazer/sui: update SDK and docs with V2 API
matej-douro File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| module pyth_lazer::channel_v2; | ||
|
|
||
| #[error] | ||
| const EChannelOutOfRange: vector<u8> = "Channel value out of range"; | ||
|
|
||
| /// Channel enum. Use `is_*` methods to check current value. | ||
| public struct Channel(u8) has copy, drop, store; | ||
|
|
||
| public(package) fun from_u8(value: u8): Channel { | ||
| assert!(value >= 1 && value <= 4, EChannelOutOfRange); | ||
| Channel(value) | ||
| } | ||
|
|
||
| public fun is_real_time(self: &Channel): bool { | ||
| self.0 == 1 | ||
| } | ||
|
|
||
| public fun is_fixed_rate_50ms(self: &Channel): bool { | ||
| self.0 == 2 | ||
| } | ||
|
|
||
| public fun is_fixed_rate_200ms(self: &Channel): bool { | ||
| self.0 == 3 | ||
| } | ||
|
|
||
| public fun is_fixed_rate_1000ms(self: &Channel): bool { | ||
| self.0 == 4 | ||
| } | ||
|
|
||
| /// Returns the update interval in milliseconds for fixed rate channels, 0 for RealTime. | ||
| public fun get_update_interval_ms(self: &Channel): u64 { | ||
| if (self.0 == 1) { 0 } | ||
| else if (self.0 == 2) { 50 } | ||
| else if (self.0 == 3) { 200 } | ||
| else if (self.0 == 4) { 1000 } | ||
| else { abort EChannelOutOfRange } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,66 +1,42 @@ | ||
| #[deprecated(note = b"Use `pyth_lazer::update_v2` instead.")] | ||
| module pyth_lazer::update; | ||
|
|
||
| use pyth_lazer::channel::{Self, Channel}; | ||
| use pyth_lazer::feed::{Self, Feed}; | ||
| use sui::bcs; | ||
|
|
||
| // Error codes for update parsing | ||
| const EInvalidPayload: u64 = 3; | ||
| use pyth_lazer::feed::Feed; | ||
| use pyth_lazer::update_v2; | ||
|
|
||
| #[deprecated(note = b"Use `update_v2::Update` instead.")] | ||
| public struct Update has copy, drop { | ||
| timestamp: u64, | ||
| channel: Channel, | ||
| feeds: vector<Feed>, | ||
| } | ||
|
|
||
| public(package) fun new(timestamp: u64, channel: Channel, feeds: vector<Feed>): Update { | ||
| Update { timestamp, channel, feeds } | ||
| } | ||
|
|
||
| /// Get the timestamp of the update | ||
| #[deprecated(note = b"Use `update_v2::Update` instead.")] | ||
| public fun timestamp(update: &Update): u64 { | ||
| update.timestamp | ||
| } | ||
|
|
||
| /// Get a reference to the channel of the update | ||
| #[deprecated(note = b"Use `update_v2::Update` instead.")] | ||
| public fun channel(update: &Update): Channel { | ||
| update.channel | ||
| } | ||
|
|
||
| /// Get a copy of the feeds vector of the update | ||
| #[deprecated(note = b"Use `update_v2::Update` instead.")] | ||
| public fun feeds(update: &Update): vector<Feed> { | ||
| update.feeds | ||
| } | ||
|
|
||
| /// Get a reference to the feeds vector of the update | ||
| #[deprecated(note = b"Use `update_v2::Update` instead.")] | ||
| public fun feeds_ref(update: &Update): &vector<Feed> { | ||
| &update.feeds | ||
| } | ||
|
|
||
| /// Parse the update from a BCS cursor containing the payload data | ||
| /// This assumes the payload magic has already been validated and consumed | ||
| public(package) fun parse_from_cursor(mut cursor: bcs::BCS): Update { | ||
| // Parse timestamp | ||
| let timestamp = cursor.peel_u64(); | ||
|
|
||
| // Parse channel | ||
| let channel_value = cursor.peel_u8(); | ||
| let channel = channel::from_u8(channel_value); | ||
|
|
||
| // Parse feeds | ||
| let feed_count = cursor.peel_u8(); | ||
| let mut feeds = vector::empty<Feed>(); | ||
| let mut feed_i = 0; | ||
|
|
||
| while (feed_i < feed_count) { | ||
| let feed = feed::parse_from_cursor(&mut cursor); | ||
| vector::push_back(&mut feeds, feed); | ||
| feed_i = feed_i + 1; | ||
| }; | ||
|
|
||
| // Verify no remaining bytes | ||
| let remaining_bytes = cursor.into_remainder_bytes(); | ||
| assert!(remaining_bytes.length() == 0, EInvalidPayload); | ||
|
|
||
| Update { timestamp, channel, feeds } | ||
| #[allow(deprecated_usage)] | ||
| public(package) fun from_v2(update: update_v2::Update): Update { | ||
| Update { | ||
| timestamp: update.timestamp(), | ||
| channel: channel::from_v2(update.channel()), | ||
| feeds: update.feeds(), | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| module pyth_lazer::update_v2; | ||
|
|
||
| use pyth_lazer::channel_v2::{Self, Channel}; | ||
| use pyth_lazer::feed::{Self, Feed}; | ||
| use sui::bcs; | ||
|
|
||
| #[error] | ||
| const ETrailingPayloadData: vector<u8> = "Trailing Update payload data"; | ||
|
|
||
| public struct Update has copy, drop { | ||
| timestamp: u64, | ||
| channel: Channel, | ||
| feeds: vector<Feed>, | ||
| } | ||
|
|
||
| public(package) fun new(timestamp: u64, channel: Channel, feeds: vector<Feed>): Update { | ||
| Update { timestamp, channel, feeds } | ||
| } | ||
|
|
||
| /// Get the timestamp of the update. | ||
| public fun timestamp(update: &Update): u64 { | ||
| update.timestamp | ||
| } | ||
|
|
||
| /// Get a reference to the channel of the update. | ||
| public fun channel(update: &Update): Channel { | ||
| update.channel | ||
| } | ||
|
|
||
| /// Get a copy of the feeds vector of the update. | ||
| public fun feeds(update: &Update): vector<Feed> { | ||
| update.feeds | ||
| } | ||
|
|
||
| /// Get a reference to the feeds vector of the update. | ||
| public fun feeds_ref(update: &Update): &vector<Feed> { | ||
| &update.feeds | ||
| } | ||
|
|
||
| /// Parse the update from a BCS cursor containing the payload data. | ||
| /// Assumes the payload magic has already been validated and consumed. | ||
| public(package) fun parse_from_cursor(mut cursor: bcs::BCS): Update { | ||
| let timestamp = cursor.peel_u64(); | ||
|
|
||
| let channel_value = cursor.peel_u8(); | ||
| let channel = channel_v2::from_u8(channel_value); | ||
|
|
||
| let feed_count = cursor.peel_u8(); | ||
| let mut feeds = vector::empty<Feed>(); | ||
| let mut feed_i = 0; | ||
|
|
||
| while (feed_i < feed_count) { | ||
| let feed = feed::parse_from_cursor(&mut cursor); | ||
| vector::push_back(&mut feeds, feed); | ||
| feed_i = feed_i + 1; | ||
| }; | ||
|
|
||
| let remaining_bytes = cursor.into_remainder_bytes(); | ||
| assert!(remaining_bytes.length() == 0, ETrailingPayloadData); | ||
|
|
||
| Update { timestamp, channel, feeds } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚩 SDK breaking change: return type changes from update::Update to update_v2::Update
The SDK function
addParseAndVerifyLeEcdsaUpdateCallatlazer/contracts/sui/sdk/js/src/index.ts:18now callsparse_and_verify_le_ecdsa_update_v2instead ofparse_and_verify_le_ecdsa_update. This changes the on-chain return type frompyth_lazer::update::Updatetopyth_lazer::update_v2::Update. Any existing deployed consumer smart contracts that acceptupdate::Updateas a parameter will fail at transaction execution time when used with the updated SDK, because the types are incompatible on-chain. The package version atlazer/contracts/sui/sdk/js/package.json:59remains0.3.0and was not bumped despite this being a breaking change. Per REVIEW.md guidelines, public packages with changes should have their version bumped — suggest a minor bump to0.4.0(since semver 0.x allows breaking changes in minor versions).Was this helpful? React with 👍 or 👎 to provide feedback.