Skip to content
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
14 changes: 7 additions & 7 deletions contracts-abi/abi/BidderRegistry.abi
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@
"internalType": "address"
},
{
"name": "_feePayoutPeriodBlocks",
"name": "_feePayoutPeriod",
"type": "uint256",
"internalType": "uint256"
}
Expand Down Expand Up @@ -392,12 +392,12 @@
"internalType": "uint256"
},
{
"name": "lastPayoutBlock",
"name": "lastPayoutTimestamp",
"type": "uint256",
"internalType": "uint256"
},
{
"name": "payoutPeriodBlocks",
"name": "payoutTimePeriod",
"type": "uint256",
"internalType": "uint256"
}
Expand Down Expand Up @@ -486,10 +486,10 @@
},
{
"type": "function",
"name": "setNewFeePayoutPeriodBlocks",
"name": "setNewFeePayoutPeriod",
"inputs": [
{
"name": "newFeePayoutPeriodBlocks",
"name": "newFeePayoutPeriod",
"type": "uint256",
"internalType": "uint256"
}
Expand Down Expand Up @@ -725,10 +725,10 @@
},
{
"type": "event",
"name": "FeePayoutPeriodBlocksUpdated",
"name": "FeePayoutPeriodUpdated",
"inputs": [
{
"name": "newFeePayoutPeriodBlocks",
"name": "newFeePayoutPeriod",
"type": "uint256",
"indexed": true,
"internalType": "uint256"
Expand Down
14 changes: 7 additions & 7 deletions contracts-abi/abi/ProviderRegistry.abi
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@
"internalType": "uint256"
},
{
"name": "_penaltyFeePayoutPeriodBlocks",
"name": "_penaltyFeePayoutPeriod",
"type": "uint256",
"internalType": "uint256"
}
Expand Down Expand Up @@ -385,12 +385,12 @@
"internalType": "uint256"
},
{
"name": "lastPayoutBlock",
"name": "lastPayoutTimestamp",
"type": "uint256",
"internalType": "uint256"
},
{
"name": "payoutPeriodBlocks",
"name": "payoutTimePeriod",
"type": "uint256",
"internalType": "uint256"
}
Expand Down Expand Up @@ -490,10 +490,10 @@
},
{
"type": "function",
"name": "setFeePayoutPeriodBlocks",
"name": "setFeePayoutPeriod",
"inputs": [
{
"name": "_feePayoutPeriodBlocks",
"name": "_feePayoutPeriod",
"type": "uint256",
"internalType": "uint256"
}
Expand Down Expand Up @@ -766,10 +766,10 @@
},
{
"type": "event",
"name": "FeePayoutPeriodBlocksUpdated",
"name": "FeePayoutPeriodUpdated",
"inputs": [
{
"name": "newFeePayoutPeriodBlocks",
"name": "newFeePayoutPeriod",
"type": "uint256",
"indexed": true,
"internalType": "uint256"
Expand Down
154 changes: 77 additions & 77 deletions contracts-abi/clients/BidderRegistry/BidderRegistry.go

Large diffs are not rendered by default.

154 changes: 77 additions & 77 deletions contracts-abi/clients/ProviderRegistry/ProviderRegistry.go

Large diffs are not rendered by default.

22 changes: 11 additions & 11 deletions contracts/contracts/core/BidderRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,16 @@ contract BidderRegistry is
* @param _feePercent The fee percentage for protocol
* @param _owner Owner of the contract, explicitly needed since contract is deployed w/ create2 factory.
* @param _blockTracker The address of the block tracker contract.
* @param _feePayoutPeriodBlocks The number of blocks for the fee payout period
* @param _feePayoutPeriod The number of seconds or ms on the mev-commit chain for the fee payout period
*/
function initialize(
address _protocolFeeRecipient,
uint256 _feePercent,
address _owner,
address _blockTracker,
uint256 _feePayoutPeriodBlocks
uint256 _feePayoutPeriod
) external initializer {
FeePayout.init(protocolFeeTracker, _protocolFeeRecipient, _feePayoutPeriodBlocks);
FeePayout.initTimestampTracker(protocolFeeTracker, _protocolFeeRecipient, _feePayoutPeriod);
feePercent = _feePercent;
blockTrackerContract = IBlockTracker(_blockTracker);
__ReentrancyGuard_init();
Expand Down Expand Up @@ -179,8 +179,8 @@ contract BidderRegistry is
uint256 amtMinusFeeAndDecay = decayedAmt - feeAmt;

protocolFeeTracker.accumulatedAmount += feeAmt;
if (FeePayout.isPayoutDue(protocolFeeTracker)) {
FeePayout.transferToRecipient(protocolFeeTracker);
if (FeePayout.isPayoutDueByTimestamp(protocolFeeTracker)) {
FeePayout.transferToRecipientByTimestamp(protocolFeeTracker);
}

providerAmount[provider] += amtMinusFeeAndDecay;
Expand Down Expand Up @@ -316,13 +316,13 @@ contract BidderRegistry is
}

/**
* @notice Sets the new fee payout period in blocks
* @notice Sets the new fee payout period in seconds or ms on the mev-commit chain
* @dev onlyOwner restriction
* @param newFeePayoutPeriodBlocks The new fee payout period in blocks
* @param newFeePayoutPeriod The new fee payout period in seconds or ms on the mev-commit chain
*/
function setNewFeePayoutPeriodBlocks(uint256 newFeePayoutPeriodBlocks) external onlyOwner {
protocolFeeTracker.payoutPeriodBlocks = newFeePayoutPeriodBlocks;
emit FeePayoutPeriodBlocksUpdated(newFeePayoutPeriodBlocks);
function setNewFeePayoutPeriod(uint256 newFeePayoutPeriod) external onlyOwner {
protocolFeeTracker.payoutTimePeriod = newFeePayoutPeriod;
emit FeePayoutPeriodUpdated(newFeePayoutPeriod);
}

/**
Expand Down Expand Up @@ -376,7 +376,7 @@ contract BidderRegistry is
* to cover the edge case that oracle doesn't slash/reward, and funds still need to be withdrawn.
*/
function manuallyWithdrawProtocolFee() external onlyOwner {
FeePayout.transferToRecipient(protocolFeeTracker);
FeePayout.transferToRecipientByTimestamp(protocolFeeTracker);
}

/// @dev Allows owner to pause the contract.
Expand Down
2 changes: 1 addition & 1 deletion contracts/contracts/core/BidderRegistryStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ abstract contract BidderRegistryStorage {
IBlockTracker public blockTrackerContract;

/// Struct enabling automatic protocol fee payouts
FeePayout.Tracker public protocolFeeTracker;
FeePayout.TimestampTracker public protocolFeeTracker;

// Mapping from bidder addresses and window numbers to their locked funds
mapping(address => mapping(uint256 => uint256)) public lockedFunds;
Expand Down
26 changes: 13 additions & 13 deletions contracts/contracts/core/ProviderRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,20 @@ contract ProviderRegistry is
* @param _feePercent The fee percentage for penalty
* @param _owner Owner of the contract, explicitly needed since contract is deployed w/ create2 factory.
* @param _withdrawalDelay The withdrawal delay in milliseconds.
* @param _penaltyFeePayoutPeriodBlocks The min number of blocks between penalty fee payouts
* @param _penaltyFeePayoutPeriod The min number of seconds (or ms on the mev-commit chain) between penalty fee payouts
*/
function initialize(
uint256 _minStake,
address _penaltyFeeRecipient,
uint256 _feePercent,
address _owner,
uint256 _withdrawalDelay,
uint256 _penaltyFeePayoutPeriodBlocks
uint256 _penaltyFeePayoutPeriod
) external initializer {
FeePayout.init(
FeePayout.initTimestampTracker(
penaltyFeeTracker,
_penaltyFeeRecipient,
_penaltyFeePayoutPeriodBlocks
_penaltyFeePayoutPeriod
);
minStake = _minStake;
feePercent = _feePercent;
Expand Down Expand Up @@ -151,8 +151,8 @@ contract ProviderRegistry is
providerStakes[provider] = providerStake - totalSlash;
penaltyFeeTracker.accumulatedAmount += penaltyFee;

if (FeePayout.isPayoutDue(penaltyFeeTracker)) {
FeePayout.transferToRecipient(penaltyFeeTracker);
if (FeePayout.isPayoutDueByTimestamp(penaltyFeeTracker)) {
FeePayout.transferToRecipientByTimestamp(penaltyFeeTracker);
}

if (!payable(bidder).send(bidderPortion)) {
Expand Down Expand Up @@ -211,13 +211,13 @@ contract ProviderRegistry is
emit PenaltyFeeRecipientUpdated(newFeeRecipient);
}

/// @dev Sets the fee payout period in blocks
/// @param _feePayoutPeriodBlocks The new fee payout period in blocks
function setFeePayoutPeriodBlocks(
uint256 _feePayoutPeriodBlocks
/// @dev Sets the fee payout period in seconds (or ms on the mev-commit chain)
/// @param _feePayoutPeriod The new fee payout period in seconds (or ms on the mev-commit chain)
function setFeePayoutPeriod(
uint256 _feePayoutPeriod
) external onlyOwner {
penaltyFeeTracker.payoutPeriodBlocks = _feePayoutPeriodBlocks;
emit FeePayoutPeriodBlocksUpdated(_feePayoutPeriodBlocks);
penaltyFeeTracker.payoutTimePeriod = _feePayoutPeriod;
emit FeePayoutPeriodUpdated(_feePayoutPeriod);
}

function overrideAddBLSKey(
Expand Down Expand Up @@ -334,7 +334,7 @@ contract ProviderRegistry is
* to cover the edge case that oracle doesn't slash/reward, and funds still need to be withdrawn.
*/
function manuallyWithdrawPenaltyFee() external onlyOwner {
FeePayout.transferToRecipient(penaltyFeeTracker);
FeePayout.transferToRecipientByTimestamp(penaltyFeeTracker);
}

/// @dev Allows the owner to pause the contract.
Expand Down
2 changes: 1 addition & 1 deletion contracts/contracts/core/ProviderRegistryStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ abstract contract ProviderRegistryStorage {
uint256 public withdrawalDelay;

/// Struct enabling automatic penalty fee payouts
FeePayout.Tracker public penaltyFeeTracker;
FeePayout.TimestampTracker public penaltyFeeTracker;

/// @dev Mapping from provider address to whether they are registered or not
mapping(address => bool) public providerRegistered;
Expand Down
4 changes: 2 additions & 2 deletions contracts/contracts/interfaces/IBidderRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ interface IBidderRegistry {
/// @dev Event emitted when the block tracker is updated
event BlockTrackerUpdated(address indexed newBlockTracker);

/// @dev Event emitted when the fee payout period in blocks is updated
event FeePayoutPeriodBlocksUpdated(uint256 indexed newFeePayoutPeriodBlocks);
/// @dev Event emitted when the fee payout period is updated
event FeePayoutPeriodUpdated(uint256 indexed newFeePayoutPeriod);

/// @dev Event emitted when the protocol fee recipient is updated
event ProtocolFeeRecipientUpdated(address indexed newProtocolFeeRecipient);
Expand Down
4 changes: 2 additions & 2 deletions contracts/contracts/interfaces/IProviderRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ interface IProviderRegistry {
/// @dev Event emitted when the penalty fee recipient is updated
event PenaltyFeeRecipientUpdated(address indexed newPenaltyFeeRecipient);

/// @dev Event emitted when the fee payout period in blocks is updated
event FeePayoutPeriodBlocksUpdated(uint256 indexed newFeePayoutPeriodBlocks);
/// @dev Event emitted when the fee payout period is updated
event FeePayoutPeriodUpdated(uint256 indexed newFeePayoutPeriod);

/// @dev Event emitted when the min stake is updated
event MinStakeUpdated(uint256 indexed newMinStake);
Expand Down
39 changes: 39 additions & 0 deletions contracts/contracts/utils/FeePayout.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@ library FeePayout {
uint256 payoutPeriodBlocks;
}

struct TimestampTracker {
/// @dev Address that accumulates fees
address recipient;
/// @dev Accumulated fees since last payout
uint256 accumulatedAmount;
/// @dev Timestamp when the last fee payout was made
uint256 lastPayoutTimestamp;
/// @dev Min number of seconds (or ms on mev-commit chain) between payouts
uint256 payoutTimePeriod;
}

/// @dev Event emitted when fees are transferred to the recipient.
event FeeTransfer(uint256 amount, address indexed recipient);

Expand Down Expand Up @@ -42,10 +53,38 @@ library FeePayout {
emit FeeTransfer(amountToPay, tracker.recipient);
}

/// @dev Initialize a new timestamp fee tracker in storage
function initTimestampTracker(TimestampTracker storage self, address _recipient, uint256 _payoutTimePeriod) internal {
require(_recipient != address(0), FeeRecipientIsZero());
require(_payoutTimePeriod != 0, PayoutPeriodMustBePositive());
self.recipient = _recipient;
self.accumulatedAmount = 0;
self.lastPayoutTimestamp = block.timestamp;
self.payoutTimePeriod = _payoutTimePeriod;
}

/// @dev Transfers the accumulated fees to the recipient and resets the tracker
/// @param tracker The FeePayout.TimestampTracker struct
function transferToRecipientByTimestamp(TimestampTracker storage tracker) internal {
uint256 amountToPay = tracker.accumulatedAmount;
tracker.accumulatedAmount = 0;
tracker.lastPayoutTimestamp = block.timestamp;
(bool success, ) = payable(tracker.recipient).call{value: amountToPay}("");
require(success, TransferToRecipientFailed());
emit FeeTransfer(amountToPay, tracker.recipient);
}

/// @dev Checks if a fee payout is due
/// @param tracker The FeePayout.Tracker struct
/// @return true if a payout is due, false otherwise
function isPayoutDue(Tracker storage tracker) internal view returns (bool) {
return block.number > tracker.lastPayoutBlock + tracker.payoutPeriodBlocks;
}

/// @dev Checks if a fee payout is due by timestamp
/// @param tracker The FeePayout.TimestampTracker struct
/// @return true if a payout is due, false otherwise
function isPayoutDueByTimestamp(TimestampTracker storage tracker) internal view returns (bool) {
return block.timestamp > tracker.lastPayoutTimestamp + tracker.payoutTimePeriod;
}
}
6 changes: 3 additions & 3 deletions contracts/scripts/core/DeployCore.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ contract DeployCore is Script {
uint256 providerPenaltyPercent = 5 * PERCENT_MULTIPLIER; // 5%
uint64 commitmentDispatchWindow = 500;
uint256 withdrawalDelay = 24 hours * 1000; // 24 hours in milliseconds
uint256 protocolFeePayoutPeriodBlocks = 5 hours ; // 1 hour with 200ms blocks
uint256 protocolFeePayoutPeriod = 1 hours * 1000; // 1 hour with ms timestamps
address oracleKeystoreAddress = vm.envAddress("ORACLE_KEYSTORE_ADDRESS");
require(oracleKeystoreAddress != address(0), "missing Oracle keystore address");

Expand All @@ -53,7 +53,7 @@ contract DeployCore is Script {
feePercent, // _feePercent param
msg.sender, // _owner param
address(blockTracker), // _blockTracker param
protocolFeePayoutPeriodBlocks)) // _protocolFeePayoutPeriodBlocks param
protocolFeePayoutPeriod)) // _protocolFeePayoutPeriod param
);
BidderRegistry bidderRegistry = BidderRegistry(payable(bidderRegistryProxy));
console.log("BidderRegistry:", address(bidderRegistry));
Expand All @@ -66,7 +66,7 @@ contract DeployCore is Script {
providerPenaltyPercent, // _feePercent param
msg.sender, // _owner param
withdrawalDelay, // _withdrawalDelay param
protocolFeePayoutPeriodBlocks)) // _protocolFeePayoutPeriodBlocks param
protocolFeePayoutPeriod)) // _protocolFeePayoutPeriod param
);
ProviderRegistry providerRegistry = ProviderRegistry(payable(providerRegistryProxy));
console.log("ProviderRegistry:", address(providerRegistry));
Expand Down
Loading
Loading