Skip to content

Commit

Permalink
set default validator ofa share to 50%
Browse files Browse the repository at this point in the history
  • Loading branch information
jj1980a committed Jan 5, 2024
1 parent 26d0b69 commit 3b01c51
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
19 changes: 13 additions & 6 deletions contracts/auction-handler/FastLaneAuctionHandler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ contract FastLaneAuctionHandler is FastLaneAuctionHandlerEvents {
/// @notice The scale for validator refund share
uint256 internal constant VALIDATOR_REFUND_SCALE = 10_000; // 1 = 0.01%

/// @notice The default refund share for validators
int256 internal constant DEFAULT_VALIDATOR_REFUND_SHARE = 5000; // 50%

/// @notice Mapping to Validator Data Struct
mapping(address => ValidatorData) internal validatorsDataMap;

Expand All @@ -111,11 +114,11 @@ contract FastLaneAuctionHandler is FastLaneAuctionHandlerEvents {
/// @notice Map key is block.number
mapping(uint256 => PGAData) public fulfilledPGAMap;

/// @notice Map[validator] = % payment to validator in a bid with refund
mapping(address => uint256) public validatorsRefundShareMap;

uint256 public validatorsTotal;

/// @notice Map[validator] = % payment to validator in a bid with refund
mapping(address => int256) private validatorsRefundShareMap;

bytes32 private constant UNLOCKED = bytes32(uint256(1));
bytes32 private constant LOCKED = bytes32(uint256(2));

Expand Down Expand Up @@ -182,7 +185,7 @@ contract FastLaneAuctionHandler is FastLaneAuctionHandlerEvents {
) external payable checkBid(oppTxHash, bidAmount) onlyEOA nonReentrant {

if (searcherToAddress == address(0)) revert RelaySearcherWrongParams();
if (validatorsRefundShareMap[block.coinbase] > VALIDATOR_REFUND_SCALE) revert RelayValidatorNotAcceptingRefundBids();
if (getValidatorRefundShare(block.coinbase) > VALIDATOR_REFUND_SCALE) revert RelayValidatorNotAcceptingRefundBids();

// Call the searcher's contract (see searcher_contract.sol for example of call receiver)
// And forward msg.value
Expand Down Expand Up @@ -405,7 +408,7 @@ contract FastLaneAuctionHandler is FastLaneAuctionHandlerEvents {
}

// Calculate the split of payment
uint256 validatorShare = (validatorsRefundShareMap[block.coinbase] * bidAmount) / VALIDATOR_REFUND_SCALE;
uint256 validatorShare = (getValidatorRefundShare(block.coinbase) * bidAmount) / VALIDATOR_REFUND_SCALE;
uint256 refundAmount = bidAmount - validatorShare; // subtract to ensure no overflow

// Update balance and make payment
Expand Down Expand Up @@ -582,7 +585,11 @@ contract FastLaneAuctionHandler is FastLaneAuctionHandlerEvents {
// ensure that validators can't insert txs to boost their refund rates during their own blocks
if (validator == block.coinbase) revert RelayImmutableBlockAuthorRate();

validatorsRefundShareMap[validator] = refundShare;
validatorsRefundShareMap[validator] = int256(refundShare) - DEFAULT_VALIDATOR_REFUND_SHARE;
}

function getValidatorRefundShare(address validator) public view returns (uint256) {
return uint256(validatorsRefundShareMap[validator] + DEFAULT_VALIDATOR_REFUND_SHARE);
}

/***********************************|
Expand Down
12 changes: 12 additions & 0 deletions test/PFL_AuctionHandler.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,18 @@ contract PFLAuctionHandlerTest is PFLHelper, FastLaneAuctionHandlerEvents {
}
}

function testUpdateValidatorRefundShare() public {
uint256 newShare = 7500;

PFR.payValidatorFee{value: 1}(SEARCHER_ADDRESS1);

vm.coinbase(address(0));
vm.prank(VALIDATOR1);
PFR.updateValidatorRefundShare(newShare);

assertEq(newShare, PFR.getValidatorRefundShare(VALIDATOR1));
}

function testSubmitFlashBidWithRefund() public {

vm.deal(SEARCHER_ADDRESS1, 150 ether);
Expand Down

0 comments on commit 3b01c51

Please sign in to comment.