-
Notifications
You must be signed in to change notification settings - Fork 1
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
[DRAFT] Encrypted Derivative Value (EDV) Auction Module #196
Open
Oighty
wants to merge
4
commits into
develop
Choose a base branch
from
edv
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
213 changes: 213 additions & 0 deletions
213
src/interfaces/modules/auctions/IEncryptedDerivativeValue.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,213 @@ | ||
// SPDX-License-Identifier: AGPL-3.0-or-later | ||
pragma solidity >=0.8.0; | ||
|
||
import {Point} from "src/lib/ECIES.sol"; | ||
|
||
/// @title IEncryptedDerivativeValue | ||
/// @notice Interface for encrypted derivative value batch auctions | ||
/// @dev This contract does not inherit from `BatchAuctionModule` in order to avoid conflicts. Implementing contracts should inherit from both `BatchAuctionModule` and this interface. | ||
interface IEncryptedDerivativeValue { | ||
// ========== ERRORS ========== // | ||
|
||
error Auction_InvalidKey(); | ||
error Auction_WrongState(uint96 lotId); | ||
error Bid_WrongState(uint96 lotId, uint64 bidId); | ||
error NotPermitted(address caller); | ||
|
||
// ========== EVENTS ========== // | ||
|
||
event BidDecrypted(uint96 indexed lotId, uint64 indexed bidId, uint128 value); | ||
|
||
// ========== DATA STRUCTURES ========== // | ||
|
||
/// @notice Parameters that are used to set auction-specific data | ||
/// | ||
/// @param price The fixed price of the auction (quote tokens per base tokens) | ||
/// @param minValue The minimum derivative value that a user must bid to be considered in the auction | ||
/// @param sortHighToLow True if bid values are sorted high to low, false if low to high | ||
/// @param minFillPercent The minimum percentage of capacity that the lot must fill in order to settle. Maximum value = 100_000 = 1e5. | ||
/// @param minBidSize The minimum size of a bid in quote tokens | ||
/// @param publicKey The public key used to encrypt bids | ||
struct AuctionDataParams { | ||
uint256 price; | ||
uint128 minValue; | ||
bool sortHighToLow; | ||
uint24 minFillPercent; | ||
uint256 minBidSize; | ||
Point publicKey; | ||
} | ||
|
||
/// @notice Parameters to the bid function | ||
/// | ||
/// @param encryptedDerivativeValue The encrypted derivative value of the bid | ||
/// @param bidPublicKey The public key used to encrypt the bid | ||
struct BidParams { | ||
uint256 encryptedDerivativeValue; | ||
Point bidPublicKey; | ||
} | ||
|
||
/// @notice The status of an auction lot | ||
enum LotStatus { | ||
Created, | ||
Decrypted, | ||
Settled | ||
} | ||
|
||
/// @notice The status of a bid | ||
/// @dev Bid status will also be set to claimed if the bid is cancelled/refunded | ||
enum BidStatus { | ||
Submitted, | ||
Decrypted, | ||
Claimed | ||
} | ||
|
||
/// @notice Struct containing auction-specific data | ||
/// | ||
/// @param nextBidId The ID of the next bid to be submitted | ||
/// @param nextDecryptIndex The index of the next bid to decrypt | ||
/// @param status The status of the auction | ||
/// @param marginalBidId The ID of the marginal bid (marking that bids following it are not filled) | ||
/// @param marginalValue The marginal derivative value of the auction (determined at settlement, blank before) | ||
/// @param minValue The minimum derivative value that a user must bid to be considered in the auction | ||
/// @param price The fixed price of the auction (quote tokens per base token) | ||
/// @param minFilled The minimum amount of the lot that must be filled | ||
/// @param minBidSize The minimum size of a bid in quote tokens | ||
/// @param publicKey The public key used to encrypt bids (a point on the alt_bn128 curve from the generator point (1,2)) | ||
/// @param privateKey The private key used to decrypt bids (not provided until after the auction ends) | ||
/// @param bidIds The list of bid IDs to decrypt in order of submission, excluding cancelled bids | ||
struct AuctionData { | ||
uint64 nextBidId; // 8 + | ||
uint64 nextDecryptIndex; // 8 + | ||
LotStatus status; // 1 + | ||
uint64 marginalBidId; // 8 = 25 - end of slot 1 | ||
uint128 marginalValue; // 16 + | ||
uint128 minValue; // 16 = 32 - end of slot 2 | ||
uint256 price; // 32 - slot 3 | ||
uint256 minFilled; // 32 - slot 4 | ||
uint256 minBidSize; // 32 - slot 5 | ||
Point publicKey; // 64 - slots 6 and 7 | ||
uint256 privateKey; // 32 - slot 8 | ||
uint64[] bidIds; // slots 9+ | ||
} | ||
|
||
/// @notice Core data for a bid | ||
/// | ||
/// @param bidder The address of the bidder | ||
/// @param amount The amount of the bid | ||
/// @param minAmountOut The minimum amount out (not set until the bid is decrypted) | ||
/// @param referrer The address of the referrer | ||
/// @param status The status of the bid | ||
struct Bid { | ||
address bidder; // 20 + | ||
uint96 amount; // 12 = 32 - end of slot 1 | ||
address referrer; // 20 + | ||
BidStatus status; // 1 = 21 - end of slot 2 | ||
uint128 derivativeValue; // 16 - slot 3 | ||
} | ||
|
||
/// @notice Struct containing data for an encrypted bid | ||
/// | ||
/// @param encryptedAmountOut The encrypted derivative value. It is encrypted with a symmetric key that can be derived from the bidPubKey using the private key for the provided auction public key on the alt_bn128 curve | ||
/// @param bidPubKey The alt_bn128 public key used to encrypt the amount out (see bid() for more details) | ||
struct EncryptedBid { | ||
uint256 encryptedDerivativeValue; | ||
Point bidPubKey; | ||
} | ||
|
||
/// @notice Struct containing partial fill data for a lot | ||
/// | ||
/// @param bidId The ID of the bid | ||
/// @param refund The amount to refund to the bidder | ||
/// @param payout The amount to payout to the bidder | ||
struct PartialFill { | ||
uint64 bidId; // 8 + | ||
uint96 refund; // 12 = 20 - end of slot 1 | ||
uint256 payout; // 32 - slot 2 | ||
} | ||
|
||
// ========== DECRYPTION ========== // | ||
|
||
/// @notice Submits the private key for the auction lot and decrypts an initial number of bids | ||
/// It does not require gating. If the seller wishes to limit who can call, they can simply not reveal the key to anyone else. | ||
/// On the other hand, if a key management service is used, then anyone can call it once the key is revealed. | ||
/// | ||
/// @param lotId_ The lot ID of the auction to submit the private key for | ||
/// @param privateKey_ The ECIES private key to decrypt the bids | ||
/// @param num_ The number of bids to decrypt after submitting the private key (passed to `_decryptAndSortBids()`) | ||
/// @param sortHints_ The sort hints for the bid decryption (passed to `_decryptAndSortBids()`) | ||
function submitPrivateKey( | ||
uint96 lotId_, | ||
uint256 privateKey_, | ||
uint64 num_, | ||
bytes32[] calldata sortHints_ | ||
) external; | ||
|
||
/// @notice Decrypts a batch of bids and sorts them by price in descending order | ||
/// | ||
/// @param lotId_ The lot ID | ||
/// @param num_ The number of bids to decrypt and sort | ||
/// @param sortHints_ The sort hints for the bids | ||
function decryptAndSortBids( | ||
uint96 lotId_, | ||
uint64 num_, | ||
bytes32[] calldata sortHints_ | ||
) external; | ||
|
||
/// @notice Returns the decrypted amountOut of a single bid without altering contract state | ||
/// | ||
/// @param lotId_ The lot ID of the auction to decrypt the bid for | ||
/// @param bidId_ The bid ID to decrypt | ||
/// @return derivativeValue The decrypted derivative value | ||
function decryptBid( | ||
uint96 lotId_, | ||
uint64 bidId_ | ||
) external view returns (uint128 derivativeValue); | ||
|
||
/// @notice Returns the bid after `key_` in the queue | ||
/// | ||
/// @param lotId_ The lot ID | ||
/// @param key_ The key to search for | ||
/// @return nextKey The key of the next bid in the queue | ||
function getNextInQueue(uint96 lotId_, bytes32 key_) external view returns (bytes32 nextKey); | ||
|
||
/// @notice Returns the number of decrypted bids remaining in the queue | ||
/// | ||
/// @param lotId_ The lot ID | ||
/// @return numBids The number of decrypted bids remaining in the queue | ||
function getNumBidsInQueue(uint96 lotId_) external view returns (uint256 numBids); | ||
|
||
/// @notice Returns whether the lot sorts bids from high to low (true) or low to high (false) | ||
function sortHighToLow(uint96 lotId_) external view returns (bool); | ||
|
||
// ========== AUCTION INFORMATION ========== // | ||
|
||
/// @notice Returns the `Bid` and `EncryptedBid` data for a given lot and bid ID | ||
/// | ||
/// @param lotId_ The lot ID | ||
/// @param bidId_ The bid ID | ||
/// @return bid The `Bid` data | ||
/// @return encryptedBid The `EncryptedBid` data | ||
function getBid( | ||
uint96 lotId_, | ||
uint64 bidId_ | ||
) external view returns (Bid memory bid, EncryptedBid memory encryptedBid); | ||
|
||
/// @notice Returns the `AuctionData` data for an auction lot | ||
/// | ||
/// @param lotId_ The lot ID | ||
/// @return auctionData_ The `AuctionData` | ||
function getAuctionData(uint96 lotId_) | ||
external | ||
view | ||
returns (AuctionData memory auctionData_); | ||
|
||
/// @notice Returns the `PartialFill` data for an auction lot | ||
/// | ||
/// @param lotId_ The lot ID | ||
/// @return hasPartialFill True if a partial fill exists | ||
/// @return partialFill The `PartialFill` data | ||
function getPartialFill(uint96 lotId_) | ||
external | ||
view | ||
returns (bool hasPartialFill, PartialFill memory partialFill); | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the reasoning for having this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There may be instances where you want the winners to be whoever bids the lowest value for some parameter. Some examples are: the duration of an option, the size of an additional incentive, the strike price of a put option.
Because of this
minValue
may need to conditionally bemaxValue