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 1 commit
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
8 changes: 8 additions & 0 deletions lazer/evm/src/ExampleReceiver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
6 changes: 4 additions & 2 deletions lazer/evm/test/ExampleReceiver.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
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.4.0",
"@solana/web3.js": "^1.98.0"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion lazer/js/src/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ const main = async () => {
properties: ["price"],
chains: ["solana"],
deliveryFormat: "json",
channel: "real_time",
channel: "fixed_rate@1ms",
jsonBinaryEncoding: "hex",
});
};
Expand Down
Loading