diff --git a/contracts/BidderRegistry.sol b/contracts/BidderRegistry.sol index d0a9f57..71bcb82 100644 --- a/contracts/BidderRegistry.sol +++ b/contracts/BidderRegistry.sol @@ -148,7 +148,8 @@ contract BidderRegistry is IBidderRegistry, Ownable, ReentrancyGuard { if (bidState.state == State.UnPreConfirmed) { BidPayment[commitmentDigest] = BidState({ bidAmt: bid, - state: State.PreConfirmed + state: State.PreConfirmed, + bidder: bidder }); bidderPrepaidBalances[bidder] -= bid; } @@ -186,6 +187,24 @@ contract BidderRegistry is IBidderRegistry, Ownable, ReentrancyGuard { emit FundsRetrieved(commitmentDigest, amt); } + /** + * @dev Return funds to a bidder's prepay (only callable by the pre-confirmations contract). + * @dev reenterancy not necessary but still putting here for precaution + * @param bidID is the Bid ID that allows us to identify the bid, and prepayment + */ + function returnFunds(bytes32 bidID) external nonReentrant onlyPreConfirmationEngine() { + BidState memory bidState = BidPayment[bidID]; + require(bidState.state == State.PreConfirmed, "The bid was not preconfirmed"); + uint256 amt = bidState.bidAmt; + bidderPrepaidBalances[bidState.bidder] += amt; + + + BidPayment[bidID].state = State.Withdrawn; + BidPayment[bidID].bidAmt = 0; + + emit FundsRetrieved(bidID, amt); + } + /** * @notice Sets the new fee recipient * @dev onlyOwner restriction diff --git a/contracts/Oracle.sol b/contracts/Oracle.sol index 833f78b..b7c6af4 100644 --- a/contracts/Oracle.sol +++ b/contracts/Oracle.sol @@ -5,6 +5,8 @@ import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol"; import {PreConfCommitmentStore} from "./PreConfirmations.sol"; import {IProviderRegistry} from "./interfaces/IProviderRegistry.sol"; import {IPreConfCommitmentStore} from './interfaces/IPreConfirmations.sol'; +import {IBidderRegistry} from './interfaces/IBidderRegistry.sol'; + /// @title Oracle Contract /// @author Kartik Chopra @@ -44,6 +46,8 @@ contract Oracle is Ownable { /// @dev Reference to the PreConfCommitmentStore contract interface. IPreConfCommitmentStore private preConfContract; + IBidderRegistry private bidderRegistry; + /** * @dev Constructor to initialize the contract with a PreConfirmations contract. * @param _preConfContract The address of the pre-confirmations contract. @@ -52,10 +56,12 @@ contract Oracle is Ownable { */ constructor( address _preConfContract, + address _bidderRegistry, uint256 _nextRequestedBlockNumber, address _owner ) Ownable() { preConfContract = IPreConfCommitmentStore(_preConfContract); + bidderRegistry = IBidderRegistry(_bidderRegistry); nextRequestedBlockNumber = _nextRequestedBlockNumber; _transferOwnership(_owner); } @@ -122,7 +128,7 @@ contract Oracle is Ownable { /** */ function returnFunds(bytes32 bidID) external onlyOwner { - // Bidder registery.returnFunds(bidID); + bidderRegistry.returnFunds(bidID); } /** diff --git a/contracts/PreConfirmations.sol b/contracts/PreConfirmations.sol index 75ed9ca..66342e0 100644 --- a/contracts/PreConfirmations.sol +++ b/contracts/PreConfirmations.sol @@ -408,11 +408,7 @@ contract PreConfCommitmentStore is Ownable { payable(commitment.bidder) ); - // Return funds to bidder - bidderRegistry.retrieveFunds( - commitment.commitmentHash, - payable(commitment.bidder) - ); + bidderRegistry.returnFunds(commitment.commitmentHash); } /** diff --git a/contracts/interfaces/IBidderRegistry.sol b/contracts/interfaces/IBidderRegistry.sol index 949f461..5ba7392 100644 --- a/contracts/interfaces/IBidderRegistry.sol +++ b/contracts/interfaces/IBidderRegistry.sol @@ -14,6 +14,7 @@ interface IBidderRegistry { struct BidState { + address bidder; uint64 bidAmt; State state; } @@ -34,4 +35,6 @@ interface IBidderRegistry { bytes32 commitmentDigest, address payable provider ) external; + + function returnFunds(bytes32 bidID) external; } diff --git a/scripts/DeployScripts.s.sol b/scripts/DeployScripts.s.sol index 1a69daa..20430c1 100644 --- a/scripts/DeployScripts.s.sol +++ b/scripts/DeployScripts.s.sol @@ -63,7 +63,7 @@ contract DeployScript is Script, Create2Deployer { bidderRegistry.setPreconfirmationsContract(address(preConfCommitmentStore)); console.log("BidderRegistry updated with PreConfCommitmentStore address:", address(preConfCommitmentStore)); - Oracle oracle = new Oracle{salt: salt}(address(preConfCommitmentStore), nextRequestedBlockNumber, msg.sender); + Oracle oracle = new Oracle{salt: salt}(address(preConfCommitmentStore), address(bidderRegistry), nextRequestedBlockNumber, msg.sender); console.log("Oracle deployed to:", address(oracle)); preConfCommitmentStore.updateOracle(address(oracle)); diff --git a/test/OracleTest.sol b/test/OracleTest.sol index c3eebfb..01093db 100644 --- a/test/OracleTest.sol +++ b/test/OracleTest.sol @@ -54,7 +54,7 @@ contract OracleTest is Test { vm.startPrank(ownerInstance); bidderRegistry.prepay{value: 2 ether}(); - oracle = new Oracle(address(preConfCommitmentStore), 2, ownerInstance); + oracle = new Oracle(address(preConfCommitmentStore), address(bidderRegistry), 2, ownerInstance); oracle.addBuilderAddress("mev builder", ownerInstance); vm.stopPrank();