From 921def04bfa27adf160e9cd4df7583304325f74b Mon Sep 17 00:00:00 2001 From: Darun Seethammagari Date: Thu, 30 Jan 2025 13:14:44 -0800 Subject: [PATCH 1/6] Update example evm and js --- lazer/evm/src/ExampleReceiver.sol | 8 ++++++++ lazer/evm/test/ExampleReceiver.t.sol | 6 ++++-- lazer/js/package.json | 2 +- lazer/js/src/publish.ts | 2 +- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/lazer/evm/src/ExampleReceiver.sol b/lazer/evm/src/ExampleReceiver.sol index efddf0c..adc19ca 100644 --- a/lazer/evm/src/ExampleReceiver.sol +++ b/lazer/evm/src/ExampleReceiver.sol @@ -55,6 +55,14 @@ contract ExampleReceiver { uint64 _price; (_price, pos) = PythLazerLib.parseFeedValueUint64(payload, pos); console.log("best ask price %d", _price); + } else if (property == PythLazerLib.PriceFeedProperty.Exponent) { + int16 _exponent; + (_exponent, pos) = PythLazerLib.parseFeedValueInt16(payload, pos); + console.log("exponent %d", _exponent); + } else if (property == PythLazerLib.PriceFeedProperty.PublisherCount) { + int16 _publisher_count; + (_publisher_count, pos) = PythLazerLib.parseFeedValueUint16(payload, pos); + console.log("publisher count %d", _publisher_count); } else { revert("unknown property"); } diff --git a/lazer/evm/test/ExampleReceiver.t.sol b/lazer/evm/test/ExampleReceiver.t.sol index a643c2d..58861c0 100644 --- a/lazer/evm/test/ExampleReceiver.t.sol +++ b/lazer/evm/test/ExampleReceiver.t.sol @@ -25,14 +25,16 @@ contract ExampleReceiverTest is Test { ExampleReceiver receiver = new ExampleReceiver(address(pythLazer)); bytes memory update = - hex"2a22999a577d3cc0202197939d736bc0dcf71b9dde7b9470e4d16fa8e2120c0787a1c0d744d0c39cc372af4d1ecf2d09e84160ca905f3f597d20e2eec144a446a0459ad600001c93c7d3750006240af373971c01010000000201000000000005f5e100"; + hex"2a22999a9ee4e2a3df5affd0ad8c7c46c96d3b5ef197dd653bedd8f44a4b6b69b767fbc66341e80b80acb09ead98c60d169b9a99657ebada101f447378f227bffbc69d3d01003493c7d37500062cf28659c1e801010000000605000000000005f5e10002000000000000000001000000000000000003000104fff8"; console.logBytes(update); vm.prank(consumer); receiver.updatePrice{value: 5 * fee}(update); + assertEq(receiver.timestamp(), 1738270008001000); assertEq(receiver.price(), 100000000); - assertEq(receiver.timestamp(), 1728479312975644); + assertEq(receiver.exponent(), -8); + assertEq(receiver.publisherCount(), 1); assertEq(address(pythLazer).balance, fee); assertEq(address(receiver).balance, 0); diff --git a/lazer/js/package.json b/lazer/js/package.json index 3ce9f90..f8e3e6b 100644 --- a/lazer/js/package.json +++ b/lazer/js/package.json @@ -16,7 +16,7 @@ "author": "", "license": "Apache-2.0", "dependencies": { - "@pythnetwork/pyth-lazer-sdk": "^0.3.1", + "@pythnetwork/pyth-lazer-sdk": "^0.4.0", "@solana/web3.js": "^1.98.0" }, "devDependencies": { diff --git a/lazer/js/src/publish.ts b/lazer/js/src/publish.ts index 20ef367..4742b33 100644 --- a/lazer/js/src/publish.ts +++ b/lazer/js/src/publish.ts @@ -168,7 +168,7 @@ const main = async () => { properties: ["price"], chains: ["solana"], deliveryFormat: "json", - channel: "real_time", + channel: "fixed_rate@1ms", jsonBinaryEncoding: "hex", }); }; From 5e38857a0257cd2aec9fafadee6195328582ea16 Mon Sep 17 00:00:00 2001 From: Darun Seethammagari Date: Mon, 3 Feb 2025 06:54:34 -0800 Subject: [PATCH 2/6] Not perfectly working test --- .gitmodules | 1 + lazer/evm/lib/pyth-crosschain | 2 +- lazer/evm/src/ExampleReceiver.sol | 6 +++++- lazer/evm/test/ExampleReceiver.t.sol | 4 ++-- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/.gitmodules b/.gitmodules index 5ba4828..6b8114a 100644 --- a/.gitmodules +++ b/.gitmodules @@ -7,6 +7,7 @@ [submodule "lazer/evm/lib/openzeppelin-contracts-upgradeable"] path = lazer/evm/lib/openzeppelin-contracts-upgradeable url = https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable + branch = remove-realtime-channel-js [submodule "price_feeds/evm/pyth_sample/lib/forge-std"] path = price_feeds/evm/pyth_sample/lib/forge-std url = https://github.com/foundry-rs/forge-std diff --git a/lazer/evm/lib/pyth-crosschain b/lazer/evm/lib/pyth-crosschain index cc16040..1cc64d5 160000 --- a/lazer/evm/lib/pyth-crosschain +++ b/lazer/evm/lib/pyth-crosschain @@ -1 +1 @@ -Subproject commit cc16040038691a5a5a499661d8de0daba8eed4c3 +Subproject commit 1cc64d5a16e84025ff1718ca76d96a58dc2072d0 diff --git a/lazer/evm/src/ExampleReceiver.sol b/lazer/evm/src/ExampleReceiver.sol index adc19ca..2cd58c0 100644 --- a/lazer/evm/src/ExampleReceiver.sol +++ b/lazer/evm/src/ExampleReceiver.sol @@ -9,6 +9,8 @@ contract ExampleReceiver { PythLazer pythLazer; uint64 public price; uint64 public timestamp; + int16 public exponent; + uint16 public publisher_count; constructor(address pythLazerAddress) { pythLazer = PythLazer(pythLazerAddress); @@ -59,10 +61,12 @@ contract ExampleReceiver { int16 _exponent; (_exponent, pos) = PythLazerLib.parseFeedValueInt16(payload, pos); console.log("exponent %d", _exponent); + exponent = _exponent; } else if (property == PythLazerLib.PriceFeedProperty.PublisherCount) { - int16 _publisher_count; + uint16 _publisher_count; (_publisher_count, pos) = PythLazerLib.parseFeedValueUint16(payload, pos); console.log("publisher count %d", _publisher_count); + publisher_count = _publisher_count; } else { revert("unknown property"); } diff --git a/lazer/evm/test/ExampleReceiver.t.sol b/lazer/evm/test/ExampleReceiver.t.sol index 58861c0..dbe2587 100644 --- a/lazer/evm/test/ExampleReceiver.t.sol +++ b/lazer/evm/test/ExampleReceiver.t.sol @@ -9,7 +9,7 @@ contract ExampleReceiverTest is Test { function setUp() public {} function test_1() public { - address trustedSigner = 0xEfEf56cD66896f6799A90A4e4d512C330c094e44; + address trustedSigner = 0xb8d50f0bAE75BF6E03c104903d7C3aFc4a6596Da; console.log("trustedSigner %s", trustedSigner); address lazer = makeAddr("lazer"); @@ -34,7 +34,7 @@ contract ExampleReceiverTest is Test { assertEq(receiver.timestamp(), 1738270008001000); assertEq(receiver.price(), 100000000); assertEq(receiver.exponent(), -8); - assertEq(receiver.publisherCount(), 1); + assertEq(receiver.publisher_count(), 1); assertEq(address(pythLazer).balance, fee); assertEq(address(receiver).balance, 0); From cb3e44c1aee77011b811ec7a1ed22b85308a86d6 Mon Sep 17 00:00:00 2001 From: Darun Seethammagari Date: Mon, 3 Feb 2025 09:11:04 -0800 Subject: [PATCH 3/6] Update JS to use real time and make tests pass --- lazer/evm/lib/pyth-crosschain | 2 +- lazer/evm/src/ExampleReceiver.sol | 2 +- lazer/js/src/publish.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lazer/evm/lib/pyth-crosschain b/lazer/evm/lib/pyth-crosschain index 1cc64d5..d305a40 160000 --- a/lazer/evm/lib/pyth-crosschain +++ b/lazer/evm/lib/pyth-crosschain @@ -1 +1 @@ -Subproject commit 1cc64d5a16e84025ff1718ca76d96a58dc2072d0 +Subproject commit d305a40406985f37c2ada43cbcb6b55658b7e192 diff --git a/lazer/evm/src/ExampleReceiver.sol b/lazer/evm/src/ExampleReceiver.sol index 2cd58c0..6a8b68b 100644 --- a/lazer/evm/src/ExampleReceiver.sol +++ b/lazer/evm/src/ExampleReceiver.sol @@ -45,7 +45,7 @@ contract ExampleReceiver { uint64 _price; (_price, pos) = PythLazerLib.parseFeedValueUint64(payload, pos); console.log("price %d", _price); - if (feedId == 2 && _timestamp > timestamp) { + if (feedId == 6 && _timestamp > timestamp) { price = _price; timestamp = _timestamp; } diff --git a/lazer/js/src/publish.ts b/lazer/js/src/publish.ts index 4742b33..20ef367 100644 --- a/lazer/js/src/publish.ts +++ b/lazer/js/src/publish.ts @@ -168,7 +168,7 @@ const main = async () => { properties: ["price"], chains: ["solana"], deliveryFormat: "json", - channel: "fixed_rate@1ms", + channel: "real_time", jsonBinaryEncoding: "hex", }); }; From e1167f84a6076bfa7c5c9d041eb1d20263d01684 Mon Sep 17 00:00:00 2001 From: Darun Seethammagari Date: Mon, 3 Feb 2025 09:13:27 -0800 Subject: [PATCH 4/6] Change js sdk version usage --- lazer/js/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lazer/js/package.json b/lazer/js/package.json index f8e3e6b..4c810b7 100644 --- a/lazer/js/package.json +++ b/lazer/js/package.json @@ -16,7 +16,7 @@ "author": "", "license": "Apache-2.0", "dependencies": { - "@pythnetwork/pyth-lazer-sdk": "^0.4.0", + "@pythnetwork/pyth-lazer-sdk": "^0.3.2", "@solana/web3.js": "^1.98.0" }, "devDependencies": { From a12ea3f5324c515844ae79b49a69c52052f9fb4d Mon Sep 17 00:00:00 2001 From: Darun Seethammagari Date: Mon, 3 Feb 2025 09:15:39 -0800 Subject: [PATCH 5/6] No change to js package json --- lazer/js/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lazer/js/package.json b/lazer/js/package.json index 4c810b7..3ce9f90 100644 --- a/lazer/js/package.json +++ b/lazer/js/package.json @@ -16,7 +16,7 @@ "author": "", "license": "Apache-2.0", "dependencies": { - "@pythnetwork/pyth-lazer-sdk": "^0.3.2", + "@pythnetwork/pyth-lazer-sdk": "^0.3.1", "@solana/web3.js": "^1.98.0" }, "devDependencies": { From ac151435400233b5689147a08a009983728a7e67 Mon Sep 17 00:00:00 2001 From: Darun Seethammagari Date: Mon, 3 Feb 2025 09:23:10 -0800 Subject: [PATCH 6/6] Use main branch crosschain --- .gitmodules | 1 - lazer/evm/lib/pyth-crosschain | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.gitmodules b/.gitmodules index 6b8114a..5ba4828 100644 --- a/.gitmodules +++ b/.gitmodules @@ -7,7 +7,6 @@ [submodule "lazer/evm/lib/openzeppelin-contracts-upgradeable"] path = lazer/evm/lib/openzeppelin-contracts-upgradeable url = https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable - branch = remove-realtime-channel-js [submodule "price_feeds/evm/pyth_sample/lib/forge-std"] path = price_feeds/evm/pyth_sample/lib/forge-std url = https://github.com/foundry-rs/forge-std diff --git a/lazer/evm/lib/pyth-crosschain b/lazer/evm/lib/pyth-crosschain index d305a40..5ef46e4 160000 --- a/lazer/evm/lib/pyth-crosschain +++ b/lazer/evm/lib/pyth-crosschain @@ -1 +1 @@ -Subproject commit d305a40406985f37c2ada43cbcb6b55658b7e192 +Subproject commit 5ef46e4986f22faaddf45b662401178292bb2e57