From 094c5fabdebad6c6ce4a7c27fc2e216cdc817245 Mon Sep 17 00:00:00 2001 From: Schlagonia Date: Thu, 8 Feb 2024 18:00:23 -0700 Subject: [PATCH] chore: auction tweaks --- src/Auctions/Auction.sol | 59 ++++++++++++++++++++++----------- src/Auctions/AuctionFactory.sol | 27 ++++++++------- 2 files changed, 54 insertions(+), 32 deletions(-) diff --git a/src/Auctions/Auction.sol b/src/Auctions/Auction.sol index fda74e9..81c03f2 100644 --- a/src/Auctions/Auction.sol +++ b/src/Auctions/Auction.sol @@ -58,7 +58,8 @@ contract Auction is Governance { uint256 internal constant WAD = 1e18; /// @notice Used for the price decay. - uint256 constant MINUTE_HALF_LIFE = 0.988514020352896135_356867505 * 1e27; // 0.5^(1/60) + uint256 internal constant MINUTE_HALF_LIFE = + 0.988514020352896135_356867505 * 1e27; // 0.5^(1/60) TokenInfo internal wantInfo; @@ -106,7 +107,7 @@ contract Auction is Governance { require(_startingPrice != 0, "starting price"); // Set variables - wantInfo = TokenInfo ({ + wantInfo = TokenInfo({ tokenAddress: _want, scaler: uint96(WAD / 10 ** ERC20(_want).decimals()) }); @@ -124,16 +125,17 @@ contract Auction is Governance { function want() external view returns (address) { return wantInfo.tokenAddress; } - + /** * @notice Get the unique auction identifier. * @param _from The address of the token to sell. * @return bytes32 A unique auction identifier. */ - function getAuctionId( - address _from - ) public view virtual returns (bytes32) { - return keccak256(abi.encodePacked(_from, wantInfo.tokenAddress, address(this))); + function getAuctionId(address _from) public view virtual returns (bytes32) { + return + keccak256( + abi.encodePacked(_from, wantInfo.tokenAddress, address(this)) + ); } /** @@ -187,11 +189,16 @@ contract Auction is Governance { address _hook = hook; if (_hook != address(0)) { // If so default to the hooks logic. - return IHook(_hook).kickable(auctions[_auctionId].fromInfo.tokenAddress); + return + IHook(_hook).kickable( + auctions[_auctionId].fromInfo.tokenAddress + ); } else { // Else just use the full balance of this contract. return - ERC20(auctions[_auctionId].fromInfo.tokenAddress).balanceOf(address(this)); + ERC20(auctions[_auctionId].fromInfo.tokenAddress).balanceOf( + address(this) + ); } } @@ -307,9 +314,7 @@ contract Auction is Governance { * @param _from The address of the token to be auctioned. * @return . The unique identifier of the enabled auction. */ - function enable( - address _from - ) external virtual returns (bytes32) { + function enable(address _from) external virtual returns (bytes32) { return enable(_from, 0, governance); } @@ -350,7 +355,7 @@ contract Auction is Governance { ); auctions[_auctionId] = AuctionInfo({ - fromInfo: TokenInfo ({ + fromInfo: TokenInfo({ tokenAddress: _from, scaler: uint96(WAD / 10 ** ERC20(_from).decimals()) }), @@ -361,7 +366,12 @@ contract Auction is Governance { receiver: _receiver }); - emit AuctionEnabled(_auctionId, _from, wantInfo.tokenAddress, address(this)); + emit AuctionEnabled( + _auctionId, + _from, + wantInfo.tokenAddress, + address(this) + ); } /** @@ -369,18 +379,24 @@ contract Auction is Governance { * @dev Only callable by governance. * @param _from The address of the token being sold. */ - function disable( - address _from - ) external virtual onlyGovernance { + function disable(address _from) external virtual onlyGovernance { bytes32 _auctionId = getAuctionId(_from); // Make sure the auction was enables. - require(auctions[_auctionId].fromInfo.tokenAddress != address(0), "not enabled"); + require( + auctions[_auctionId].fromInfo.tokenAddress != address(0), + "not enabled" + ); // Remove the struct. delete auctions[_auctionId]; - emit AuctionDisabled(_auctionId, _from, wantInfo.tokenAddress, address(this)); + emit AuctionDisabled( + _auctionId, + _from, + wantInfo.tokenAddress, + address(this) + ); } /*////////////////////////////////////////////////////////////// @@ -501,7 +517,10 @@ contract Auction is Governance { ); // Transfer from token out. - ERC20(auction.fromInfo.tokenAddress).safeTransfer(_receiver, _amountTaken); + ERC20(auction.fromInfo.tokenAddress).safeTransfer( + _receiver, + _amountTaken + ); emit AuctionTaken(_auctionId, _amountTaken, left); diff --git a/src/Auctions/AuctionFactory.sol b/src/Auctions/AuctionFactory.sol index 5e4aae9..2ad536c 100644 --- a/src/Auctions/AuctionFactory.sol +++ b/src/Auctions/AuctionFactory.sol @@ -9,10 +9,10 @@ import {Auction} from "./Auction.sol"; contract AuctionFactory is Clonable { event DeployedNewAuction(address indexed auction); - /// @notice The minimum time to wait between auction 'kicks'. - uint256 public constant defaultAuctionLength = 3 days; - /// @notice The time that each auction lasts. + uint256 public constant defaultAuctionLength = 1 days; + + /// @notice The minimum time to wait between auction 'kicks'. uint256 public constant defaultAuctionCooldown = 7 days; /// @notice The amount to start the auction with. @@ -35,7 +35,10 @@ contract AuctionFactory is Clonable { ); } - function createNewAuction(address _want, address _hook) external returns (address) { + function createNewAuction( + address _want, + address _hook + ) external returns (address) { return _createNewAuction( _want, @@ -67,16 +70,16 @@ contract AuctionFactory is Clonable { address _want, address _hook, address _governance, - uint256 _startingPrice + uint256 _auctionLength ) external returns (address) { return _createNewAuction( _want, _hook, _governance, - defaultAuctionLength, + _auctionLength, defaultAuctionCooldown, - _startingPrice + defaultStartingPrice ); } @@ -84,7 +87,7 @@ contract AuctionFactory is Clonable { address _want, address _hook, address _governance, - uint256 _startingPrice, + uint256 _auctionLength, uint256 _auctionCooldown ) external returns (address) { return @@ -92,9 +95,9 @@ contract AuctionFactory is Clonable { _want, _hook, _governance, - defaultAuctionLength, + _auctionLength, _auctionCooldown, - _startingPrice + defaultStartingPrice ); } @@ -102,9 +105,9 @@ contract AuctionFactory is Clonable { address _want, address _hook, address _governance, - uint256 _startingPrice, + uint256 _auctionLength, uint256 _auctionCooldown, - uint256 _auctionLength + uint256 _startingPrice ) external returns (address) { return _createNewAuction(