Skip to content

Commit

Permalink
Merge pull request #76 from primevprotocol/ckartik/adds-read-on-treasury
Browse files Browse the repository at this point in the history
  • Loading branch information
ckartik authored Jan 17, 2024
2 parents 1988489 + 0813f30 commit 26b3ce8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
17 changes: 12 additions & 5 deletions contracts/BidderRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ contract BidderRegistry is IBidderRegistry, Ownable, ReentrancyGuard {
mapping(address => uint256) public providerAmount;

/// @dev Event emitted when a bidder is registered with their prepayed amount
event BidderRegistered(address indexed bidder, uint256 prepayedAmount);
event BidderRegistered(address indexed bidder, uint256 prepaidAmount);

/// @dev Event emitted when funds are retrieved from a bidder's prepay
event FundsRetrieved(address indexed bidder, uint256 amount);
Expand Down Expand Up @@ -112,6 +112,13 @@ contract BidderRegistry is IBidderRegistry, Ownable, ReentrancyGuard {
return providerAmount[provider];
}

/**
* @dev Get the amount assigned to the fee recipient (treasury).
*/
function getFeeRecipientAmount() external onlyOwner view returns (uint256) {
return feeRecipientAmount;
}

/**
* @dev Internal function for bidder registration and staking.
*/
Expand Down Expand Up @@ -203,13 +210,13 @@ contract BidderRegistry is IBidderRegistry, Ownable, ReentrancyGuard {
require(success, "Couldn't transfer to provider");
}

function withdrawPrepayedAmount(address payable bidder) external nonReentrant {
uint256 prepayedAmount = bidderPrepaidBalances[bidder];
function withdrawPrepaidAmount(address payable bidder) external nonReentrant {
uint256 prepaidAmount = bidderPrepaidBalances[bidder];
bidderPrepaidBalances[bidder] = 0;
require(msg.sender == bidder, "Only bidder can unprepay");
require(prepayedAmount > 0, "Provider Prepayd Amount is zero");
require(prepaidAmount > 0, "Provider Prepayd Amount is zero");

(bool success, ) = bidder.call{value: prepayedAmount}("");
(bool success, ) = bidder.call{value: prepaidAmount}("");
require(success, "Couldn't transfer prepay to bidder");
}

Expand Down
8 changes: 5 additions & 3 deletions test/BidderRegistryTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ contract BidderRegistryTest is Test {

assertEq(providerAmount, 900000000000000000);
assertEq(feeRecipientAmount, 100000000000000000);
assertEq(bidderRegistry.getFeeRecipientAmount(), 100000000000000000);
assertEq(bidderRegistry.bidderPrepaidBalances(bidder), 1 ether);
}

Expand Down Expand Up @@ -198,6 +199,7 @@ contract BidderRegistryTest is Test {
uint256 balanceAfter = feeRecipient.balance;
assertEq(balanceAfter - balanceBefore, 100000000000000000);
assertEq(bidderRegistry.feeRecipientAmount(), 0);
assertEq(bidderRegistry.getFeeRecipientAmount(), 0);
}

function testFail_withdrawFeeRecipientAmount() public {
Expand Down Expand Up @@ -232,7 +234,7 @@ contract BidderRegistryTest is Test {
bidderRegistry.prepay{value: 5 ether}();
uint256 balanceBefore = address(bidder).balance;
vm.prank(bidder);
bidderRegistry.withdrawPrepayedAmount(payable(bidder));
bidderRegistry.withdrawPrepaidAmount(payable(bidder));
uint256 balanceAfter = address(bidder).balance;
assertEq(balanceAfter - balanceBefore, 5 ether);
assertEq(bidderRegistry.bidderPrepaidBalances(bidder), 0);
Expand All @@ -242,13 +244,13 @@ contract BidderRegistryTest is Test {
bidderRegistry.setPreconfirmationsContract(address(this));
vm.prank(bidder);
bidderRegistry.prepay{value: 5 ether}();
bidderRegistry.withdrawPrepayedAmount(payable(bidder));
bidderRegistry.withdrawPrepaidAmount(payable(bidder));
}

function testFail_withdrawStakedAmountStakeZero() public {
bidderRegistry.setPreconfirmationsContract(address(this));
vm.prank(bidder);
bidderRegistry.withdrawPrepayedAmount(payable(bidder));
bidderRegistry.withdrawPrepaidAmount(payable(bidder));
}

function test_withdrawProtocolFee() public {
Expand Down

0 comments on commit 26b3ce8

Please sign in to comment.