From b2a58c7f549b3d913235a91b72f029fe31bec815 Mon Sep 17 00:00:00 2001 From: sam bacha Date: Wed, 22 May 2024 11:19:29 -0700 Subject: [PATCH] feat(rulebook): contracts --- .../Accountant.sol/contract.Accountant.md | 389 ++++++++++++++ .../Auctioneer.sol/contract.Auctioneer.md | 507 ++++++++++++++++++ .../Auctioneer.sol/interface.Bidder.md | 26 + .../Auctioneer.sol/interface.IAccountant.md | 26 + .../L1Holding.sol/contract.L1Holding.md | 133 +++++ docs/Rulebook/contracts/README.md | 12 + .../contract.SettlementHouse.md | 83 +++ .../Ownable2Step.sol/abstract.Ownable2Step.md | 77 +++ docs/Rulebook/contracts/auth/README.md | 5 + .../auth/solady.auth.sol/abstract.Owned.md | 46 ++ .../IERC6909.sol/interface.IERC6909.md | 195 +++++++ .../IL1Bridge.sol/interface.IL1Bridge.md | 26 + .../IL2Bridge.sol/interface.IL2Bridge.md | 32 ++ .../interfaces/IWETH.sol/interface.IWETH.md | 19 + docs/Rulebook/contracts/interfaces/README.md | 7 + .../solady.libsort.sol/library.LibSort.md | 387 +++++++++++++ 16 files changed, 1970 insertions(+) create mode 100644 docs/Rulebook/contracts/Accountant.sol/contract.Accountant.md create mode 100644 docs/Rulebook/contracts/Auctioneer.sol/contract.Auctioneer.md create mode 100644 docs/Rulebook/contracts/Auctioneer.sol/interface.Bidder.md create mode 100644 docs/Rulebook/contracts/Auctioneer.sol/interface.IAccountant.md create mode 100644 docs/Rulebook/contracts/L1Holding.sol/contract.L1Holding.md create mode 100644 docs/Rulebook/contracts/README.md create mode 100644 docs/Rulebook/contracts/SettlementHouse.sol/contract.SettlementHouse.md create mode 100644 docs/Rulebook/contracts/auth/Ownable2Step.sol/abstract.Ownable2Step.md create mode 100644 docs/Rulebook/contracts/auth/README.md create mode 100644 docs/Rulebook/contracts/auth/solady.auth.sol/abstract.Owned.md create mode 100644 docs/Rulebook/contracts/interfaces/IERC6909.sol/interface.IERC6909.md create mode 100644 docs/Rulebook/contracts/interfaces/IL1Bridge.sol/interface.IL1Bridge.md create mode 100644 docs/Rulebook/contracts/interfaces/IL2Bridge.sol/interface.IL2Bridge.md create mode 100644 docs/Rulebook/contracts/interfaces/IWETH.sol/interface.IWETH.md create mode 100644 docs/Rulebook/contracts/interfaces/README.md create mode 100644 docs/Rulebook/contracts/solady.libsort.sol/library.LibSort.md diff --git a/docs/Rulebook/contracts/Accountant.sol/contract.Accountant.md b/docs/Rulebook/contracts/Accountant.sol/contract.Accountant.md new file mode 100644 index 0000000..acdce45 --- /dev/null +++ b/docs/Rulebook/contracts/Accountant.sol/contract.Accountant.md @@ -0,0 +1,389 @@ +# Accountant +[Git Source](https://github.com/manifoldfinance/auctioneer/blob/94186b27ea5ddae3ff2f27674c7d42c6d498df0f/src/Accountant.sol) + +**Inherits:** +[Ownable2Step](/src/auth/Ownable2Step.sol/abstract.Ownable2Step.md) + +**Author:** +MEV Protocol + +*Pays out validators, protocol fees and L2 infrastructure from auction and coinbase revenue* + + +## State Variables +### minGasLimit +min gas limit for L2 bridge tx + + +```solidity +uint32 public minGasLimit = 200_000; +``` + + +### bridge +L2 => L1 bridge + + +```solidity +IL2Bridge public bridge; +``` + + +### weth +L2 Weth + + +```solidity +WETH public immutable weth; +``` + + +### auctioneer + +```solidity +address public auctioneer; +``` + + +### LEGACY_ERC20_ETH +Address of the LegacyERC20ETH predeploy + + +```solidity +address internal constant LEGACY_ERC20_ETH = 0xDeadDeAddeAddEAddeadDEaDDEAdDeaDDeAD0000; +``` + + +### adminFeePerTenThousand +per 10,000 of revenue to allocate for protocol + + +```solidity +uint256 public constant adminFeePerTenThousand = 1; +``` + + +### isValidatorRegistered +registered validator payout addresses + + +```solidity +mapping(address => bool) public isValidatorRegistered; +``` + + +### activeValidators +List of active validators + + +```solidity +mapping(uint256 => address) public activeValidators; +``` + + +### numValidatorsRegistered +number of validators registered to reward address + + +```solidity +mapping(address => uint256) public numValidatorsRegistered; +``` + + +### validatorCount +Number of active validator reward addresses + + +```solidity +uint256 public validatorCount; +``` + + +### totalValidatorCount +Cumulative total of registered validators + + +```solidity +uint256 public totalValidatorCount; +``` + + +### payoutRecord + +```solidity +mapping(address validator => uint256 cumulativeAmount) public payoutRecord; +``` + + +### minPayout +threshold payout amount to make make L1 fees worthwhile + + +```solidity +uint256 public minPayout; +``` + + +## Functions +### constructor + +*Initializes the Accountant contract.* + + +```solidity +constructor(address _bridge, address _weth, uint256 _minPayout) Ownable2Step(msg.sender); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`_bridge`|`address`|Address of the L2 bridge contract.| +|`_weth`|`address`|Address of the WETH contract.| +|`_minPayout`|`uint256`|| + + +### receive + +*Fallback function to receive Ether.* + + +```solidity +receive() external payable; +``` + +### onlyAuctioneer + +*Modifier to only allow Auctioneer contract as caller* + + +```solidity +modifier onlyAuctioneer(); +``` + +### getValidatorList + +*Get validator list* + + +```solidity +function getValidatorList() external view returns (address[] memory validators); +``` +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`validators`|`address[]`|list| + + +### getTotalPayout + +*Get total payouts* + + +```solidity +function getTotalPayout() external view returns (uint256 total); +``` +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`total`|`uint256`|payout amount| + + +### getPayoutBalance + +*gets current aggregated balance for validator payouts* + + +```solidity +function getPayoutBalance() external view returns (uint256 payoutBalance); +``` + +### payout + +*Distributes funds to various addresses based on predefined shares.* + + +```solidity +function payout() external onlyAuctioneer; +``` + +### updateBridge + +*Updates the address of the L2 bridge contract.* + + +```solidity +function updateBridge(address _bridge) external onlyOwner; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`_bridge`|`address`|New address of the L2 bridge contract.| + + +### updateMinGasLimit + +*Updates the minimum gas limit for L2 bridge transactions.* + + +```solidity +function updateMinGasLimit(uint32 _minGasLimit) external onlyOwner; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`_minGasLimit`|`uint32`|New minimum gas limit.| + + +### updateMinPayout + +*Updates the minimum threshold balance for L1 validator payouts.* + + +```solidity +function updateMinPayout(uint256 _minPayout) external onlyOwner; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`_minPayout`|`uint256`|New minimum payout threshold.| + + +### registerValidator + +*Registers a validator.* + + +```solidity +function registerValidator(address validator, uint256 numValidators) public onlyOwner; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`validator`|`address`|Address of the validator to register.| +|`numValidators`|`uint256`|Number of validators registered for above address.| + + +### updateNumValidators + +*Updates a number of registered a validators.* + + +```solidity +function updateNumValidators(address validator, uint256 numValidators) external onlyOwner; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`validator`|`address`|Address of the validator.| +|`numValidators`|`uint256`|Number of validators registered for above address.| + + +### unregisterValidator + +*Unregisters a validator.* + + +```solidity +function unregisterValidator(address validator) public onlyOwner; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`validator`|`address`|Address of the validator to unregister.| + + +### registerBatchValidators + +*Registers a batch of validators.* + + +```solidity +function registerBatchValidators(address[] calldata validators, uint256[] calldata numValidators) external onlyOwner; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`validators`|`address[]`|Address list of the validators to register.| +|`numValidators`|`uint256[]`|Number of validators registered for each above address.| + + +### unregisterBatchValidators + +*Unregisters a batch of validators.* + + +```solidity +function unregisterBatchValidators(address[] calldata validators) external onlyOwner; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`validators`|`address[]`|Address list of the validators to unregister.| + + +### updateAuctioneer + +*Updates auctioneer address* + + +```solidity +function updateAuctioneer(address _auctioneer) external onlyOwner; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`_auctioneer`|`address`|address of Auctioneer contract| + + +### removeValidatorFromArray + +*Removes a validator address from the activeValidators array.* + + +```solidity +function removeValidatorFromArray(address validator) internal; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`validator`|`address`|Address of the validator to remove.| + + +## Events +### PaymentReceived + +```solidity +event PaymentReceived(address indexed sender, uint256 amount); +``` + +### PaymentSplit + +```solidity +event PaymentSplit(address indexed sender, uint256 adminFee, uint256 validatorsShare); +``` + +### AuctioneerUpdated + +```solidity +event AuctioneerUpdated(address indexed _auctioneer); +``` + +## Errors +### ThresholdBalanceNotMet + +```solidity +error ThresholdBalanceNotMet(); +``` + diff --git a/docs/Rulebook/contracts/Auctioneer.sol/contract.Auctioneer.md b/docs/Rulebook/contracts/Auctioneer.sol/contract.Auctioneer.md new file mode 100644 index 0000000..be41eca --- /dev/null +++ b/docs/Rulebook/contracts/Auctioneer.sol/contract.Auctioneer.md @@ -0,0 +1,507 @@ +# Auctioneer +[Git Source](https://github.com/manifoldfinance/auctioneer/blob/94186b27ea5ddae3ff2f27674c7d42c6d498df0f/src/Auctioneer.sol) + +**Inherits:** +ERC6909, [Ownable2Step](/src/auth/Ownable2Step.sol/abstract.Ownable2Step.md) + +*Implements an auction mechanism for selling block space.* + + +## State Variables +### maxBidder + +```solidity +uint8 public maxBidder; +``` + + +### WETH9 + +```solidity +WETH public immutable WETH9; +``` + + +### accountant + +```solidity +address public accountant; +``` + + +### maxBids + +```solidity +uint256 public maxBids = 50; +``` + + +### minGasAmount + +```solidity +uint120 public minGasAmount = 20_000; +``` + + +### operator + +```solidity +address public operator; +``` + + +### IdMap + +```solidity +mapping(address bidder => uint8 id) public IdMap; +``` + + +### bidderMap + +```solidity +mapping(uint8 id => address bidder) public bidderMap; +``` + + +### auctions + +```solidity +mapping(uint256 slot => Auction) public auctions; +``` + + +### slotsCount + +```solidity +uint256 public slotsCount; +``` + + +### slotsAuctioned + +```solidity +mapping(uint256 index => uint256 slot) public slotsAuctioned; +``` + + +### bidCount + +```solidity +mapping(uint256 slot => uint256 count) public bidCount; +``` + + +### bids + +```solidity +mapping(uint256 slot => mapping(uint256 index => uint256 bid)) internal bids; +``` + + +## Functions +### constructor + + +```solidity +constructor(WETH _weth, address _accountant) Ownable2Step(msg.sender); +``` + +### onlyOperator + + +```solidity +modifier onlyOperator(); +``` + +### newBidder + +*Add a new bidder to the auction.* + + +```solidity +function newBidder(address additionalBidder) external onlyOwner returns (uint8 newId); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`additionalBidder`|`address`|The address of the additional bidder.| + + +### removeBidder + +*Remove a bidder from the auction.* + + +```solidity +function removeBidder(uint8 bidderId) external onlyOwner; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`bidderId`|`uint8`|The index of the bidder to be removed.| + + +### changeOperator + +*Change operator of the auction.* + + +```solidity +function changeOperator(address newOperator) external onlyOwner; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`newOperator`|`address`|The address of the new operator| + + +### openAuction + +*Open a new auction for a specific slot.* + + +```solidity +function openAuction(uint256 slot, uint120 itemsForSale) external onlyOperator; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`slot`|`uint256`|The auction slot.| +|`itemsForSale`|`uint120`|The number of items available for sale in the auction.| + + +### bid + +*Bid function for bidders to submit manual bids.* + + +```solidity +function bid(uint256 slot, uint256[] memory packedBids) external; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`slot`|`uint256`|The auction slot.| +|`packedBids`|`uint256[]`|Array of packed bids| + + +### runAndSettle + +*Execute the auction for a specific slot.* + + +```solidity +function runAndSettle(uint256 slot) public onlyOperator; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`slot`|`uint256`|The auction slot.| + + +### payout + +*Payout revenue from auction to validators* + + +```solidity +function payout(uint256 slot) external onlyOperator; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`slot`|`uint256`|The auction slot.| + + +### refund + +*Refund revenue from auction to bidders* + + +```solidity +function refund(uint256 slot) external onlyOperator; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`slot`|`uint256`|The auction slot.| + + +### getBidderInfo + +*Retrieve information about a bidder after auction settlement.* + + +```solidity +function getBidderInfo(uint256 slot, address bidder) external view returns (uint120 itemsBought, uint128 amountOwed); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`slot`|`uint256`|The slot identifier of the auction.| +|`bidder`|`address`|The address of the bidder for whom information is requested.| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`itemsBought`|`uint120`|The number of items bought by the bidder in the specified auction.| +|`amountOwed`|`uint128`|The amount owed by the bidder for the items bought in the specified auction. Requirements: - The auction must have been settled. - The provided `bidder` address must be valid and have participated in the auction.| + + +### packBid + +*Packed Bid details into a uint256 for submission.* + + +```solidity +function packBid(uint128 bidPrice, uint120 itemsToBuy, uint8 bidderId) external pure returns (uint256 packedBid); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`bidPrice`|`uint128`|Price per item.| +|`itemsToBuy`|`uint120`|Items to buy in the auction.| +|`bidderId`|`uint8`|Id for bidder| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`packedBid`|`uint256`|for auction submission| + + +### decodeBid + +*Decode the packed bid information.* + + +```solidity +function decodeBid(uint256 packedBid) internal pure returns (uint8 bidderId, uint120 itemsToBuy, uint128 bidPrice); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`packedBid`|`uint256`|The packed bid information.| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`bidderId`|`uint8`|The bidder's ID.| +|`itemsToBuy`|`uint120`|The number of items the bidder wants to buy.| +|`bidPrice`|`uint128`|The price per item in the bid.| + + +### calcAverageBid + +*Calculate average bid price for the last n auctions* + + +```solidity +function calcAverageBid(uint256 numAuctions) external view returns (uint128 avBidPrice); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`numAuctions`|`uint256`|Number of auctions to average for| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`avBidPrice`|`uint128`|for last n auctions| + + +### checkAndStoreBid + +*Check the validity of a bid.* + + +```solidity +function checkAndStoreBid( + bool revertInvalid, + address bidder, + uint256 slot, + uint256 itemsForSale, + uint256[] memory packedBids +) internal; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`revertInvalid`|`bool`|true for manual bids causing reverts for invalid data| +|`bidder`|`address`|Address of bidder.| +|`slot`|`uint256`|The auction slot.| +|`itemsForSale`|`uint256`|Total items for sale for the slot.| +|`packedBids`|`uint256[]`|Array of packed bids Requirements: - The number of items in the bid must not exceed the available items for sale in the auction. - The bidder must have enough funds to cover the bid amount.| + + +### updateAccountant + +*update accountant address* + + +```solidity +function updateAccountant(address newAccountant) external onlyOwner; +``` + +### updateMaxBids + +*update max num of bids per bidder* + + +```solidity +function updateMaxBids(uint256 newMaxBids) external onlyOwner; +``` + +### updateMinGasAmount + +*update minGasAmount* + + +```solidity +function updateMinGasAmount(uint120 newAmount) external onlyOwner; +``` + +## Events +### OperatorUpdated + +```solidity +event OperatorUpdated(address indexed oldOperator, address indexed newOperator); +``` + +### AuctionSettled + +```solidity +event AuctionSettled(uint256 indexed slot); +``` + +### BidderAdded + +```solidity +event BidderAdded(address indexed bidder, uint8 indexed bidderId); +``` + +### BidderRemoved + +```solidity +event BidderRemoved(address indexed bidder, uint8 indexed bidderId); +``` + +### AuctionOpened + +```solidity +event AuctionOpened(uint256 indexed slot, uint120 itemsForSale); +``` + +### AuctionPaidOut + +```solidity +event AuctionPaidOut(uint256 indexed slot); +``` + +### AuctionRefund + +```solidity +event AuctionRefund(uint256 indexed slot); +``` + +## Errors +### InvalidId + +```solidity +error InvalidId(); +``` + +### Unauthorized + +```solidity +error Unauthorized(); +``` + +### InvalidBidItems + +```solidity +error InvalidBidItems(); +``` + +### InsufficientFunds + +```solidity +error InsufficientFunds(); +``` + +### AuctionNotOpen + +```solidity +error AuctionNotOpen(uint256 slot); +``` + +### AuctionNotClosed + +```solidity +error AuctionNotClosed(uint256 slot); +``` + +### AuctionAlreadyOpen + +```solidity +error AuctionAlreadyOpen(uint256 slot); +``` + +### AuctionAlreadySettled + +```solidity +error AuctionAlreadySettled(uint256 slot); +``` + +### BidderNotRegistered + +```solidity +error BidderNotRegistered(address bidder); +``` + +### BidderAlreadyExists + +```solidity +error BidderAlreadyExists(address bidder); +``` + +## Structs +### Auction + +```solidity +struct Auction { + uint120 itemsForSale; + bool isOpen; + bool isSettled; + bool isPaidOut; + bool isRefunded; + mapping(address => BidderInfo) biddersInfo; +} +``` + +### BidderInfo + +```solidity +struct BidderInfo { + uint120 itemsBought; + uint128 amountOwed; +} +``` + diff --git a/docs/Rulebook/contracts/Auctioneer.sol/interface.Bidder.md b/docs/Rulebook/contracts/Auctioneer.sol/interface.Bidder.md new file mode 100644 index 0000000..2ffa579 --- /dev/null +++ b/docs/Rulebook/contracts/Auctioneer.sol/interface.Bidder.md @@ -0,0 +1,26 @@ +# Bidder +[Git Source](https://github.com/manifoldfinance/auctioneer/blob/94186b27ea5ddae3ff2f27674c7d42c6d498df0f/src/Auctioneer.sol) + + +## Functions +### getBid + +*Get the bid from a bidder for a specific slot and round.* + + +```solidity +function getBid(uint256 slot) external view returns (uint256[] memory packedBids); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`slot`|`uint256`|The auction slot.| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`packedBids`|`uint256[]`|Array of bids (in a packed format). uint256(uint128(bidPrice),uint120(itemsToBuy),uint8(bidderId))| + + diff --git a/docs/Rulebook/contracts/Auctioneer.sol/interface.IAccountant.md b/docs/Rulebook/contracts/Auctioneer.sol/interface.IAccountant.md new file mode 100644 index 0000000..2072716 --- /dev/null +++ b/docs/Rulebook/contracts/Auctioneer.sol/interface.IAccountant.md @@ -0,0 +1,26 @@ +# IAccountant +[Git Source](https://github.com/manifoldfinance/auctioneer/blob/94186b27ea5ddae3ff2f27674c7d42c6d498df0f/src/Auctioneer.sol) + + +## Functions +### payout + + +```solidity +function payout() external; +``` + +### getPayoutBalance + + +```solidity +function getPayoutBalance() external view returns (uint256 payoutBalance); +``` + +### minPayout + + +```solidity +function minPayout() external view returns (uint256 amount); +``` + diff --git a/docs/Rulebook/contracts/L1Holding.sol/contract.L1Holding.md b/docs/Rulebook/contracts/L1Holding.sol/contract.L1Holding.md new file mode 100644 index 0000000..f59baaf --- /dev/null +++ b/docs/Rulebook/contracts/L1Holding.sol/contract.L1Holding.md @@ -0,0 +1,133 @@ +# L1Holding +[Git Source](https://github.com/manifoldfinance/auctioneer/blob/94186b27ea5ddae3ff2f27674c7d42c6d498df0f/src/L1Holding.sol) + +**Inherits:** +[Ownable2Step](/src/auth/Ownable2Step.sol/abstract.Ownable2Step.md) + +**Author:** +MEV Protocol + +*Pays out L1 builder payments to L2 Accountant* + + +## State Variables +### minGasLimit +min gas limit for L2 bridge tx + + +```solidity +uint32 public minGasLimit = 200_000; +``` + + +### accountant +L2 accountant + + +```solidity +address public accountant; +``` + + +### bridge +L1 => L2 bridge + + +```solidity +IL1Bridge public bridge; +``` + + +## Functions +### constructor + +*Initializes the L1Holding contract.* + + +```solidity +constructor(address _accountant, address _bridge) Ownable2Step(msg.sender); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`_accountant`|`address`|Address of the protocol treasury.| +|`_bridge`|`address`|Address of the L2 bridge contract.| + + +### receive + +*Fallback function to receive Ether.* + + +```solidity +receive() external payable; +``` + +### payAccounatnt + +*Pays accountant.* + + +```solidity +function payAccounatnt() external; +``` + +### updateAccountant + +*Updates the L2 accountant address.* + + +```solidity +function updateAccountant(address _accountant) external onlyOwner; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`_accountant`|`address`|New address of the L2 accountant| + + +### updateBridge + +*Updates the address of the L2 bridge contract.* + + +```solidity +function updateBridge(address _bridge) external onlyOwner; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`_bridge`|`address`|New address of the L2 bridge contract.| + + +### updateMinGasLimit + +*Updates the minimum gas limit for L2 bridge transactions.* + + +```solidity +function updateMinGasLimit(uint32 _minGasLimit) external onlyOwner; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`_minGasLimit`|`uint32`|New minimum gas limit.| + + +## Events +### PaymentReceived + +```solidity +event PaymentReceived(address indexed sender, uint256 amount); +``` + +### PaymentSent + +```solidity +event PaymentSent(address indexed recipient, uint256 amount); +``` + diff --git a/docs/Rulebook/contracts/README.md b/docs/Rulebook/contracts/README.md new file mode 100644 index 0000000..39fcd60 --- /dev/null +++ b/docs/Rulebook/contracts/README.md @@ -0,0 +1,12 @@ + + +# Contents +- [auth](/src/auth) +- [interfaces](/src/interfaces) +- [Accountant](Accountant.sol/contract.Accountant.md) +- [Bidder](Auctioneer.sol/interface.Bidder.md) +- [IAccountant](Auctioneer.sol/interface.IAccountant.md) +- [Auctioneer](Auctioneer.sol/contract.Auctioneer.md) +- [L1Holding](L1Holding.sol/contract.L1Holding.md) +- [SettlementHouse](SettlementHouse.sol/contract.SettlementHouse.md) +- [LibSort](solady.libsort.sol/library.LibSort.md) diff --git a/docs/Rulebook/contracts/SettlementHouse.sol/contract.SettlementHouse.md b/docs/Rulebook/contracts/SettlementHouse.sol/contract.SettlementHouse.md new file mode 100644 index 0000000..98d8ec5 --- /dev/null +++ b/docs/Rulebook/contracts/SettlementHouse.sol/contract.SettlementHouse.md @@ -0,0 +1,83 @@ +# SettlementHouse +[Git Source](https://github.com/manifoldfinance/auctioneer/blob/94186b27ea5ddae3ff2f27674c7d42c6d498df0f/src/SettlementHouse.sol) + +*A contract for managing bundles of transactions for a futures token.* + + +## State Variables +### futuresToken + +```solidity +IERC6909 public immutable futuresToken; +``` + + +### bundleCounter + +```solidity +mapping(uint256 => uint256) internal bundleCounter; +``` + + +### bundles + +```solidity +mapping(uint256 => mapping(uint256 => Bundle)) internal bundles; +``` + + +## Functions +### constructor + +*Constructor to initialize the contract with the futures token contract address.* + + +```solidity +constructor(IERC6909 _futuresToken); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`_futuresToken`|`IERC6909`|Address of the futures token contract.| + + +### submitBundle + + +```solidity +function submitBundle(uint256 slot, uint256 amountOfGas, bytes32[] calldata bundleHashes) external; +``` + +### queryBundles + + +```solidity +function queryBundles(uint256 slot) external view returns (Bundle[] memory slotBundles); +``` + +## Events +### BundleSubmitted + +```solidity +event BundleSubmitted(address indexed sender, uint256 indexed slot, uint256 indexed index, uint256 amountOfGas); +``` + +## Errors +### Unauthorized + +```solidity +error Unauthorized(); +``` + +## Structs +### Bundle + +```solidity +struct Bundle { + address submitter; + uint256 amountOfGas; + bytes32[] bundleHashes; +} +``` + diff --git a/docs/Rulebook/contracts/auth/Ownable2Step.sol/abstract.Ownable2Step.md b/docs/Rulebook/contracts/auth/Ownable2Step.sol/abstract.Ownable2Step.md new file mode 100644 index 0000000..a9e072c --- /dev/null +++ b/docs/Rulebook/contracts/auth/Ownable2Step.sol/abstract.Ownable2Step.md @@ -0,0 +1,77 @@ +# Ownable2Step +[Git Source](https://github.com/manifoldfinance/auctioneer/blob/94186b27ea5ddae3ff2f27674c7d42c6d498df0f/src/auth/Ownable2Step.sol) + +**Inherits:** +[Owned](/src/auth/solady.auth.sol/abstract.Owned.md) + +*An abstract contract that extends the Owned contract and provides a two-step ownership +transfer mechanism. +The contract allows the current owner to initiate a transfer of ownership to a new account. The +new owner must then +explicitly accept the ownership transfer to complete the process. +This contract emits an `OwnershipTransferStarted` event when the ownership transfer is initiated, +and an +`OwnershipTransferred` event when the transfer is completed.* + + +## State Variables +### pendingOwner + +```solidity +address public pendingOwner; +``` + + +## Functions +### constructor + + +```solidity +constructor(address _owner) Owned(_owner); +``` + +### onlyPendingOwner + + +```solidity +modifier onlyPendingOwner() virtual; +``` + +### transferOwnership + +*Starts the ownership transfer of the contract to a new account. Replaces the pending +transfer if there is one. +Can only be called by the current owner.* + + +```solidity +function transferOwnership(address newOwner) public virtual override onlyOwner; +``` + +### _transferOwnership + +*Transfers ownership of the contract to a new account (`newOwner`) and deletes any pending +owner. +Internal function without access restriction.* + + +```solidity +function _transferOwnership(address newOwner) internal virtual; +``` + +### acceptOwnership + +*The new owner accepts the ownership transfer.* + + +```solidity +function acceptOwnership() public virtual onlyPendingOwner; +``` + +## Events +### OwnershipTransferStarted + +```solidity +event OwnershipTransferStarted(address indexed previousOwner, address indexed newOwner); +``` + diff --git a/docs/Rulebook/contracts/auth/README.md b/docs/Rulebook/contracts/auth/README.md new file mode 100644 index 0000000..5ede1a6 --- /dev/null +++ b/docs/Rulebook/contracts/auth/README.md @@ -0,0 +1,5 @@ + + +# Contents +- [Ownable2Step](Ownable2Step.sol/abstract.Ownable2Step.md) +- [Owned](solady.auth.sol/abstract.Owned.md) diff --git a/docs/Rulebook/contracts/auth/solady.auth.sol/abstract.Owned.md b/docs/Rulebook/contracts/auth/solady.auth.sol/abstract.Owned.md new file mode 100644 index 0000000..12445c8 --- /dev/null +++ b/docs/Rulebook/contracts/auth/solady.auth.sol/abstract.Owned.md @@ -0,0 +1,46 @@ +# Owned +[Git Source](https://github.com/manifoldfinance/auctioneer/blob/94186b27ea5ddae3ff2f27674c7d42c6d498df0f/src/auth/solady.auth.sol) + +**Author:** +Solmate (https://github.com/transmissions11/solmate/blob/main/src/auth/Owned.sol) + +Simple single owner authorization mixin. + + +## State Variables +### owner + +```solidity +address public owner; +``` + + +## Functions +### onlyOwner + + +```solidity +modifier onlyOwner() virtual; +``` + +### constructor + + +```solidity +constructor(address _owner); +``` + +### transferOwnership + + +```solidity +function transferOwnership(address newOwner) public virtual onlyOwner; +``` + +## Events +### OwnershipTransferred + +```solidity +event OwnershipTransferred(address indexed user, address indexed newOwner); +``` + diff --git a/docs/Rulebook/contracts/interfaces/IERC6909.sol/interface.IERC6909.md b/docs/Rulebook/contracts/interfaces/IERC6909.sol/interface.IERC6909.md new file mode 100644 index 0000000..5335935 --- /dev/null +++ b/docs/Rulebook/contracts/interfaces/IERC6909.sol/interface.IERC6909.md @@ -0,0 +1,195 @@ +# IERC6909 +[Git Source](https://github.com/manifoldfinance/auctioneer/blob/94186b27ea5ddae3ff2f27674c7d42c6d498df0f/src/interfaces/IERC6909.sol) + +**Author:** +jtriley.eth + + +## Functions +### balanceOf + +Owner balance of an id. + + +```solidity +function balanceOf(address owner, uint256 id) external view returns (uint256 amount); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`owner`|`address`|The address of the owner.| +|`id`|`uint256`|The id of the token.| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`amount`|`uint256`|The balance of the token.| + + +### allowance + +Spender allowance of an id. + + +```solidity +function allowance(address owner, address spender, uint256 id) external view returns (uint256 amount); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`owner`|`address`|The address of the owner.| +|`spender`|`address`|The address of the spender.| +|`id`|`uint256`|The id of the token.| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`amount`|`uint256`|The allowance of the token.| + + +### isOperator + +Checks if a spender is approved by an owner as an operator + + +```solidity +function isOperator(address owner, address spender) external view returns (bool approved); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`owner`|`address`|The address of the owner.| +|`spender`|`address`|The address of the spender.| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`approved`|`bool`|The approval status.| + + +### transfer + +Transfers an amount of an id from the caller to a receiver. + + +```solidity +function transfer(address receiver, uint256 id, uint256 amount) external returns (bool); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`receiver`|`address`|The address of the receiver.| +|`id`|`uint256`|The id of the token.| +|`amount`|`uint256`|The amount of the token.| + + +### transferFrom + +Transfers an amount of an id from a sender to a receiver. + + +```solidity +function transferFrom(address sender, address receiver, uint256 id, uint256 amount) external returns (bool); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`sender`|`address`|The address of the sender.| +|`receiver`|`address`|The address of the receiver.| +|`id`|`uint256`|The id of the token.| +|`amount`|`uint256`|The amount of the token.| + + +### approve + +Approves an amount of an id to a spender. + + +```solidity +function approve(address spender, uint256 id, uint256 amount) external returns (bool); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`spender`|`address`|The address of the spender.| +|`id`|`uint256`|The id of the token.| +|`amount`|`uint256`|The amount of the token.| + + +### setOperator + +Sets or removes a spender as an operator for the caller. + + +```solidity +function setOperator(address spender, bool approved) external returns (bool); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`spender`|`address`|The address of the spender.| +|`approved`|`bool`|The approval status.| + + +## Events +### Transfer +The event emitted when a transfer occurs. + + +```solidity +event Transfer(address caller, address indexed sender, address indexed receiver, uint256 indexed id, uint256 amount); +``` + +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`caller`|`address`|The caller of the transfer.| +|`sender`|`address`|The address of the sender.| +|`receiver`|`address`|The address of the receiver.| +|`id`|`uint256`|The id of the token.| +|`amount`|`uint256`|The amount of the token.| + +### OperatorSet +The event emitted when an operator is set. + + +```solidity +event OperatorSet(address indexed owner, address indexed spender, bool approved); +``` + +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`owner`|`address`|The address of the owner.| +|`spender`|`address`|The address of the spender.| +|`approved`|`bool`|The approval status.| + +### Approval +The event emitted when an approval occurs. + + +```solidity +event Approval(address indexed owner, address indexed spender, uint256 indexed id, uint256 amount); +``` + +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`owner`|`address`|The address of the owner.| +|`spender`|`address`|The address of the spender.| +|`id`|`uint256`|The id of the token.| +|`amount`|`uint256`|The amount of the token.| + diff --git a/docs/Rulebook/contracts/interfaces/IL1Bridge.sol/interface.IL1Bridge.md b/docs/Rulebook/contracts/interfaces/IL1Bridge.sol/interface.IL1Bridge.md new file mode 100644 index 0000000..aa3f5c9 --- /dev/null +++ b/docs/Rulebook/contracts/interfaces/IL1Bridge.sol/interface.IL1Bridge.md @@ -0,0 +1,26 @@ +# IL1Bridge +[Git Source](https://github.com/manifoldfinance/auctioneer/blob/94186b27ea5ddae3ff2f27674c7d42c6d498df0f/src/interfaces/IL1Bridge.sol) + + +## Functions +### depositETHTo + +Deposits some amount of ETH into a target account on L2. +Note that if ETH is sent to a contract on L2 and the call fails, then that ETH will +be locked in the L2StandardBridge. ETH may be recoverable if the call can be +successfully replayed by increasing the amount of gas supplied to the call. If the +call will fail for any amount of gas, then the ETH will be locked permanently. + + +```solidity +function depositETHTo(address _to, uint32 _minGasLimit, bytes calldata _extraData) external payable; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`_to`|`address`| Address of the recipient on L2.| +|`_minGasLimit`|`uint32`|Minimum gas limit for the deposit message on L2.| +|`_extraData`|`bytes`| Optional data to forward to L2. Data supplied here will not be used to execute any code on L2 and is only emitted as extra data for the convenience of off-chain tooling.| + + diff --git a/docs/Rulebook/contracts/interfaces/IL2Bridge.sol/interface.IL2Bridge.md b/docs/Rulebook/contracts/interfaces/IL2Bridge.sol/interface.IL2Bridge.md new file mode 100644 index 0000000..406d6e9 --- /dev/null +++ b/docs/Rulebook/contracts/interfaces/IL2Bridge.sol/interface.IL2Bridge.md @@ -0,0 +1,32 @@ +# IL2Bridge +[Git Source](https://github.com/manifoldfinance/auctioneer/blob/94186b27ea5ddae3ff2f27674c7d42c6d498df0f/src/interfaces/IL2Bridge.sol) + + +## Functions +### withdrawTo + +Initiates a withdrawal from L2 to L1 to a target account on L1. +Note that if ETH is sent to a contract on L1 and the call fails, then that ETH will +be locked in the L1StandardBridge. ETH may be recoverable if the call can be +successfully replayed by increasing the amount of gas supplied to the call. If the +call will fail for any amount of gas, then the ETH will be locked permanently. +This function only works with OptimismMintableERC20 tokens or ether. Use the +`bridgeERC20To` function to bridge native L2 tokens to L1. + + +```solidity +function withdrawTo(address _l2Token, address _to, uint256 _amount, uint32 _minGasLimit, bytes calldata _extraData) + external + payable; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`_l2Token`|`address`| Address of the L2 token to withdraw.| +|`_to`|`address`| Recipient account on L1.| +|`_amount`|`uint256`| Amount of the L2 token to withdraw.| +|`_minGasLimit`|`uint32`|Minimum gas limit to use for the transaction.| +|`_extraData`|`bytes`| Extra data attached to the withdrawal.| + + diff --git a/docs/Rulebook/contracts/interfaces/IWETH.sol/interface.IWETH.md b/docs/Rulebook/contracts/interfaces/IWETH.sol/interface.IWETH.md new file mode 100644 index 0000000..7ccdb67 --- /dev/null +++ b/docs/Rulebook/contracts/interfaces/IWETH.sol/interface.IWETH.md @@ -0,0 +1,19 @@ +# IWETH +[Git Source](https://github.com/manifoldfinance/auctioneer/blob/94186b27ea5ddae3ff2f27674c7d42c6d498df0f/src/interfaces/IWETH.sol) + + +## Functions +### deposit + + +```solidity +function deposit() external payable; +``` + +### withdraw + + +```solidity +function withdraw(uint256 amount) external; +``` + diff --git a/docs/Rulebook/contracts/interfaces/README.md b/docs/Rulebook/contracts/interfaces/README.md new file mode 100644 index 0000000..aa9a153 --- /dev/null +++ b/docs/Rulebook/contracts/interfaces/README.md @@ -0,0 +1,7 @@ + + +# Contents +- [IERC6909](IERC6909.sol/interface.IERC6909.md) +- [IL1Bridge](IL1Bridge.sol/interface.IL1Bridge.md) +- [IL2Bridge](IL2Bridge.sol/interface.IL2Bridge.md) +- [IWETH](IWETH.sol/interface.IWETH.md) diff --git a/docs/Rulebook/contracts/solady.libsort.sol/library.LibSort.md b/docs/Rulebook/contracts/solady.libsort.sol/library.LibSort.md new file mode 100644 index 0000000..dfc9f6a --- /dev/null +++ b/docs/Rulebook/contracts/solady.libsort.sol/library.LibSort.md @@ -0,0 +1,387 @@ +# LibSort +[Git Source](https://github.com/manifoldfinance/auctioneer/blob/94186b27ea5ddae3ff2f27674c7d42c6d498df0f/src/solady.libsort.sol) + +**Author:** +Solady (https://github.com/vectorized/solady/blob/main/src/utils/Sort.sol) + +Optimized sorts and operations for sorted arrays. + + +## Functions +### insertionSort + +*Sorts the array in-place with insertion sort.* + + +```solidity +function insertionSort(uint256[] memory a) internal pure; +``` + +### insertionSort + +*Sorts the array in-place with insertion sort.* + + +```solidity +function insertionSort(int256[] memory a) internal pure; +``` + +### insertionSort + +*Sorts the array in-place with insertion sort.* + + +```solidity +function insertionSort(address[] memory a) internal pure; +``` + +### sort + +*Sorts the array in-place with intro-quicksort.* + + +```solidity +function sort(uint256[] memory a) internal pure; +``` + +### sort + +*Sorts the array in-place with intro-quicksort.* + + +```solidity +function sort(int256[] memory a) internal pure; +``` + +### sort + +*Sorts the array in-place with intro-quicksort.* + + +```solidity +function sort(address[] memory a) internal pure; +``` + +### uniquifySorted + +*Removes duplicate elements from a ascendingly sorted memory array.* + + +```solidity +function uniquifySorted(uint256[] memory a) internal pure; +``` + +### uniquifySorted + +*Removes duplicate elements from a ascendingly sorted memory array.* + + +```solidity +function uniquifySorted(int256[] memory a) internal pure; +``` + +### uniquifySorted + +*Removes duplicate elements from a ascendingly sorted memory array.* + + +```solidity +function uniquifySorted(address[] memory a) internal pure; +``` + +### searchSorted + +*Returns whether `a` contains `needle`, and the index of `needle`. +`index` precedence: equal to > nearest before > nearest after.* + + +```solidity +function searchSorted(uint256[] memory a, uint256 needle) internal pure returns (bool found, uint256 index); +``` + +### searchSorted + +*Returns whether `a` contains `needle`, and the index of `needle`. +`index` precedence: equal to > nearest before > nearest after.* + + +```solidity +function searchSorted(int256[] memory a, int256 needle) internal pure returns (bool found, uint256 index); +``` + +### searchSorted + +*Returns whether `a` contains `needle`, and the index of `needle`. +`index` precedence: equal to > nearest before > nearest after.* + + +```solidity +function searchSorted(address[] memory a, address needle) internal pure returns (bool found, uint256 index); +``` + +### reverse + +*Reverses the array in-place.* + + +```solidity +function reverse(uint256[] memory a) internal pure; +``` + +### reverse + +*Reverses the array in-place.* + + +```solidity +function reverse(int256[] memory a) internal pure; +``` + +### reverse + +*Reverses the array in-place.* + + +```solidity +function reverse(address[] memory a) internal pure; +``` + +### isSorted + +*Returns whether the array is sorted in ascending order.* + + +```solidity +function isSorted(uint256[] memory a) internal pure returns (bool result); +``` + +### isSorted + +*Returns whether the array is sorted in ascending order.* + + +```solidity +function isSorted(int256[] memory a) internal pure returns (bool result); +``` + +### isSorted + +*Returns whether the array is sorted in ascending order.* + + +```solidity +function isSorted(address[] memory a) internal pure returns (bool result); +``` + +### isSortedAndUniquified + +*Returns whether the array is strictly ascending (sorted and uniquified).* + + +```solidity +function isSortedAndUniquified(uint256[] memory a) internal pure returns (bool result); +``` + +### isSortedAndUniquified + +*Returns whether the array is strictly ascending (sorted and uniquified).* + + +```solidity +function isSortedAndUniquified(int256[] memory a) internal pure returns (bool result); +``` + +### isSortedAndUniquified + +*Returns whether the array is strictly ascending (sorted and uniquified).* + + +```solidity +function isSortedAndUniquified(address[] memory a) internal pure returns (bool result); +``` + +### difference + +*Returns the sorted set difference of `a` and `b`. +Note: Behaviour is undefined if inputs are not sorted and uniquified.* + + +```solidity +function difference(uint256[] memory a, uint256[] memory b) internal pure returns (uint256[] memory c); +``` + +### difference + +*Returns the sorted set difference between `a` and `b`. +Note: Behaviour is undefined if inputs are not sorted and uniquified.* + + +```solidity +function difference(int256[] memory a, int256[] memory b) internal pure returns (int256[] memory c); +``` + +### difference + +*Returns the sorted set difference between `a` and `b`. +Note: Behaviour is undefined if inputs are not sorted and uniquified.* + + +```solidity +function difference(address[] memory a, address[] memory b) internal pure returns (address[] memory c); +``` + +### intersection + +*Returns the sorted set intersection between `a` and `b`. +Note: Behaviour is undefined if inputs are not sorted and uniquified.* + + +```solidity +function intersection(uint256[] memory a, uint256[] memory b) internal pure returns (uint256[] memory c); +``` + +### intersection + +*Returns the sorted set intersection between `a` and `b`. +Note: Behaviour is undefined if inputs are not sorted and uniquified.* + + +```solidity +function intersection(int256[] memory a, int256[] memory b) internal pure returns (int256[] memory c); +``` + +### intersection + +*Returns the sorted set intersection between `a` and `b`. +Note: Behaviour is undefined if inputs are not sorted and uniquified.* + + +```solidity +function intersection(address[] memory a, address[] memory b) internal pure returns (address[] memory c); +``` + +### union + +*Returns the sorted set union of `a` and `b`. +Note: Behaviour is undefined if inputs are not sorted and uniquified.* + + +```solidity +function union(uint256[] memory a, uint256[] memory b) internal pure returns (uint256[] memory c); +``` + +### union + +*Returns the sorted set union of `a` and `b`. +Note: Behaviour is undefined if inputs are not sorted and uniquified.* + + +```solidity +function union(int256[] memory a, int256[] memory b) internal pure returns (int256[] memory c); +``` + +### union + +*Returns the sorted set union between `a` and `b`. +Note: Behaviour is undefined if inputs are not sorted and uniquified.* + + +```solidity +function union(address[] memory a, address[] memory b) internal pure returns (address[] memory c); +``` + +### _toUints + +*Reinterpret cast to an uint256 array.* + + +```solidity +function _toUints(int256[] memory a) private pure returns (uint256[] memory casted); +``` + +### _toUints + +*Reinterpret cast to an uint256 array.* + + +```solidity +function _toUints(address[] memory a) private pure returns (uint256[] memory casted); +``` + +### _toInts + +*Reinterpret cast to an int array.* + + +```solidity +function _toInts(uint256[] memory a) private pure returns (int256[] memory casted); +``` + +### _toAddresses + +*Reinterpret cast to an address array.* + + +```solidity +function _toAddresses(uint256[] memory a) private pure returns (address[] memory casted); +``` + +### _flipSign + +*Converts an array of signed integers to unsigned +integers suitable for sorting or vice versa.* + + +```solidity +function _flipSign(int256[] memory a) private pure; +``` + +### _searchSorted + +*Returns whether `a` contains `needle`, and the index of `needle`. +`index` precedence: equal to > nearest before > nearest after.* + + +```solidity +function _searchSorted(uint256[] memory a, uint256 needle, uint256 signed) + private + pure + returns (bool found, uint256 index); +``` + +### _difference + +*Returns the sorted set difference of `a` and `b`. +Note: Behaviour is undefined if inputs are not sorted and uniquified.* + + +```solidity +function _difference(uint256[] memory a, uint256[] memory b, uint256 signed) + private + pure + returns (uint256[] memory c); +``` + +### _intersection + +*Returns the sorted set intersection between `a` and `b`. +Note: Behaviour is undefined if inputs are not sorted and uniquified.* + + +```solidity +function _intersection(uint256[] memory a, uint256[] memory b, uint256 signed) + private + pure + returns (uint256[] memory c); +``` + +### _union + +*Returns the sorted set union of `a` and `b`. +Note: Behaviour is undefined if inputs are not sorted and uniquified.* + + +```solidity +function _union(uint256[] memory a, uint256[] memory b, uint256 signed) private pure returns (uint256[] memory c); +``` +