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

USDC/KWENTA Auctions #3

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open

USDC/KWENTA Auctions #3

wants to merge 13 commits into from

Conversation

Flocqst
Copy link
Collaborator

@Flocqst Flocqst commented Jul 31, 2024

Create an auction contract that sells off lots/tranches of USDC fees for KWENTA tokens

Description

  • Create an auction contract
    ** Auction lasts 1 day
    ** Bidding extends the auction by 1 hour if it is ending in less than an hour
    ** There is a configurable bidBuffer in order to prevent the auction running forever
    ** Every bidder can withdraw except for the highest bid
    ** Owner can pause bidding and withdraw funds in case there is an issue
  • Create an auction factory that will deploy a proxy that points to the auction contract

Auctions will be started every wednesday at UTC (noon) based off USDC in the KSX contract, so there will need to be some off-chain mechanism that create an auction each week using the auction factory.

Motivation and Context

Will be used by the KSX vault to compound usdc rewards into KWENTA tokens

@Flocqst Flocqst marked this pull request as ready for review August 5, 2024 18:14
Copy link
Contributor

@JaredBorders JaredBorders left a comment

Choose a reason for hiding this comment

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

really good work here!

auction logic is really impressive tbh. very elegant 😎

approving this now but would be good to get a deployment / factory test suite to make sure that entire process goes as expected


import {IERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
Copy link
Contributor

Choose a reason for hiding this comment

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

contracts-upgradeable gitmodule is missing

Copy link
Contributor

Choose a reason for hiding this comment

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

The contract exists in the repo that is included.

I change the import to:
"import "@openzeppelin/contracts/proxy/utils/Initializable.sol";"

and it worked fine

Copy link
Member

Choose a reason for hiding this comment

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

@Flocqst resolved?

@Flocqst Flocqst requested a review from jcmonte September 3, 2024 15:31
Copy link
Member

@jcmonte jcmonte left a comment

Choose a reason for hiding this comment

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

Good clean contract written from scratch, nice work. Architecture is nice too.

Still some logic issues to iron out if I'm understanding correctly, and left you some questions to think about / respond to.

Will do a second pass after you look over this again.


// Extend the auction if it is ending in less than an hour
if (endAt - block.timestamp < 1 hours) {
endAt = block.timestamp + 1 hours;
Copy link
Member

Choose a reason for hiding this comment

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

I thought we were making auction time countdown length customizable? Or are you implicitly assuming we will change via upgradeability (new version) in the future (which is fine).

Even so, this should probably be a constant for DRY purposes. Not good to hardcode the same value in multiple places.

constant COUNTDOWN_EXTENSION_PERIOD = 1 hours

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, if we want to change auction time in the future (currently one day) then yes it will be done through a new version of the auctionImplementation, as each new auction is its own contract deployed by the AuctionFactory (which means we cannot change the auction time for an auction that already started, but this should not be a problem according to the spec).

Comment on lines +210 to +217
function withdraw() external {
uint256 bal = bids[msg.sender];
bids[msg.sender] = 0;

kwenta.transfer(msg.sender, bal);

emit Withdraw(msg.sender, bal);
}
Copy link
Member

Choose a reason for hiding this comment

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

What if you are a winning bid, auction ends, and then you withdraw before the auction is settled?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You can't withdraw winning bid, even when the auction ends.

src/Auction.sol Outdated
Comment on lines 97 to 103
uint256 public endAt;

/// @notice Indicates if the auction has started.
bool public started;

/// @notice Indicates if the auction has ended.
bool public ended;
Copy link
Member

Choose a reason for hiding this comment

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

Typically it's better to only use 1 state variable to mark the state of a contract. What I mean is that technically you could end up in a state where endAt is in the past and ended is still false. This is an invariant you don't want.

Like it's better to have a endAt state variable and then a view function ended() that returns the result of the expression block.timestamp > endAt for example. Singular source of truth.

WDYT?

Copy link
Member

Choose a reason for hiding this comment

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

Unless you are using ended as a way to mark that the auction is already settled. Because I don't see it being used anywhere else. If that's the case it should just be settled.

Copy link
Collaborator Author

@Flocqst Flocqst Sep 11, 2024

Choose a reason for hiding this comment

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

renamed settled for clarity

src/Auction.sol Show resolved Hide resolved
src/Auction.sol Outdated Show resolved Hide resolved
@jcmonte
Copy link
Member

jcmonte commented Sep 23, 2024

Latest changes look good but lmk when you add the new requested things we talked about

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants