Skip to content

Commit 7f0faa6

Browse files
Darun Seethammagaridarunrs
authored andcommitted
Add fees and test
1 parent 1e169bd commit 7f0faa6

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

lazer/contracts/evm/src/PythLazer.sol

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
66

77
contract PythLazer is OwnableUpgradeable, UUPSUpgradeable {
88
TrustedSignerInfo[2] public trustedSigners;
9+
uint256 public verification_fee = 0.01 ether;
910

1011
struct TrustedSignerInfo {
1112
address pubkey;
@@ -62,7 +63,13 @@ contract PythLazer is OwnableUpgradeable, UUPSUpgradeable {
6263

6364
function verifyUpdate(
6465
bytes calldata update
65-
) external view returns (bytes calldata payload, address signer) {
66+
) external payable returns (bytes calldata payload, address signer) {
67+
// Require fee and refund excess
68+
require(msg.value >= verification_fee, "Insufficient fee provided");
69+
if (msg.value > verification_fee) {
70+
payable(msg.sender).transfer(msg.value - verification_fee);
71+
}
72+
6673
if (update.length < 71) {
6774
revert("input too short");
6875
}

lazer/contracts/evm/test/PythLazer.t.sol

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,40 @@ contract PythLazerTest is Test {
2020
skip(2000);
2121
assert(!pythLazer.isValidSigner(address(2)));
2222
}
23+
24+
function test_verify_with_fee() public {
25+
// Prepare dummy update and signer
26+
address trustedSigner = 0xEfEf56cD66896f6799A90A4e4d512C330c094e44;
27+
vm.prank(address(1));
28+
pythLazer.updateTrustedSigner(trustedSigner, 3000000000000000);
29+
bytes memory update = hex"2a22999a577d3cc0202197939d736bc0dcf71b9dde7b9470e4d16fa8e2120c0787a1c0d744d0c39cc372af4d1ecf2d09e84160ca905f3f597d20e2eec144a446a0459ad600001c93c7d3750006240af373971c01010000000201000000000005f5e100";
30+
31+
uint256 fee = pythLazer.verification_fee();
32+
33+
address alice = makeAddr("alice");
34+
vm.deal(alice, 1 ether);
35+
address bob = makeAddr("bob");
36+
vm.deal(bob, 1 ether);
37+
38+
// Alice provides appropriate fee
39+
vm.prank(alice);
40+
pythLazer.verifyUpdate{ value: fee }(update);
41+
assertEq(alice.balance, 1 ether - fee);
42+
43+
// Alice overpays and is refunded
44+
vm.prank(alice);
45+
pythLazer.verifyUpdate{ value: 0.5 ether }(update);
46+
assertEq(alice.balance, 1 ether - fee - fee);
47+
48+
// Bob does not attach a fee
49+
vm.prank(bob);
50+
vm.expectRevert("Insufficient fee provided");
51+
pythLazer.verifyUpdate(update);
52+
assertEq(bob.balance, 1 ether);
53+
54+
// Bob does not attach enough fees
55+
vm.expectRevert("Insufficient fee provided");
56+
pythLazer.verifyUpdate{ value: 0.00001 ether }(update);
57+
assertEq(bob.balance, 1 ether);
58+
}
2359
}

0 commit comments

Comments
 (0)