From 5cf82e1179ea7178a9d6aed0dfdfe0ee094518d7 Mon Sep 17 00:00:00 2001 From: Jan <mig@jankjr.dk> Date: Tue, 9 Jan 2024 12:09:51 +0100 Subject: [PATCH] add documentation for Router and update the MEV section in the docs to reflect new design --- contracts/plugins/trading/DutchTrade.sol | 7 ++++--- contracts/plugins/trading/DutchTradeRouter.sol | 8 +++++--- docs/mev.md | 4 +++- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/contracts/plugins/trading/DutchTrade.sol b/contracts/plugins/trading/DutchTrade.sol index 8d37c21ebb..9cb98f7bfb 100644 --- a/contracts/plugins/trading/DutchTrade.sol +++ b/contracts/plugins/trading/DutchTrade.sol @@ -11,7 +11,6 @@ import "../../interfaces/ITrade.sol"; interface IDutchTradeCallee { function dutchTradeCallback( - address caller, address buyToken, // {qBuyTok} uint256 buyAmount, @@ -209,7 +208,7 @@ contract DutchTrade is ITrade { // {qBuyTok} amountIn = _bidAmount(price); - // Transfer in buy tokens + // Mark bidder bidder = msg.sender; // status must begin OPEN @@ -219,9 +218,11 @@ contract DutchTrade is ITrade { if (price > bestPrice.mul(ONE_POINT_FIVE, CEIL)) { broker.reportViolation(); } + + // Transfer buy tokens from bidder sell.safeTransfer(bidder, lot()); // {qSellTok} uint256 balanceBefore = buy.balanceOf(address(this)); // {qBuyTok} - IDutchTradeCallee(bidder).dutchTradeCallback(bidder, address(buy), amountIn, data); + IDutchTradeCallee(bidder).dutchTradeCallback(address(buy), amountIn, data); require( amountIn <= buy.balanceOf(address(this)) - balanceBefore, "insufficient buy tokens" diff --git a/contracts/plugins/trading/DutchTradeRouter.sol b/contracts/plugins/trading/DutchTradeRouter.sol index f39d356329..0125394214 100644 --- a/contracts/plugins/trading/DutchTradeRouter.sol +++ b/contracts/plugins/trading/DutchTradeRouter.sol @@ -6,6 +6,11 @@ import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import { IDutchTradeCallee, TradeStatus, DutchTrade } from "../trading/DutchTrade.sol"; import { IMain } from "../../interfaces/IMain.sol"; +/** @title DutchTradeRouter + * @notice Utility contract for placing bids on DutchTrade auctions + * @dev This contract is needed as end user wallets cannot call DutchTrade.bid directly anymore, + tests and UI need to be updated to use this contract + */ contract DutchTradeRouter is IDutchTradeCallee { using SafeERC20 for IERC20; struct Bid { @@ -53,17 +58,14 @@ contract DutchTradeRouter is IDutchTradeCallee { } /// @notice Callback for DutchTrade - /// @param caller The caller of the callback, should be the router /// @param buyToken The token DutchTrade is expecting to receive /// @param buyAmount The amt the DutchTrade is expecting to receive {qBuyToken} /// @notice Data is not used here function dutchTradeCallback( - address caller, address buyToken, uint256 buyAmount, bytes calldata ) external { - require(caller == address(this), "Invalid caller"); require(msg.sender == address(_currentTrade), "Incorrect callee"); IERC20(buyToken).safeTransfer(msg.sender, buyAmount); // {qBuyToken} } diff --git a/docs/mev.md b/docs/mev.md index f0579c8c3b..f2703581da 100644 --- a/docs/mev.md +++ b/docs/mev.md @@ -27,7 +27,7 @@ Bidding instructions from the `DutchTrade` contract: `DutchTrade` (relevant) interface: ```solidity -function bid() external; // execute a bid at the current block number +function bid(bytes memory data) external; // execute a bid at the current block number function sell() external view returns (IERC20); @@ -43,6 +43,8 @@ function bidAmount(uint256 blockNumber) external view returns (uint256); // {qBu To participate: +Make sure calling contract implements the `IDutchTradeCallee` interface. It contains a single method function `dutchTradeCallbac(address buyToken,uint256 buyAmount,bytes calldata data) external;`. This method will be called by the `DutchTrade` as a callback after calling `bid` and before the trade has been resolved. The trader is expected to pay for the trade during the callback. See `DutchTradeRouter.sol` for an example. + 1. Call `status()` view; the auction is ongoing if return value is 1 2. Call `lot()` to see the number of tokens being sold 3. Call `bidAmount()` to see the number of tokens required to buy the lot, at various block numbers