Gas-Price Priority Auction

gas-price-priority-auction · auction-allocation · 486 B runtime · funds-movement

scores

source

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;

contract GasPricePriorityAuction {
    mapping(uint256 => uint256) public highestBid;
    mapping(uint256 => address) public leader;

    event BidPlaced(uint256 indexed blockNumber, address indexed bidder, uint256 gasPrice);

    function bid() external {
        uint256 blockNum = block.number;
        uint256 gasPrice = tx.gasprice;
        require(gasPrice > highestBid[blockNum], 'GasPricePriorityAuction: bid too low');
        highestBid[blockNum] = gasPrice;
        leader[blockNum] = msg.sender;
        emit BidPlaced(blockNum, msg.sender, gasPrice);
    }
}