Skip to content

Commit

Permalink
chore: auction tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
Schlagonia committed Feb 9, 2024
1 parent 826aa33 commit 094c5fa
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 32 deletions.
59 changes: 39 additions & 20 deletions src/Auctions/Auction.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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())
});
Expand All @@ -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))
);
}

/**
Expand Down Expand Up @@ -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)
);
}
}

Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -350,7 +355,7 @@ contract Auction is Governance {
);

auctions[_auctionId] = AuctionInfo({
fromInfo: TokenInfo ({
fromInfo: TokenInfo({
tokenAddress: _from,
scaler: uint96(WAD / 10 ** ERC20(_from).decimals())
}),
Expand All @@ -361,26 +366,37 @@ contract Auction is Governance {
receiver: _receiver
});

emit AuctionEnabled(_auctionId, _from, wantInfo.tokenAddress, address(this));
emit AuctionEnabled(
_auctionId,
_from,
wantInfo.tokenAddress,
address(this)
);
}

/**
* @notice Disables an existing auction.
* @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)
);
}

/*//////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -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);

Expand Down
27 changes: 15 additions & 12 deletions src/Auctions/AuctionFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Check warning on line 13 in src/Auctions/AuctionFactory.sol

View workflow job for this annotation

GitHub Actions / solidity

Constant name must be in capitalized SNAKE_CASE

/// @notice The minimum time to wait between auction 'kicks'.
uint256 public constant defaultAuctionCooldown = 7 days;

Check warning on line 16 in src/Auctions/AuctionFactory.sol

View workflow job for this annotation

GitHub Actions / solidity

Constant name must be in capitalized SNAKE_CASE

/// @notice The amount to start the auction with.
Expand All @@ -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,
Expand Down Expand Up @@ -67,44 +70,44 @@ 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
);
}

function createNewAuction(
address _want,
address _hook,
address _governance,
uint256 _startingPrice,
uint256 _auctionLength,
uint256 _auctionCooldown
) external returns (address) {
return
_createNewAuction(
_want,
_hook,
_governance,
defaultAuctionLength,
_auctionLength,
_auctionCooldown,
_startingPrice
defaultStartingPrice
);
}

function createNewAuction(
address _want,
address _hook,
address _governance,
uint256 _startingPrice,
uint256 _auctionLength,
uint256 _auctionCooldown,
uint256 _auctionLength
uint256 _startingPrice
) external returns (address) {
return
_createNewAuction(
Expand Down

0 comments on commit 094c5fa

Please sign in to comment.