Skip to content

Commit b8782d0

Browse files
committed
Fee correctly used
1 parent 1ceed17 commit b8782d0

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

lazer/evm/src/ExampleReceiver.sol

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,20 @@ import {PythLazerLib} from "pyth-lazer/PythLazerLib.sol";
77

88
contract ExampleReceiver {
99
PythLazer pythLazer;
10+
uint256 verification_fee;
1011
uint64 public price;
1112
uint64 public timestamp;
1213

1314
constructor(address pythLazerAddress) {
1415
pythLazer = PythLazer(pythLazerAddress);
16+
verification_fee = pythLazer.verification_fee();
1517
}
1618

1719
function updatePrice(bytes calldata update) payable public {
18-
(bytes memory payload,) = pythLazer.verifyUpdate{value: pythLazer.verification_fee()}(update);
19-
if (msg.value > pythLazer.verification_fee()) {
20-
payable(msg.sender).transfer(msg.value - pythLazer.verification_fee());
20+
require(msg.value >= verification_fee, "Insufficient fee provided");
21+
(bytes memory payload,) = pythLazer.verifyUpdate{value: verification_fee}(update);
22+
if (msg.value > verification_fee) {
23+
payable(msg.sender).transfer(msg.value - verification_fee);
2124
}
2225

2326
(uint64 _timestamp, PythLazerLib.Channel channel, uint8 feedsLen, uint16 pos) =

lazer/evm/test/ExampleReceiver.t.sol

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,27 @@ contract ExampleReceiverTest is Test {
1515
address lazer = makeAddr("lazer");
1616
PythLazer pythLazer = new PythLazer();
1717
pythLazer.initialize(lazer);
18+
1819
vm.prank(lazer);
1920
pythLazer.updateTrustedSigner(trustedSigner, 3000000000000000);
21+
uint256 fee = pythLazer.verification_fee();
2022

2123
address consumer = makeAddr("consumer");
24+
vm.deal(consumer, 10 wei);
25+
2226
ExampleReceiver receiver = new ExampleReceiver(address(pythLazer));
2327
bytes memory update =
2428
hex"2a22999a577d3cc0202197939d736bc0dcf71b9dde7b9470e4d16fa8e2120c0787a1c0d744d0c39cc372af4d1ecf2d09e84160ca905f3f597d20e2eec144a446a0459ad600001c93c7d3750006240af373971c01010000000201000000000005f5e100";
2529
console.logBytes(update);
2630

27-
vm.deal(consumer, 1 ether);
2831
vm.prank(consumer);
29-
receiver.updatePrice{value: pythLazer.verification_fee()}(update);
32+
receiver.updatePrice{value: 5 * fee}(update);
33+
3034
assertEq(receiver.price(), 100000000);
3135
assertEq(receiver.timestamp(), 1728479312975644);
32-
assertEq(address(pythLazer).balance, pythLazer.verification_fee());
33-
assertEq(consumer.balance, 1 ether - pythLazer.verification_fee());
36+
37+
assertEq(address(pythLazer).balance, fee);
38+
assertEq(address(receiver).balance, 0);
39+
assertEq(consumer.balance, 10 wei - fee);
3440
}
3541
}

0 commit comments

Comments
 (0)