function commitEth(address payable _beneficiary) public payable nonReentrant { // Get ETH able to be committed uint256 ethToTransfer = calculateCommitment(msg.value);
/// @notice Accept ETH Payments. uint256 ethToRefund = msg.value - ethToTransfer; if (ethToTransfer > 0) { _addCommitment(_beneficiary, ethToTransfer); } /// @notice Return any ETH to be refunded. if (ethToRefund > 0) { _beneficiary.transfer(ethToRefund); } }
这个合约就是获得用户承诺的金额,计算最大的承诺上限,然后再与用户承诺金额比较,计算退回的eth.
还有就只再最后结算的时候,如果拍卖部成功,也会退回金额
function withdrawTokens(address beneficiary) public nonReentrant { if (auctionSuccessful()) { require(marketStatus.finalized, "DutchAuction: not finalized"); /// @dev Successful auction! Transfer claimed tokens. uint256 tokensToClaim = tokensClaimable(beneficiary); require(tokensToClaim > 0, "DutchAuction: No tokens to claim"); claimed[beneficiary] = claimed[beneficiary]+tokensToClaim; IERC20(auctionToken).safeTransfer(beneficiary,tokensToClaim); } else { /// @dev Auction did not meet reserve price. /// @dev Return committed funds back to user. require(block.timestamp > marketInfo.endTime, "DutchAuction: auction has not finished yet"); uint256 fundsCommitted = commitments[beneficiary]; commitments[beneficiary] = 0; // Stop multiple withdrawals and free some gas