Skip to content

feat: add support for custom update fees #2575

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
7 changes: 5 additions & 2 deletions target_chains/ethereum/contracts/contracts/pyth/Pyth.sol
Original file line number Diff line number Diff line change
Expand Up @@ -493,8 +493,11 @@ abstract contract Pyth is
function getTotalFee(
uint totalNumUpdates
) private view returns (uint requiredFee) {
return
(totalNumUpdates * singleUpdateFeeInWei()) + transactionFeeInWei();
uint updateFee = customUpdateFeeInWei(msg.sender);
if (updateFee == 0) {
updateFee = singleUpdateFeeInWei();
}
return (totalNumUpdates * updateFee) + transactionFeeInWei();
}

function findIndexOfPriceId(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,8 @@ contract PythGetters is PythState {
function transactionFeeInWei() public view returns (uint) {
return _state.transactionFeeInWei;
}

function customUpdateFeeInWei(address addr) public view returns (uint) {
return _state.customUpdateFeeInWei[addr];
}
}
13 changes: 13 additions & 0 deletions target_chains/ethereum/contracts/contracts/pyth/PythGovernance.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ abstract contract PythGovernance is
address newWormholeAddress
);
event TransactionFeeSet(uint oldFee, uint newFee);
event CustomFeeSet(address indexed target, uint oldFee, uint newFee);

struct SetCustomFeePayload {
address target;
uint newFee;
}

function verifyGovernanceVM(
bytes memory encodedVM
Expand Down Expand Up @@ -255,4 +261,11 @@ abstract contract PythGovernance is

emit TransactionFeeSet(oldFee, transactionFeeInWei());
}

function setCustomFee(SetCustomFeePayload memory payload) internal {
uint oldFee = customUpdateFeeInWei(payload.target);
setCustomUpdateFeeInWei(payload.target, payload.newFee);

emit CustomFeeSet(payload.target, oldFee, payload.newFee);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pragma solidity ^0.8.0;

import "./PythState.sol";
import "@pythnetwork/pyth-sdk-solidity/IPythEvents.sol";
import "./PythInternalStructs.sol";

contract PythSetters is PythState, IPythEvents {
function setWormhole(address wh) internal {
Expand Down Expand Up @@ -52,4 +53,8 @@ contract PythSetters is PythState, IPythEvents {
function setTransactionFeeInWei(uint fee) internal {
_state.transactionFeeInWei = fee;
}

function setCustomUpdateFeeInWei(address addr, uint fee) internal {
_state.customUpdateFeeInWei[addr] = fee;
}
}
2 changes: 2 additions & 0 deletions target_chains/ethereum/contracts/contracts/pyth/PythState.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ contract PythStorage {
mapping(bytes32 => PythInternalStructs.PriceInfo) latestPriceInfo;
// Fee charged per transaction, in addition to per-update fees
uint transactionFeeInWei;
// Mapping of address to custom fee per update (0 means use default fee)
mapping(address => uint) customUpdateFeeInWei;
}
}

Expand Down
Loading