Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: dutch auction and factory #36

Merged
merged 24 commits into from
Feb 23, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 41 additions & 12 deletions src/Auctions/Auction.sol
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
/// @notice Array of all the enabled auction for this contract.
bytes32[] public enabledAuctions;

constructor() Governance(msg.sender) {}

Check warning on line 115 in src/Auctions/Auction.sol

View workflow job for this annotation

GitHub Actions / solidity

Code contains empty blocks

/**
* @notice Initializes the Auction contract with initial parameters.
Expand All @@ -137,10 +137,14 @@
require(_auctionLength < _auctionCooldown, "cooldown");
require(_startingPrice != 0, "starting price");

// Cannot have more than 18 decimals.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

uint256 decimals = ERC20(_want).decimals();
require(decimals <= WAD, "unsupported decimals");
Copy link

@0xkorin 0xkorin Feb 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be decimals <= 18, right? or alternatively WAD / 10 ** decimals > 0

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch


// Set variables
wantInfo = TokenInfo({
tokenAddress: _want,
scaler: uint96(WAD / 10 ** ERC20(_want).decimals())
scaler: uint96(WAD / 10 ** decimals)
});

// If we are using a hook.
Expand Down Expand Up @@ -425,6 +429,9 @@
_receiver != address(0) && _receiver != address(this),
"receiver"
);
// Cannot have more than 18 decimals.
uint256 decimals = ERC20(_from).decimals();
require(decimals <= WAD, "unsupported decimals");

// Calculate the id.
_auctionId = getAuctionId(_from);
Schlagonia marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -437,7 +444,7 @@
// Store all needed info.
auctions[_auctionId].fromInfo = TokenInfo({
tokenAddress: _from,
scaler: uint96(WAD / 10 ** ERC20(_from).decimals())
scaler: uint96(WAD / 10 ** decimals)
});
auctions[_auctionId].receiver = _receiver;

Expand All @@ -452,7 +459,20 @@
* @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 {
disable(_from, 0);
}

/**
* @notice Disables an existing auction.
* @dev Only callable by governance.
* @param _from The address of the token being sold.
* @param _index The index the auctionId is at in the array.
*/
function disable(
address _from,
uint256 _index
) public virtual onlyGovernance {
bytes32 _auctionId = getAuctionId(_from);

// Make sure the auction was enabled.
Expand All @@ -466,19 +486,28 @@

// Remove the auction ID from the array.
bytes32[] memory _enabledAuctions = enabledAuctions;
for (uint256 i = 0; i < _enabledAuctions.length; ++i) {
if (_enabledAuctions[i] == _auctionId) {
if (i < _enabledAuctions.length - 1) {
_enabledAuctions[i] = _enabledAuctions[
_enabledAuctions.length - 1
];
enabledAuctions = _enabledAuctions;
if (_enabledAuctions[_index] != _auctionId) {
// If the _index given is not the id find it.
for (uint256 i = 0; i < _enabledAuctions.length; ++i) {
if (_enabledAuctions[i] == _auctionId) {
_index = i;
break;
}
enabledAuctions.pop();
break;
}
}

// Move the id to the last spot if not there.
if (_index < _enabledAuctions.length - 1) {
_enabledAuctions[_index] = _enabledAuctions[
_enabledAuctions.length - 1
];
// Update the array.
enabledAuctions = _enabledAuctions;
}

// Pop the id off the array.
enabledAuctions.pop();

emit AuctionDisabled(_auctionId, _from, want(), address(this));
}

Expand Down Expand Up @@ -602,7 +631,7 @@
}

/// @dev Implements the take of the auction.
function _take(

Check warning on line 634 in src/Auctions/Auction.sol

View workflow job for this annotation

GitHub Actions / solidity

Function body contains 73 lines but allowed no more than 50 lines
bytes32 _auctionId,
uint256 _maxAmount,
fp-crypto marked this conversation as resolved.
Show resolved Hide resolved
address _receiver,
Expand Down
Loading