Skip to content

feat(lazer): Update EVM Example and Test #46

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

Merged
merged 6 commits into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from 4 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
1 change: 1 addition & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion lazer/evm/lib/pyth-crosschain
Submodule pyth-crosschain updated 486 files
14 changes: 13 additions & 1 deletion lazer/evm/src/ExampleReceiver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -43,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;
}
Expand All @@ -55,6 +57,16 @@ 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);
exponent = _exponent;
} else if (property == PythLazerLib.PriceFeedProperty.PublisherCount) {
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");
}
Expand Down
8 changes: 5 additions & 3 deletions lazer/evm/test/ExampleReceiver.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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.publisher_count(), 1);

assertEq(address(pythLazer).balance, fee);
assertEq(address(receiver).balance, 0);
Expand Down
2 changes: 1 addition & 1 deletion lazer/js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"author": "",
"license": "Apache-2.0",
"dependencies": {
"@pythnetwork/pyth-lazer-sdk": "^0.3.1",
"@pythnetwork/pyth-lazer-sdk": "^0.3.2",
"@solana/web3.js": "^1.98.0"
},
"devDependencies": {
Expand Down
Loading