From 45fe828062de91fcc93742eb99a358c0c8331539 Mon Sep 17 00:00:00 2001 From: Alok Date: Wed, 10 Jul 2024 02:21:32 +0530 Subject: [PATCH] fix: undo transfer --- contracts/contracts/BidderRegistry.sol | 13 +++++-------- contracts/test/BidderRegistryTest.sol | 12 ++++++------ contracts/test/PreConfirmationConfTest.sol | 8 ++++---- 3 files changed, 15 insertions(+), 18 deletions(-) diff --git a/contracts/contracts/BidderRegistry.sol b/contracts/contracts/BidderRegistry.sol index efcbbed87..c006ef190 100644 --- a/contracts/contracts/BidderRegistry.sol +++ b/contracts/contracts/BidderRegistry.sol @@ -313,12 +313,10 @@ contract BidderRegistry is providerAmount[provider] += amtMinusFeeAndDecay; - // Transfer funds back to the bidder wallet - uint256 fundsToReturn = bidState.bidAmt - decayedAmt; - if (fundsToReturn > 0) { - (bool success, ) = payable(bidState.bidder).call{value: (bidState.bidAmt - decayedAmt)}(""); - require(success, "couldn't transfer to bidder"); - } + // Ensures the bidder gets back the bid amount - decayed reward given to provider and protocol + lockedFunds[bidState.bidder][windowToSettle] += + bidState.bidAmt - + decayedAmt; BidPayment[commitmentDigest].state = State.Withdrawn; BidPayment[commitmentDigest].bidAmt = 0; @@ -348,8 +346,7 @@ contract BidderRegistry is "The bid was not preconfirmed" ); uint256 amt = bidState.bidAmt; - (bool success, ) = payable(bidState.bidder).call{value: amt}(""); - require(success, "couldn't transfer to bidder"); + lockedFunds[bidState.bidder][window] += amt; BidPayment[bidID].state = State.Withdrawn; BidPayment[bidID].bidAmt = 0; diff --git a/contracts/test/BidderRegistryTest.sol b/contracts/test/BidderRegistryTest.sol index bce8f2b00..6e7b997ee 100644 --- a/contracts/test/BidderRegistryTest.sol +++ b/contracts/test/BidderRegistryTest.sol @@ -183,7 +183,7 @@ contract BidderRegistryTest is Test { bidderRegistry.OpenBid(bidID, 1 ether, bidder, blockNumber); - uint256 bidderBalance = bidder.balance; + //uint256 bidderBalance = bidder.balance; bidderRegistry.retrieveFunds(nextWindow, bidID, payable(provider), 50); uint256 providerAmount = bidderRegistry.providerAmount(provider); @@ -193,8 +193,8 @@ contract BidderRegistryTest is Test { assertEq(feeRecipientAmount, 50000000000000000); assertEq(bidderRegistry.getFeeRecipientAmount(), 50000000000000000); - assertEq(bidder.balance, bidderBalance + 500000000000000000); - assertEq(bidderRegistry.lockedFunds(bidder, nextWindow), 63 ether); + //assertEq(bidder.balance, bidderBalance + 500000000000000000); + assertEq(bidderRegistry.lockedFunds(bidder, nextWindow), 63.5 ether); } function test_shouldReturnFunds() public { @@ -210,7 +210,7 @@ contract BidderRegistryTest is Test { blockTracker.addBuilderAddress("test", provider); blockTracker.recordL1Block(blockNumber, "test"); - uint256 bidderBalance = bidder.balance; + //uint256 bidderBalance = bidder.balance; bidderRegistry.OpenBid(bidID, 1 ether, bidder, blockNumber); @@ -221,8 +221,8 @@ contract BidderRegistryTest is Test { assertEq(providerAmount, 0); assertEq(feeRecipientAmount, 0); - assertEq(bidder.balance, bidderBalance + 1 ether); - assertEq(bidderRegistry.lockedFunds(bidder, nextWindow), 63 ether); + //assertEq(bidder.balance, bidderBalance + 1 ether); + assertEq(bidderRegistry.lockedFunds(bidder, nextWindow), 64 ether); } function test_shouldRetrieveFundsWithoutFeeRecipient() public { diff --git a/contracts/test/PreConfirmationConfTest.sol b/contracts/test/PreConfirmationConfTest.sol index 7ebd9654a..55811c72b 100644 --- a/contracts/test/PreConfirmationConfTest.sol +++ b/contracts/test/PreConfirmationConfTest.sol @@ -647,9 +647,9 @@ contract TestPreConfCommitmentStore is Test { // Verify that the commitment has been deleted assert(isUsed == true); - assertEq(bidderRegistry.lockedFunds(bidder, depositWindow), 2 ether - _testCommitmentAliceBob.bid); + assertEq(bidderRegistry.lockedFunds(bidder, depositWindow), 2 ether); assertEq(bidderRegistry.providerAmount(commiter), 0 ether); - assertEq(bidder.balance, 3 ether + _testCommitmentAliceBob.bid); + //assertEq(bidder.balance, 3 ether + _testCommitmentAliceBob.bid); } // commitmentHash value is internal to contract and not asserted } @@ -821,9 +821,9 @@ contract TestPreConfCommitmentStore is Test { assert(isUsed == true); // commitmentHash value is internal to contract and not asserted - assertEq(bidderRegistry.lockedFunds(bidder, window), 2 ether - _testCommitmentAliceBob.bid); + assertEq(bidderRegistry.lockedFunds(bidder, window), 2 ether); assertEq(bidderRegistry.providerAmount(commiter), 0 ether); - assertEq(bidder.balance, 3 ether + _testCommitmentAliceBob.bid); + //assertEq(bidder.balance, 3 ether + _testCommitmentAliceBob.bid); } }