Skip to content

feat(lazer): Update EVM example to attach fee for verification #39

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 5 commits into from
Dec 17, 2024
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
2 changes: 1 addition & 1 deletion lazer/evm/lib/forge-std
2 changes: 1 addition & 1 deletion lazer/evm/lib/pyth-crosschain
Submodule pyth-crosschain updated 342 files
10 changes: 8 additions & 2 deletions lazer/evm/src/ExampleReceiver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,14 @@ contract ExampleReceiver {
pythLazer = PythLazer(pythLazerAddress);
}

function updatePrice(bytes calldata update) public {
(bytes memory payload,) = pythLazer.verifyUpdate(update);
function updatePrice(bytes calldata update) public payable {
uint256 verification_fee = pythLazer.verification_fee();
require(msg.value >= verification_fee, "Insufficient fee provided");
(bytes memory payload,) = pythLazer.verifyUpdate{value: verification_fee}(update);
if (msg.value > verification_fee) {
payable(msg.sender).transfer(msg.value - verification_fee);
}

(uint64 _timestamp, PythLazerLib.Channel channel, uint8 feedsLen, uint16 pos) =
PythLazerLib.parsePayloadHeader(payload);
console.log("timestamp %d", _timestamp);
Expand Down
19 changes: 15 additions & 4 deletions lazer/evm/test/ExampleReceiver.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,30 @@ contract ExampleReceiverTest is Test {
address trustedSigner = 0xEfEf56cD66896f6799A90A4e4d512C330c094e44;
console.log("trustedSigner %s", trustedSigner);

address lazer = makeAddr("lazer");
PythLazer pythLazer = new PythLazer();
pythLazer.initialize(address(0x1));
vm.prank(address(0x1));
pythLazer.initialize(lazer);

vm.prank(lazer);
pythLazer.updateTrustedSigner(trustedSigner, 3000000000000000);
uint256 fee = pythLazer.verification_fee();

ExampleReceiver receiver = new ExampleReceiver(address(pythLazer));
address consumer = makeAddr("consumer");
vm.deal(consumer, 10 wei);

ExampleReceiver receiver = new ExampleReceiver(address(pythLazer));
bytes memory update =
hex"2a22999a577d3cc0202197939d736bc0dcf71b9dde7b9470e4d16fa8e2120c0787a1c0d744d0c39cc372af4d1ecf2d09e84160ca905f3f597d20e2eec144a446a0459ad600001c93c7d3750006240af373971c01010000000201000000000005f5e100";
console.logBytes(update);

receiver.updatePrice(update);
vm.prank(consumer);
receiver.updatePrice{value: 5 * fee}(update);

assertEq(receiver.price(), 100000000);
assertEq(receiver.timestamp(), 1728479312975644);

assertEq(address(pythLazer).balance, fee);
assertEq(address(receiver).balance, 0);
assertEq(consumer.balance, 10 wei - fee);
}
}