From ef8e4d453646f91d22c47218c7a36f4306ae2736 Mon Sep 17 00:00:00 2001 From: Mikelle Date: Thu, 18 Apr 2024 18:30:06 +0200 Subject: [PATCH] added comments --- contracts/BidderRegistry.sol | 28 ++++++++++++++++++++++++++++ contracts/BlockTracker.sol | 22 ++++++++++++++++++---- contracts/PreConfirmations.sol | 3 +++ contracts/ProviderRegistry.sol | 4 ++++ 4 files changed, 53 insertions(+), 4 deletions(-) diff --git a/contracts/BidderRegistry.sol b/contracts/BidderRegistry.sol index 0003051..a7712dc 100644 --- a/contracts/BidderRegistry.sol +++ b/contracts/BidderRegistry.sol @@ -163,6 +163,19 @@ contract BidderRegistry is IBidderRegistry, Ownable, ReentrancyGuard { ); } + /** + * @dev Prepay for a specific window. + * @param window The window for which the prepay is being made. + */ + function prepayAllowanceForSpecificWindow(uint256 window) external payable { + require(msg.value >= minAllowance, "Insufficient prepay"); + + bidderRegistered[msg.sender] = true; + lockedFunds[msg.sender][window] += msg.value; + + emit BidderRegistered(msg.sender, lockedFunds[msg.sender][window], window); + } + /** * @dev Check the prepay of a bidder. * @param bidder The address of the bidder. @@ -284,6 +297,9 @@ contract BidderRegistry is IBidderRegistry, Ownable, ReentrancyGuard { feePercent = newFeePercent; } + /** + * @dev Withdraw funds to the fee recipient. + */ function withdrawFeeRecipientAmount() external nonReentrant { uint256 amount = feeRecipientAmount; feeRecipientAmount = 0; @@ -292,6 +308,10 @@ contract BidderRegistry is IBidderRegistry, Ownable, ReentrancyGuard { require(successFee, "couldn't transfer to fee Recipient"); } + /** + * @dev Withdraw funds to the provider. + * @param provider The address of the provider. + */ function withdrawProviderAmount( address payable provider ) external nonReentrant { @@ -303,6 +323,10 @@ contract BidderRegistry is IBidderRegistry, Ownable, ReentrancyGuard { require(success, "couldn't transfer to provider"); } + /** + * @dev Withdraw funds to the bidder. + * @param bidder The address of the bidder. + */ function withdrawBidderAmountFromWindow( address payable bidder, uint256 window @@ -327,6 +351,10 @@ contract BidderRegistry is IBidderRegistry, Ownable, ReentrancyGuard { emit BidderWithdrawal(bidder, window, amount); } + /** + * @dev Withdraw protocol fee. + * @param bidder The address of the bidder. + */ function withdrawProtocolFee( address payable bidder ) external onlyOwner nonReentrant { diff --git a/contracts/BlockTracker.sol b/contracts/BlockTracker.sol index 76228c7..eef35b6 100644 --- a/contracts/BlockTracker.sol +++ b/contracts/BlockTracker.sol @@ -8,11 +8,18 @@ import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol"; */ contract BlockTracker is Ownable { /// @dev Event emitted when a new L1 block is tracked. - event NewL1Block(uint256 indexed blockNumber, address indexed winner, uint256 indexed window); + event NewL1Block( + uint256 indexed blockNumber, + address indexed winner, + uint256 indexed window + ); /// @dev Event emitted when a new window is created. event NewWindow(uint256 indexed window); + /// @dev Event emitted when the number of blocks per window is updated. + event NewBlocksPerWindow(uint256 blocksPerWindow); + uint256 public currentWindow = 1; uint256 public blocksPerWindow = 64; uint256 public lastL1BlockNumber; @@ -59,6 +66,8 @@ contract BlockTracker is Ownable { */ function setBlocksPerWindow(uint256 _blocksPerWindow) external onlyOwner { blocksPerWindow = _blocksPerWindow; + + emit NewBlocksPerWindow(blocksPerWindow); } /** * @dev Returns the current window number. @@ -73,7 +82,10 @@ contract BlockTracker is Ownable { * @param _blockNumber The number of the new L1 block. * @param _winner The address of the winner of the new L1 block. */ - function recordL1Block(uint256 _blockNumber, address _winner) external onlyOwner { + function recordL1Block( + uint256 _blockNumber, + address _winner + ) external onlyOwner { lastL1BlockNumber = _blockNumber; lastL1BlockWinner = _winner; recordBlockWinner(_blockNumber, _winner); @@ -98,7 +110,9 @@ contract BlockTracker is Ownable { } // Function to get the winner of a specific block - function getBlockWinner(uint256 blockNumber) external view returns (address) { + function getBlockWinner( + uint256 blockNumber + ) external view returns (address) { return blockWinners[blockNumber]; } @@ -116,4 +130,4 @@ contract BlockTracker is Ownable { receive() external payable { revert("Invalid call"); } -} \ No newline at end of file +} diff --git a/contracts/PreConfirmations.sol b/contracts/PreConfirmations.sol index 619ed8c..48a7e41 100644 --- a/contracts/PreConfirmations.sol +++ b/contracts/PreConfirmations.sol @@ -87,6 +87,7 @@ contract PreConfCommitmentStore is Ownable { bytes sharedSecretKey; } + /// @dev Event to log successful commitment storage event CommitmentStored( bytes32 indexed commitmentIndex, address bidder, @@ -104,6 +105,7 @@ contract PreConfCommitmentStore is Ownable { bytes sharedSecretKey ); + /// @dev Struct for all the information around encrypted preconfirmations commitment struct EncrPreConfCommitment { bool commitmentUsed; address commiter; @@ -112,6 +114,7 @@ contract PreConfCommitmentStore is Ownable { uint256 blockCommitedAt; } + /// @dev Event to log successful encrypted commitment storage event EncryptedCommitmentStored( bytes32 indexed commitmentIndex, address commiter, diff --git a/contracts/ProviderRegistry.sol b/contracts/ProviderRegistry.sol index 0aea024..baafe2a 100644 --- a/contracts/ProviderRegistry.sol +++ b/contracts/ProviderRegistry.sol @@ -210,6 +210,10 @@ contract ProviderRegistry is IProviderRegistry, Ownable, ReentrancyGuard { require(success, "Couldn't transfer to bidder"); } + /** + * @dev Withdraw staked amount for the provider. + * @param provider The address of the provider. + */ function withdrawStakedAmount( address payable provider ) external nonReentrant {