Skip to content

Commit

Permalink
add unit notation
Browse files Browse the repository at this point in the history
  • Loading branch information
jankjr committed Jan 9, 2024
1 parent 85948a0 commit 69c1bc9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
3 changes: 2 additions & 1 deletion contracts/plugins/trading/DutchTrade.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ interface IDutchTradeCallee {
function dutchTradeCallback(
address caller,
address buyToken,
// {qBuyTok}
uint256 buyAmount,
bytes calldata data
) external;
Expand Down Expand Up @@ -219,7 +220,7 @@ contract DutchTrade is ITrade {
broker.reportViolation();
}
sell.safeTransfer(bidder, lot()); // {qSellTok}
uint256 balanceBefore = buy.balanceOf(address(this));
uint256 balanceBefore = buy.balanceOf(address(this)); // {qBuyTok}
IDutchTradeCallee(bidder).dutchTradeCallback(bidder, address(buy), amountIn, data);
require(
amountIn <= buy.balanceOf(address(this)) - balanceBefore,
Expand Down
16 changes: 8 additions & 8 deletions contracts/plugins/trading/DutchTradeRouter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ contract DutchTradeRouter is IDutchTradeCallee {
IERC20 sellToken;
/// @notice The amount of tokenIn the protocol got {qSellAmt}
uint256 sellAmt;
/// @notice The token bought from the trade
/// @notice The token bought from the trade
IERC20 buyToken;
/// @notice The amount of tokenOut the we got {qBuyAmt}
uint256 buyAmt;
Expand All @@ -26,9 +26,9 @@ contract DutchTradeRouter is IDutchTradeCallee {
/// @param trade The DutchTrade that was bid on
/// @param bidder The address of the bidder
/// @param sellToken The token being sold by the protocol
/// @param soldAmt The amount of sellToken sold
/// @param soldAmt The amount of sellToken sold {qSellToken}
/// @param buyToken The token being bought by the protocol
/// @param boughtAmt The amount of buyToken bought
/// @param boughtAmt The amount of buyToken bought {qBuyToken}
event BidPlaced(
IMain main,
DutchTrade trade,
Expand All @@ -55,7 +55,7 @@ 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
/// @param buyAmount The amt the DutchTrade is expecting to receive {qBuyToken}
/// @notice Data is not used here
function dutchTradeCallback(
address caller,
Expand All @@ -65,7 +65,7 @@ contract DutchTradeRouter is IDutchTradeCallee {
) external {
require(caller == address(this), "Invalid caller");
require(msg.sender == address(_currentTrade), "Incorrect callee");
IERC20(buyToken).safeTransfer(msg.sender, buyAmount);
IERC20(buyToken).safeTransfer(msg.sender, buyAmount); // {qBuyToken}
}

function _sendBalanceTo(IERC20 token, address to) internal {
Expand All @@ -88,14 +88,14 @@ contract DutchTradeRouter is IDutchTradeCallee {
out.buyAmt = trade.bidAmount(block.number); // {qBuyToken}
out.buyToken.safeTransferFrom(bidder, address(this), out.buyAmt);

uint256 sellAmt = out.sellToken.balanceOf(address(this)); // {qSellToken}
uint256 sellAmt = out.sellToken.balanceOf(address(this)); // {qSellToken}

uint256 expectedSellAmt = trade.lot(); // {qSellToken}
trade.bid(new bytes(0));

sellAmt = out.sellToken.balanceOf(address(this)) - sellAmt; // {qSellToken}
sellAmt = out.sellToken.balanceOf(address(this)) - sellAmt; // {qSellToken}
require(sellAmt >= expectedSellAmt, "insufficient amount out");
out.sellAmt = sellAmt; // {qSellToken}
out.sellAmt = sellAmt; // {qSellToken}

_currentTrade = DutchTrade(address(0));
emit BidPlaced(
Expand Down

0 comments on commit 69c1bc9

Please sign in to comment.