Skip to content

Commit

Permalink
fix: undo transfer
Browse files Browse the repository at this point in the history
  • Loading branch information
Alok committed Jul 9, 2024
1 parent 4a3ca37 commit 45fe828
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 18 deletions.
13 changes: 5 additions & 8 deletions contracts/contracts/BidderRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
12 changes: 6 additions & 6 deletions contracts/test/BidderRegistryTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 {
Expand All @@ -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);

Expand All @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions contracts/test/PreConfirmationConfTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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);
}
}

Expand Down

0 comments on commit 45fe828

Please sign in to comment.