aboutsummaryrefslogtreecommitdiffstats
path: root/packages
diff options
context:
space:
mode:
authorJacob Evans <jacob@dekz.net>2018-12-04 06:10:59 +0800
committerJacob Evans <jacob@dekz.net>2018-12-04 06:14:00 +0800
commit247266b969d5439abc372ede77a68b937809a6ab (patch)
tree553ecd9bcf1878dce24a8b674a78b06dc16866c1 /packages
parent0bffc3d10e5b7c55fabfd4f0e5dcceefe468aa5f (diff)
downloaddexon-sol-tools-247266b969d5439abc372ede77a68b937809a6ab.tar
dexon-sol-tools-247266b969d5439abc372ede77a68b937809a6ab.tar.gz
dexon-sol-tools-247266b969d5439abc372ede77a68b937809a6ab.tar.bz2
dexon-sol-tools-247266b969d5439abc372ede77a68b937809a6ab.tar.lz
dexon-sol-tools-247266b969d5439abc372ede77a68b937809a6ab.tar.xz
dexon-sol-tools-247266b969d5439abc372ede77a68b937809a6ab.tar.zst
dexon-sol-tools-247266b969d5439abc372ede77a68b937809a6ab.zip
chore: SafeMath and if statement in getAuctionDetails
Diffstat (limited to 'packages')
-rw-r--r--packages/contracts/contracts/extensions/DutchAuction/DutchAuction.sol28
1 files changed, 18 insertions, 10 deletions
diff --git a/packages/contracts/contracts/extensions/DutchAuction/DutchAuction.sol b/packages/contracts/contracts/extensions/DutchAuction/DutchAuction.sol
index 9b8fec54a..abe8309cf 100644
--- a/packages/contracts/contracts/extensions/DutchAuction/DutchAuction.sol
+++ b/packages/contracts/contracts/extensions/DutchAuction/DutchAuction.sol
@@ -114,7 +114,8 @@ contract DutchAuction is
// |----------|--------|---------|-------------------------------------|
// | Header | 0 | 4 | function selector |
// | Params | | 1 * 32 | function parameters: |
- // | | 4 | 12 + 20 | 1. token address |
+ // | | 4 | 12 | 1. token address padding |
+ // | | 16 | 20 | 2. token address |
bytes memory assetData = sellOrder.takerAssetData;
address token = assetData.readAddress(16);
// Calculate the excess from the buy order. This can occur if the buyer sends in a higher
@@ -183,15 +184,22 @@ contract DutchAuction is
auctionDetails.currentTimeSeconds = timestamp;
uint256 remainingDurationSeconds = order.expirationTimeSeconds-timestamp;
- uint256 currentAmount = minAmount + (remainingDurationSeconds*amountDelta/auctionDurationSeconds);
- // Check the bounds where we SafeMath was avoivded so the auction details can be queried prior
- // and after the auction time.
- // If the auction has not yet begun the current amount is the auctionBeginAmount
- currentAmount = timestamp < auctionBeginTimeSeconds ? auctionBeginAmount : currentAmount;
- // If the auction has ended the current amount is the minAmount
- // auction end time is guaranteed by 0x Exchange to fail due to the order expiration
- currentAmount = timestamp >= order.expirationTimeSeconds ? minAmount : currentAmount;
- auctionDetails.currentAmount = currentAmount;
+ if (timestamp < auctionBeginTimeSeconds) {
+ // If the auction has not yet begun the current amount is the auctionBeginAmount
+ auctionDetails.currentAmount = auctionBeginAmount;
+ } else if (timestamp >= order.expirationTimeSeconds) {
+ // If the auction has ended the current amount is the minAmount.
+ // Auction end time is guaranteed by 0x Exchange due to the order expiration
+ auctionDetails.currentAmount = minAmount;
+ } else {
+ auctionDetails.currentAmount = safeAdd(
+ minAmount,
+ safeDiv(
+ safeMul(remainingDurationSeconds, amountDelta),
+ auctionDurationSeconds
+ )
+ );
+ }
return auctionDetails;
}
}