Skip to content

Commit

Permalink
Merge 082d726 into a5d8d50
Browse files Browse the repository at this point in the history
  • Loading branch information
sarangparikh22 committed May 6, 2022
2 parents a5d8d50 + 082d726 commit fddc0b8
Show file tree
Hide file tree
Showing 6 changed files with 159 additions and 50 deletions.
7 changes: 7 additions & 0 deletions .solcover.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
skipFiles: ["flat", "libraries", "mocks", "interfaces", "utils"],
mocha: {
fgrep: "[skip-on-coverage]",
invert: true,
},
};
80 changes: 63 additions & 17 deletions contracts/SushiMakerAuction.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@ contract SushiMakerAuction is
BoringOwnable,
ReentrancyGuard
{
using SafeERC20 for IERC20;
uint128 public stakedBidToken;

mapping(IERC20 => Bid) public bids;
mapping(IERC20 => bool) public whitelistedTokens;
mapping(address => mapping(IERC20 => uint256)) balances;

address public receiver;
IERC20 public immutable bidToken;
Expand All @@ -43,10 +46,12 @@ contract SushiMakerAuction is

modifier onlyToken(IERC20 token) {
// Any cleaner way to find if it's a LP?
(bool success, ) = address(token).call(
abi.encodeWithSignature("token0()")
);
if (success) revert LPTokenNotAllowed();
if (!whitelistedTokens[token]) {
(bool success, bytes memory result) = address(token).call(
abi.encodeWithSignature("token0()")
);
if (success && result.length == 32) revert LPTokenNotAllowed();
}
_;
}

Expand All @@ -62,6 +67,43 @@ contract SushiMakerAuction is
pairCodeHash = _pairCodeHash;
}

function deposit(IERC20 token, uint256 amount) external {
token.safeTransferFrom(msg.sender, address(this), amount);
balances[msg.sender][token] += amount;
if (token == bidToken) {
stakedBidToken += uint128(amount);
}
}

function withdraw(IERC20 token, uint256 amount) external {
balances[msg.sender][token] -= amount;
if (token == bidToken) {
stakedBidToken -= uint128(amount);
}
token.safeTransfer(msg.sender, amount);
}

function _updateTokenBalance(
IERC20 token,
address to,
uint256 amount,
bool inc
) internal {
if (inc) {
balances[to][token] += amount;
} else {
balances[to][token] -= amount;
}
}

function getBalance(address user, IERC20 token)
external
view
returns (uint256 balance)
{
return balances[user][token];
}

function start(
IERC20 token,
uint128 bidAmount,
Expand All @@ -75,16 +117,14 @@ contract SushiMakerAuction is

if (bid.bidder != address(0)) revert BidAlreadyStarted();

bidToken.transferFrom(msg.sender, address(this), bidAmount);
_updateTokenBalance(bidToken, msg.sender, bidAmount, false);

bid.bidder = to;
bid.bidAmount = bidAmount;
bid.rewardAmount = uint128(token.balanceOf(address(this)));
bid.minTTL = uint64(block.timestamp) + minTTL;
bid.maxTTL = uint64(block.timestamp) + maxTTL;

stakedBidToken += bidAmount;

emit Started(token, msg.sender, bidAmount, bid.rewardAmount);
}

Expand All @@ -104,10 +144,8 @@ contract SushiMakerAuction is
MIN_BID_THRESHOLD_PRECISION)) > bidAmount
) revert InsufficientBidAmount();

stakedBidToken += bidAmount - bid.bidAmount;

bidToken.transferFrom(msg.sender, address(this), bidAmount);
bidToken.transfer(bid.bidder, bid.bidAmount);
_updateTokenBalance(bidToken, msg.sender, bidAmount, false);
_updateTokenBalance(bidToken, bid.bidder, bid.bidAmount, true);

bid.bidder = to;
bid.bidAmount = bidAmount;
Expand All @@ -124,11 +162,8 @@ contract SushiMakerAuction is
if (bid.minTTL > block.timestamp && bid.maxTTL > block.timestamp)
revert BidNotFinished();

token.transfer(bid.bidder, bid.rewardAmount);

bidToken.transfer(receiver, bid.bidAmount);

stakedBidToken -= bid.bidAmount;
_updateTokenBalance(token, bid.bidder, bid.rewardAmount, true);
_updateTokenBalance(bidToken, receiver, bid.bidAmount, true);

emit Ended(token, bid.bidder, bid.bidAmount);

Expand All @@ -144,7 +179,10 @@ contract SushiMakerAuction is
}

function skimBidToken() external override {
bidToken.transfer(
uint128 recieverBalance = uint128(balances[receiver][bidToken]);
balances[receiver][bidToken] = 0;
stakedBidToken -= recieverBalance;
bidToken.safeTransfer(
receiver,
bidToken.balanceOf(address(this)) - stakedBidToken
);
Expand All @@ -153,4 +191,12 @@ contract SushiMakerAuction is
function updateReceiver(address newReceiver) external override onlyOwner {
receiver = newReceiver;
}

function updateWhitelistToken(IERC20 token, bool status)
external
override
onlyOwner
{
whitelistedTokens[token] = status;
}
}
3 changes: 3 additions & 0 deletions contracts/interfaces/ISushiMakerAuction.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
pragma solidity 0.8.11;

import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "../libraries/UniswapV2Library.sol";
import "../utils/BoringOwnable.sol";
import "../utils/BoringBatchable.sol";
Expand All @@ -27,6 +28,8 @@ interface ISushiMakerAuction {

function updateReceiver(address newReceiver) external;

function updateWhitelistToken(IERC20 token, bool status) external;

struct Bid {
address bidder;
uint128 bidAmount;
Expand Down
26 changes: 13 additions & 13 deletions contracts/utils/BoringBatchable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pragma experimental ABIEncoderV2;
// Combining BoringBatchable with msg.value can cause double spending issues
// https://www.paradigm.xyz/2021/08/two-rights-might-make-a-wrong/

import "../interfaces/IERC20.sol";
// import "../interfaces/IERC20.sol";

contract BaseBoringBatchable {
/// @dev Helper function to extract a useful revert message from a failed call.
Expand Down Expand Up @@ -54,16 +54,16 @@ contract BoringBatchable is BaseBoringBatchable {
/// Lookup `IERC20.permit`.
// F6: Parameters can be used front-run the permit and the user's permit will fail (due to nonce or other revert)
// if part of a batch this could be used to grief once as the second call would not need the permit
function permitToken(
IERC20 token,
address from,
address to,
uint256 amount,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) public {
token.permit(from, to, amount, deadline, v, r, s);
}
// function permitToken(
// IERC20 token,
// address from,
// address to,
// uint256 amount,
// uint256 deadline,
// uint8 v,
// bytes32 r,
// bytes32 s
// ) public {
// token.permit(from, to, amount, deadline, v, r, s);
// }
}
7 changes: 0 additions & 7 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,6 @@ task("accounts", "Prints the list of accounts", async (args, { ethers }) => {
});

const config: HardhatUserConfig = {
contractSizer: {
alphaSort: true,
disambiguatePaths: false,
runOnCompile: true,
strict: true,
only: [":SushiMakerAuction$"],
},
defaultNetwork: "hardhat",
etherscan: {
apiKey: process.env.ETHERSCAN_API_KEY,
Expand Down
Loading

0 comments on commit fddc0b8

Please sign in to comment.