-
Notifications
You must be signed in to change notification settings - Fork 467
Conversation
10cf655
to
287a83b
Compare
f7e260a
to
06d80cc
Compare
cee5bd0
to
ea4b21f
Compare
IExchange internal EXCHANGE; | ||
|
||
struct AuctionDetails { | ||
uint256 beginTimeSeconds; // Auction begin time in seconds: sellOrder.makerAssetData |
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.
Nit - specify these are unix timestamps.
const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper); | ||
const DECIMALS_DEFAULT = 18; | ||
|
||
describe.only(ContractName.DutchAuction, () => { |
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.
Note to nix the only
before merge.
let buyerOrderFactory: OrderFactory; | ||
let erc20Wrapper: ERC20Wrapper; | ||
let erc20Balances: ERC20BalancesByOwner; | ||
let tenMinutesInSeconds: number; |
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.
Nit - some of these could be const
like const tenMinutesInSeconds = 10 * 60
expect(auctionDetails.beginAmount).to.be.bignumber.equal(auctionBeginAmount); | ||
}); | ||
it('should be be worth the end price at the end of the auction', async () => { | ||
auctionBeginTimeSeconds = new BigNumber(currentBlockTimestamp - 1000); |
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.
Nit - could be good to set 1000
and 100
to variables for clarity.
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.
I'll re-use tenMinutesInSeconds
uint256 buyerExcessAmount = buyOrder.makerAssetAmount-auctionDetails.currentAmount; | ||
uint256 sellerExcessAmount = leftMakerAssetSpreadAmount-buyerExcessAmount; | ||
bytes memory assetData = sellOrder.takerAssetData; | ||
address token = assetData.readAddress(16); |
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.
Nit - include an offset table for reference. Example.
uint256 leftMakerAssetSpreadAmount = matchedFillResults.leftMakerAssetSpreadAmount; | ||
if (leftMakerAssetSpreadAmount > 0) { | ||
// Calculate the excess from the buy order. This can occur if the buyer sends in a higher | ||
// amount than the calculated current amount |
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.
Should probably use safeMath
here or include a comment about why it's definitely not needed.
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.
Agreed with all of the SafeMath comments.
returns (AuctionDetails memory auctionDetails) | ||
{ | ||
uint256 makerAssetDataLength = order.makerAssetData.length; | ||
// We assume auctionBeginTimeSeconds and auctionBeginAmount are appended to the makerAssetData |
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.
Same note as above - should include an offset table for reference. Example.
Could probably just include this once in here then reference it above.
// We assume auctionBeginTimeSeconds and auctionBeginAmount are appended to the makerAssetData | ||
uint256 auctionBeginTimeSeconds = order.makerAssetData.readUint256(makerAssetDataLength-64); | ||
uint256 auctionBeginAmount = order.makerAssetData.readUint256(makerAssetDataLength-32); | ||
require(order.expirationTimeSeconds > auctionBeginTimeSeconds, "INVALID_BEGIN_TIME"); |
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.
Same note about safeMath
in this function.
EXCHANGE = IExchange(_exchange); | ||
} | ||
|
||
/// @dev Matches the buy and sell orders at an amount given the following: the current block time, the auction |
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.
Nice
06dab7c
to
630aa70
Compare
{ | ||
AuctionDetails memory auctionDetails = getAuctionDetails(sellOrder); | ||
// Ensure the auction has not yet started | ||
require(auctionDetails.currentTimeSeconds >= auctionDetails.beginTimeSeconds, "AUCTION_NOT_STARTED"); |
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.
Let's put the revert reasons on a newline.
buySignature, | ||
sellSignature | ||
); | ||
// Return any spread to the seller |
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.
This comment is outdated.
uint256 leftMakerAssetSpreadAmount = matchedFillResults.leftMakerAssetSpreadAmount; | ||
if (leftMakerAssetSpreadAmount > 0) { | ||
// Calculate the excess from the buy order. This can occur if the buyer sends in a higher | ||
// amount than the calculated current amount |
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.
Agreed with all of the SafeMath comments.
bytes memory assetData = sellOrder.takerAssetData; | ||
address token = assetData.readAddress(16); | ||
if (sellerExcessAmount > 0) { | ||
address makerAddress = sellOrder.makerAddress; |
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.
We probably don't need to declare makerAddress
here since it isn't being reused.
IERC20Token(token).transfer(makerAddress, sellerExcessAmount); | ||
} | ||
if (buyerExcessAmount > 0) { | ||
address takerAddress = buyOrder.makerAddress; |
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.
Same as above.
// | | -32 | 32 | 2. auction begin begin amount | | ||
// ERC20 asset data length is 4+32, 64 for auction details results in min length if 100 | ||
require(makerAssetDataLength > 10, "INVALID_ASSET_DATA"); | ||
uint256 auctionBeginTimeSeconds = order.makerAssetData.readUint256(makerAssetDataLength-64); |
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.
Spaces before/after operators please :) makerAssetDataLength - 64
521e9c1
to
0d814ee
Compare
420f71c
to
271a07a
Compare
e9b30fe
to
bb4b516
Compare
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.
LGTM after fixing merge conflicts.
auctionDetails.currentTimeSeconds = timestamp; | ||
|
||
uint256 remainingDurationSeconds = order.expirationTimeSeconds-timestamp; | ||
uint256 currentAmount = minAmount + (remainingDurationSeconds*amountDelta/auctionDurationSeconds); |
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.
Nit: add spaces in between arithmetic operators
61aa012
to
907b00d
Compare
907b00d
to
247266b
Compare
Description
Quip doc here for further details.
A simple
matchOrders
in a extension contract that validates the correct amount given the current block timestamp.sellOrder
is the smallest possible amount for the asset up for sale. That is thesellOrder.takerAssetAmount
is the final amount at the end of the auction. The contract guarantees the incoming buyOrder is for an greater than or equal to the calculatedcurrentAmount
. ThecurrentAmount
is calculated from theauctionBeginTimeSeconds
,auctionBeginAmount
,sellOrder.takerAssetAmount
akaauctionEndAmount
andsellOrder.expiryTimeSeconds
akaauctionEndTimeSeconds
. currentAmount travels linearly downwards from theauctionBeginAmount
to theauctionEndAmount
.Match Orders guarantees the seller gets the minimum reserve amount (
sellOrder.takerAssetAmount
). When matched the delta betweencurrentAmount
andsellOrder.takerAssetAmount
is transferred to the seller. Any further excess is returned to the buyer (the delta betweenbuyOrder.makerAssetAmount
andcurrentAmount
. This means the buyer can send in any amount safely and be assured they will get the exact price given the current block timestamp.Testing instructions
Types of changes
Checklist:
[WIP]
if necessary.[sol-cov] Fixed bug
.