Skip to content

Commit b130e98

Browse files
committed
feat: update fee withdrawal logic to use value and exponent for amount calculation
1 parent 7714abb commit b130e98

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

target_chains/ethereum/contracts/contracts/pyth/PythGovernanceInstructions.sol

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,13 @@ contract PythGovernanceInstructions {
260260
wf.targetAddress = address(encodedPayload.toAddress(index));
261261
index += 20;
262262

263-
wf.amount = encodedPayload.toUint256(index);
264-
index += 32;
263+
uint64 val = encodedPayload.toUint64(index);
264+
index += 8;
265+
266+
uint64 expo = encodedPayload.toUint64(index);
267+
index += 8;
268+
269+
wf.amount = uint256(val) * uint256(10) ** uint256(expo);
265270

266271
if (encodedPayload.length != index)
267272
revert PythErrors.InvalidGovernanceMessage();

target_chains/ethereum/contracts/forge-test/PythGovernance.t.sol

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,6 @@ contract PythGovernanceTest is
563563
assertEq(address(pyth).balance, 1 ether);
564564

565565
address recipient = makeAddr("recipient");
566-
uint256 withdrawAmount = 0.5 ether;
567566

568567
// Create governance VAA to withdraw fee
569568
bytes memory withdrawMessage = abi.encodePacked(
@@ -572,7 +571,8 @@ contract PythGovernanceTest is
572571
uint8(GovernanceAction.WithdrawFee),
573572
TARGET_CHAIN_ID,
574573
recipient,
575-
withdrawAmount
574+
uint64(5), // value = 5
575+
uint64(17) // exponent = 17 (5 * 10^17 = 0.5 ether)
576576
);
577577

578578
bytes memory vaa = encodeAndSignMessage(
@@ -583,7 +583,7 @@ contract PythGovernanceTest is
583583
);
584584

585585
vm.expectEmit(true, true, true, true);
586-
emit FeeWithdrawn(recipient, withdrawAmount);
586+
emit FeeWithdrawn(recipient, 0.5 ether);
587587

588588
PythGovernance(address(pyth)).executeGovernanceInstruction(vaa);
589589

@@ -598,7 +598,6 @@ contract PythGovernanceTest is
598598
assertEq(address(pyth).balance, 1 ether);
599599

600600
address recipient = makeAddr("recipient");
601-
uint256 withdrawAmount = 2 ether; // More than contract balance
602601

603602
// Create governance VAA to withdraw fee
604603
bytes memory withdrawMessage = abi.encodePacked(
@@ -607,7 +606,8 @@ contract PythGovernanceTest is
607606
uint8(GovernanceAction.WithdrawFee),
608607
TARGET_CHAIN_ID,
609608
recipient,
610-
withdrawAmount
609+
uint64(2), // value = 2
610+
uint64(18) // exponent = 18 (2 * 10^18 = 2 ether, more than balance)
611611
);
612612

613613
bytes memory vaa = encodeAndSignMessage(
@@ -627,7 +627,6 @@ contract PythGovernanceTest is
627627

628628
function testWithdrawFeeInvalidGovernance() public {
629629
address recipient = makeAddr("recipient");
630-
uint256 withdrawAmount = 0.5 ether;
631630

632631
// Create governance VAA with wrong emitter
633632
bytes memory withdrawMessage = abi.encodePacked(
@@ -636,7 +635,8 @@ contract PythGovernanceTest is
636635
uint8(GovernanceAction.WithdrawFee),
637636
TARGET_CHAIN_ID,
638637
recipient,
639-
withdrawAmount
638+
uint64(5), // value = 5
639+
uint64(17) // exponent = 17 (5 * 10^17 = 0.5 ether)
640640
);
641641

642642
bytes memory vaa = encodeAndSignMessage(

0 commit comments

Comments
 (0)