aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJacob Evans <jacob@dekz.net>2018-11-21 13:04:13 +0800
committerJacob Evans <jacob@dekz.net>2018-12-04 06:13:58 +0800
commitcb8601676d70ba648683f8c7df1eca25d670d663 (patch)
treea3baab0f09d7f515d1c44c1cec5dcebb2f035681
parent98d9a9c6482e2170192f66350448703d2801d122 (diff)
downloaddexon-sol-tools-cb8601676d70ba648683f8c7df1eca25d670d663.tar
dexon-sol-tools-cb8601676d70ba648683f8c7df1eca25d670d663.tar.gz
dexon-sol-tools-cb8601676d70ba648683f8c7df1eca25d670d663.tar.bz2
dexon-sol-tools-cb8601676d70ba648683f8c7df1eca25d670d663.tar.lz
dexon-sol-tools-cb8601676d70ba648683f8c7df1eca25d670d663.tar.xz
dexon-sol-tools-cb8601676d70ba648683f8c7df1eca25d670d663.tar.zst
dexon-sol-tools-cb8601676d70ba648683f8c7df1eca25d670d663.zip
chore: Rename price to amount. Encode parameters in makerAssetData
-rw-r--r--packages/contracts/contracts/extensions/DutchAuction/DutchAuction.sol100
-rw-r--r--packages/contracts/test/extensions/dutch_auction.ts183
2 files changed, 149 insertions, 134 deletions
diff --git a/packages/contracts/contracts/extensions/DutchAuction/DutchAuction.sol b/packages/contracts/contracts/extensions/DutchAuction/DutchAuction.sol
index bb75fc188..a304184f1 100644
--- a/packages/contracts/contracts/extensions/DutchAuction/DutchAuction.sol
+++ b/packages/contracts/contracts/extensions/DutchAuction/DutchAuction.sol
@@ -32,12 +32,12 @@ contract DutchAuction {
IExchange internal EXCHANGE;
struct AuctionDetails {
- uint256 beginTime; // Auction begin time in seconds
- uint256 endTime; // Auction end time in seconds
- uint256 beginPrice; // Auction begin price
- uint256 endPrice; // Auction end price
- uint256 currentPrice; // Current auction price at block.timestamp
- uint256 currentTime; // block.timestamp
+ uint256 beginTimeSeconds; // Auction begin time in seconds
+ uint256 endTimeSeconds; // Auction end time in seconds
+ uint256 beginAmount; // Auction begin amount
+ uint256 endAmount; // Auction end amount
+ uint256 currentAmount; // Current auction amount at block.timestamp
+ uint256 currentTimeSeconds; // block.timestamp
}
constructor (address _exchange)
@@ -46,35 +46,15 @@ contract DutchAuction {
EXCHANGE = IExchange(_exchange);
}
- /// @dev Packs the begin time and price parameters of an auction into uint256.
- /// This is stored as the salt value of the sale order.
- /// @param beginTime Begin time of the auction (32 bits)
- /// @param beginPrice Starting price of the auction (224 bits)
- /// @return Encoded Auction Parameters packed into a uint256
- function encodeParameters(
- uint256 beginTime,
- uint256 beginPrice
- )
- external
- view
- returns (uint256 encodedParameters)
- {
- require(beginTime <= 2**32, "INVALID_BEGIN_TIME");
- require(beginPrice <= 2**224, "INVALID_BEGIN_PRICE");
- encodedParameters = beginTime;
- encodedParameters |= beginPrice<<32;
- return encodedParameters;
- }
-
- /// @dev Performs a match of the two orders at the price point given the current block time and the auction
- /// start time (encoded in the salt).
- /// The Sellers order is a signed order at the lowest price at the end of the auction. Excess from the match
+ /// @dev Performs a match of the two orders at the amount given: the current block time, the auction
+ /// start time and the auction begin amount.
+ /// The Sellers order is a signed order at the lowest amount at the end of the auction. Excess from the match
/// is transferred to the seller.
/// @param buyOrder The Buyer's order
/// @param sellOrder The Seller's order
/// @param buySignature Proof that order was created by the left maker.
/// @param sellSignature Proof that order was created by the right maker.
- /// @return matchedFillResults Amounts filled and fees paid by maker and taker of matched orders.
+ /// @return matchedFillResults amounts filled and fees paid by maker and taker of matched orders.
function matchOrders(
LibOrder.Order memory buyOrder,
LibOrder.Order memory sellOrder,
@@ -86,13 +66,13 @@ contract DutchAuction {
{
AuctionDetails memory auctionDetails = getAuctionDetails(sellOrder);
// Ensure the auction has not yet started
- require(auctionDetails.currentTime >= auctionDetails.beginTime, "AUCTION_NOT_STARTED");
+ require(auctionDetails.currentTimeSeconds >= auctionDetails.beginTimeSeconds, "AUCTION_NOT_STARTED");
// Ensure the auction has not expired. This will fail later in 0x but we can save gas by failing early
- require(sellOrder.expirationTimeSeconds > auctionDetails.currentTime, "AUCTION_EXPIRED");
+ require(sellOrder.expirationTimeSeconds > auctionDetails.currentTimeSeconds, "AUCTION_EXPIRED");
// Ensure the auction goes from high to low
- require(auctionDetails.beginPrice > auctionDetails.endPrice, "INVALID_PRICE");
- // Validate the buyer amount is greater than the current auction price
- require(buyOrder.makerAssetAmount >= auctionDetails.currentPrice, "INVALID_PRICE");
+ require(auctionDetails.beginAmount > auctionDetails.endAmount, "INVALID_AMOUNT");
+ // Validate the buyer amount is greater than the current auction amount
+ require(buyOrder.makerAssetAmount >= auctionDetails.currentAmount, "INVALID_AMOUNT");
// Match orders, maximally filling `buyOrder`
matchedFillResults = EXCHANGE.matchOrders(
buyOrder,
@@ -103,6 +83,7 @@ contract DutchAuction {
// Return any spread to the seller
uint256 leftMakerAssetSpreadAmount = matchedFillResults.leftMakerAssetSpreadAmount;
if (leftMakerAssetSpreadAmount > 0) {
+ // Assume auction is for ERC20
bytes memory assetData = sellOrder.takerAssetData;
address token = assetData.readAddress(16);
address makerAddress = sellOrder.makerAddress;
@@ -111,21 +92,6 @@ contract DutchAuction {
return matchedFillResults;
}
- /// @dev Decodes the packed parameters into beginTime and beginPrice.
- /// @param encodedParameters the encoded parameters
- /// @return beginTime and beginPrice decoded
- function decodeParameters(
- uint256 encodedParameters
- )
- public
- view
- returns (uint256 beginTime, uint256 beginPrice)
- {
- beginTime = encodedParameters & 0x00000000000000000000000fffffffff;
- beginPrice = encodedParameters>>32;
- return (beginTime, beginPrice);
- }
-
/// @dev Calculates the Auction Details for the given order
/// @param order The sell order
/// @return AuctionDetails
@@ -135,28 +101,30 @@ contract DutchAuction {
public
returns (AuctionDetails memory auctionDetails)
{
- // solhint-disable-next-line indent
- (uint256 auctionBeginTimeSeconds, uint256 auctionBeginPrice) = decodeParameters(order.salt);
- require(order.expirationTimeSeconds > auctionBeginTimeSeconds, "INVALID_BEGIN_TIME");
+ uint256 makerAssetDataLength = order.makerAssetData.length;
+ // 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");
uint256 auctionDurationSeconds = order.expirationTimeSeconds-auctionBeginTimeSeconds;
- uint256 minPrice = order.takerAssetAmount;
+ uint256 minAmount = order.takerAssetAmount;
// solhint-disable-next-line not-rely-on-time
uint256 timestamp = block.timestamp;
- auctionDetails.beginTime = auctionBeginTimeSeconds;
- auctionDetails.endTime = order.expirationTimeSeconds;
- auctionDetails.beginPrice = auctionBeginPrice;
- auctionDetails.endPrice = minPrice;
- auctionDetails.currentTime = timestamp;
+ auctionDetails.beginTimeSeconds = auctionBeginTimeSeconds;
+ auctionDetails.endTimeSeconds = order.expirationTimeSeconds;
+ auctionDetails.beginAmount = auctionBeginAmount;
+ auctionDetails.endAmount = minAmount;
+ auctionDetails.currentTimeSeconds = timestamp;
uint256 remainingDurationSeconds = order.expirationTimeSeconds-timestamp;
- uint256 priceDelta = auctionBeginPrice-minPrice;
- uint256 currentPrice = minPrice + (remainingDurationSeconds*priceDelta/auctionDurationSeconds);
- // If the auction has not yet begun the current price is the auctionBeginPrice
- currentPrice = timestamp < auctionBeginTimeSeconds ? auctionBeginPrice : currentPrice;
- // If the auction has ended the current price is the minPrice
+ uint256 amountDelta = auctionBeginAmount-minAmount;
+ uint256 currentAmount = minAmount + (remainingDurationSeconds*amountDelta/auctionDurationSeconds);
+ // 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
- currentPrice = timestamp >= order.expirationTimeSeconds ? minPrice : currentPrice;
- auctionDetails.currentPrice = currentPrice;
+ currentAmount = timestamp >= order.expirationTimeSeconds ? minAmount : currentAmount;
+ auctionDetails.currentAmount = currentAmount;
return auctionDetails;
}
}
diff --git a/packages/contracts/test/extensions/dutch_auction.ts b/packages/contracts/test/extensions/dutch_auction.ts
index 6a1e3ed45..4ad5cfa19 100644
--- a/packages/contracts/test/extensions/dutch_auction.ts
+++ b/packages/contracts/test/extensions/dutch_auction.ts
@@ -1,9 +1,11 @@
import { BlockchainLifecycle } from '@0x/dev-utils';
-import { assetDataUtils } from '@0x/order-utils';
+import { assetDataUtils, generatePseudoRandomSalt } from '@0x/order-utils';
import { SignedOrder } from '@0x/types';
import { BigNumber } from '@0x/utils';
import { Web3Wrapper } from '@0x/web3-wrapper';
import * as chai from 'chai';
+import ethAbi = require('ethereumjs-abi');
+import * as ethUtil from 'ethereumjs-util';
import { DummyERC20TokenContract } from '../../generated-wrappers/dummy_erc20_token';
import { DummyERC721TokenContract } from '../../generated-wrappers/dummy_erc721_token';
@@ -26,6 +28,7 @@ chaiSetup.configure();
const expect = chai.expect;
const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);
const DECIMALS_DEFAULT = 18;
+const ZERO = Web3Wrapper.toBaseUnitAmount(new BigNumber(0), DECIMALS_DEFAULT);
describe.only(ContractName.DutchAuction, () => {
let makerAddress: string;
@@ -34,13 +37,11 @@ describe.only(ContractName.DutchAuction, () => {
let feeRecipientAddress: string;
let defaultMakerAssetAddress: string;
- let weth: DummyERC20TokenContract;
let zrxToken: DummyERC20TokenContract;
let erc20TokenA: DummyERC20TokenContract;
let erc721Token: DummyERC721TokenContract;
let dutchAuctionContract: DutchAuctionContract;
let wethContract: WETH9Contract;
- let exchangeWrapper: ExchangeWrapper;
let sellerOrderFactory: OrderFactory;
let buyerOrderFactory: OrderFactory;
@@ -48,11 +49,10 @@ describe.only(ContractName.DutchAuction, () => {
let erc20Balances: ERC20BalancesByOwner;
let tenMinutesInSeconds: number;
let currentBlockTimestamp: number;
- let auctionBeginTime: BigNumber;
- let auctionEndTime: BigNumber;
- let auctionBeginPrice: BigNumber;
- let auctionEndPrice: BigNumber;
- let encodedParams: BigNumber;
+ let auctionBeginTimeSeconds: BigNumber;
+ let auctionEndTimeSeconds: BigNumber;
+ let auctionBeginAmount: BigNumber;
+ let auctionEndAmount: BigNumber;
let sellOrder: SignedOrder;
let buyOrder: SignedOrder;
let erc721MakerAssetIds: BigNumber[];
@@ -60,7 +60,7 @@ describe.only(ContractName.DutchAuction, () => {
const timestampBefore = await getLatestBlockTimestampAsync();
await web3Wrapper.increaseTimeAsync(5);
const timestampAfter = await getLatestBlockTimestampAsync();
- // HACK send some transactions
+ // HACK send some transactions when a time increase isn't supported
if (timestampAfter === timestampBefore) {
await web3Wrapper.sendTransactionAsync({ to: makerAddress, from: makerAddress, value: new BigNumber(1) });
await web3Wrapper.sendTransactionAsync({ to: makerAddress, from: makerAddress, value: new BigNumber(1) });
@@ -70,6 +70,20 @@ describe.only(ContractName.DutchAuction, () => {
}
}
+ function extendMakerAssetData(makerAssetData: string, beginTimeSeconds: BigNumber, beginAmount: BigNumber): string {
+ return ethUtil.bufferToHex(
+ Buffer.concat([
+ ethUtil.toBuffer(makerAssetData),
+ ethUtil.toBuffer(
+ (ethAbi as any).rawEncode(
+ ['uint256', 'uint256'],
+ [beginTimeSeconds.toString(), beginAmount.toString()],
+ ),
+ ),
+ ]),
+ );
+ }
+
before(async () => {
await blockchainLifecycle.startAsync();
const accounts = await web3Wrapper.getAvailableAddressesAsync();
@@ -93,8 +107,7 @@ describe.only(ContractName.DutchAuction, () => {
erc721MakerAssetIds = erc721Balances[makerAddress][erc721Token.address];
wethContract = await WETH9Contract.deployFrom0xArtifactAsync(artifacts.WETH9, provider, txDefaults);
- weth = new DummyERC20TokenContract(wethContract.abi, wethContract.address, provider);
- erc20Wrapper.addDummyTokenContract(weth);
+ erc20Wrapper.addDummyTokenContract(wethContract as any);
const zrxAssetData = assetDataUtils.encodeERC20AssetData(zrxToken.address);
const exchangeInstance = await ExchangeContract.deployFrom0xArtifactAsync(
@@ -103,9 +116,8 @@ describe.only(ContractName.DutchAuction, () => {
txDefaults,
zrxAssetData,
);
- exchangeWrapper = new ExchangeWrapper(exchangeInstance, provider);
+ const exchangeWrapper = new ExchangeWrapper(exchangeInstance, provider);
await exchangeWrapper.registerAssetProxyAsync(erc20Proxy.address, owner);
-
await exchangeWrapper.registerAssetProxyAsync(erc721Proxy.address, owner);
await erc20Proxy.addAuthorizedAddress.sendTransactionAsync(exchangeInstance.address, {
@@ -151,28 +163,30 @@ describe.only(ContractName.DutchAuction, () => {
tenMinutesInSeconds = 10 * 60;
currentBlockTimestamp = await getLatestBlockTimestampAsync();
// Default auction begins 10 minutes ago
- auctionBeginTime = new BigNumber(currentBlockTimestamp).minus(tenMinutesInSeconds);
+ auctionBeginTimeSeconds = new BigNumber(currentBlockTimestamp).minus(tenMinutesInSeconds);
// Default auction ends 10 from now
- auctionEndTime = new BigNumber(currentBlockTimestamp).plus(tenMinutesInSeconds);
- auctionBeginPrice = Web3Wrapper.toBaseUnitAmount(new BigNumber(10), DECIMALS_DEFAULT);
- auctionEndPrice = Web3Wrapper.toBaseUnitAmount(new BigNumber(1), DECIMALS_DEFAULT);
- encodedParams = await dutchAuctionContract.encodeParameters.callAsync(auctionBeginTime, auctionBeginPrice);
- const zero = Web3Wrapper.toBaseUnitAmount(new BigNumber(0), DECIMALS_DEFAULT);
+ auctionEndTimeSeconds = new BigNumber(currentBlockTimestamp).plus(tenMinutesInSeconds);
+ auctionBeginAmount = Web3Wrapper.toBaseUnitAmount(new BigNumber(10), DECIMALS_DEFAULT);
+ auctionEndAmount = Web3Wrapper.toBaseUnitAmount(new BigNumber(1), DECIMALS_DEFAULT);
// Default sell order and buy order are exact mirrors
const sellerDefaultOrderParams = {
- salt: encodedParams, // Set the encoded params as the salt for the seller order
+ salt: generatePseudoRandomSalt(),
exchangeAddress: exchangeInstance.address,
makerAddress,
feeRecipientAddress,
senderAddress: dutchAuctionContract.address,
- makerAssetData: assetDataUtils.encodeERC20AssetData(defaultMakerAssetAddress),
+ makerAssetData: extendMakerAssetData(
+ assetDataUtils.encodeERC20AssetData(defaultMakerAssetAddress),
+ auctionBeginTimeSeconds,
+ auctionBeginAmount,
+ ),
takerAssetData: assetDataUtils.encodeERC20AssetData(defaultTakerAssetAddress),
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(200), DECIMALS_DEFAULT),
- takerAssetAmount: auctionEndPrice,
- expirationTimeSeconds: auctionEndTime,
- makerFee: zero,
- takerFee: zero,
+ takerAssetAmount: auctionEndAmount,
+ expirationTimeSeconds: auctionEndTimeSeconds,
+ makerFee: ZERO,
+ takerFee: ZERO,
};
// Default buy order is for the auction begin price
const buyerDefaultOrderParams = {
@@ -180,12 +194,9 @@ describe.only(ContractName.DutchAuction, () => {
makerAddress: takerAddress,
makerAssetData: sellerDefaultOrderParams.takerAssetData,
takerAssetData: sellerDefaultOrderParams.makerAssetData,
- makerAssetAmount: auctionBeginPrice,
- takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(200), DECIMALS_DEFAULT),
+ makerAssetAmount: auctionBeginAmount,
+ takerAssetAmount: sellerDefaultOrderParams.makerAssetAmount,
};
-
- encodedParams = await dutchAuctionContract.encodeParameters.callAsync(auctionBeginTime, auctionBeginPrice);
-
const makerPrivateKey = constants.TESTRPC_PRIVATE_KEYS[accounts.indexOf(makerAddress)];
const takerPrivateKey = constants.TESTRPC_PRIVATE_KEYS[accounts.indexOf(takerAddress)];
sellerOrderFactory = new OrderFactory(makerPrivateKey, sellerDefaultOrderParams);
@@ -204,35 +215,33 @@ describe.only(ContractName.DutchAuction, () => {
await blockchainLifecycle.revertAsync();
});
describe('matchOrders', () => {
- it('should encode and decode parameters', async () => {
- encodedParams = await dutchAuctionContract.encodeParameters.callAsync(auctionBeginTime, auctionBeginPrice);
- const [decodedBegin, decodedBeginPrice] = await dutchAuctionContract.decodeParameters.callAsync(
- encodedParams,
- );
- expect(decodedBegin).to.be.bignumber.equal(auctionBeginTime);
- expect(decodedBeginPrice).to.be.bignumber.equal(auctionBeginPrice);
- });
it('should be worth the begin price at the begining of the auction', async () => {
- auctionBeginTime = new BigNumber(currentBlockTimestamp + 2);
- encodedParams = await dutchAuctionContract.encodeParameters.callAsync(auctionBeginTime, auctionBeginPrice);
+ auctionBeginTimeSeconds = new BigNumber(currentBlockTimestamp + 2);
sellOrder = await sellerOrderFactory.newSignedOrderAsync({
- salt: encodedParams,
+ makerAssetData: extendMakerAssetData(
+ assetDataUtils.encodeERC20AssetData(defaultMakerAssetAddress),
+ auctionBeginTimeSeconds,
+ auctionBeginAmount,
+ ),
});
const auctionDetails = await dutchAuctionContract.getAuctionDetails.callAsync(sellOrder);
- expect(auctionDetails.currentPrice).to.be.bignumber.equal(auctionBeginPrice);
- expect(auctionDetails.beginPrice).to.be.bignumber.equal(auctionBeginPrice);
+ expect(auctionDetails.currentAmount).to.be.bignumber.equal(auctionBeginAmount);
+ expect(auctionDetails.beginAmount).to.be.bignumber.equal(auctionBeginAmount);
});
it('should be be worth the end price at the end of the auction', async () => {
- auctionBeginTime = new BigNumber(currentBlockTimestamp - 1000);
- auctionEndTime = new BigNumber(currentBlockTimestamp - 100);
- encodedParams = await dutchAuctionContract.encodeParameters.callAsync(auctionBeginTime, auctionBeginPrice);
+ auctionBeginTimeSeconds = new BigNumber(currentBlockTimestamp - 1000);
+ auctionEndTimeSeconds = new BigNumber(currentBlockTimestamp - 100);
sellOrder = await sellerOrderFactory.newSignedOrderAsync({
- salt: encodedParams,
- expirationTimeSeconds: auctionEndTime,
+ makerAssetData: extendMakerAssetData(
+ assetDataUtils.encodeERC20AssetData(defaultMakerAssetAddress),
+ auctionBeginTimeSeconds,
+ auctionBeginAmount,
+ ),
+ expirationTimeSeconds: auctionEndTimeSeconds,
});
const auctionDetails = await dutchAuctionContract.getAuctionDetails.callAsync(sellOrder);
- expect(auctionDetails.currentPrice).to.be.bignumber.equal(auctionEndPrice);
- expect(auctionDetails.beginPrice).to.be.bignumber.equal(auctionBeginPrice);
+ expect(auctionDetails.currentAmount).to.be.bignumber.equal(auctionEndAmount);
+ expect(auctionDetails.beginAmount).to.be.bignumber.equal(auctionBeginAmount);
});
it('should match orders and send excess to seller', async () => {
const txHash = await dutchAuctionContract.matchOrders.sendTransactionAsync(
@@ -246,23 +255,23 @@ describe.only(ContractName.DutchAuction, () => {
);
await web3Wrapper.awaitTransactionSuccessAsync(txHash);
const newBalances = await erc20Wrapper.getBalancesAsync();
- expect(newBalances[dutchAuctionContract.address][weth.address]).to.be.bignumber.equal(
+ expect(newBalances[dutchAuctionContract.address][wethContract.address]).to.be.bignumber.equal(
constants.ZERO_AMOUNT,
);
- expect(newBalances[makerAddress][weth.address]).to.be.bignumber.equal(
- erc20Balances[makerAddress][weth.address].plus(buyOrder.makerAssetAmount),
+ expect(newBalances[makerAddress][wethContract.address]).to.be.bignumber.equal(
+ erc20Balances[makerAddress][wethContract.address].plus(buyOrder.makerAssetAmount),
);
});
it('should have valid getAuctionDetails at a block in the future', async () => {
let auctionDetails = await dutchAuctionContract.getAuctionDetails.callAsync(sellOrder);
- const beforePrice = auctionDetails.currentPrice;
+ const beforeAmount = auctionDetails.currentAmount;
await increaseTimeAsync();
auctionDetails = await dutchAuctionContract.getAuctionDetails.callAsync(sellOrder);
- const currentPrice = auctionDetails.currentPrice;
- expect(beforePrice).to.be.bignumber.greaterThan(currentPrice);
+ const currentAmount = auctionDetails.currentAmount;
+ expect(beforeAmount).to.be.bignumber.greaterThan(currentAmount);
buyOrder = await buyerOrderFactory.newSignedOrderAsync({
- makerAssetAmount: currentPrice,
+ makerAssetAmount: currentAmount,
});
const txHash = await dutchAuctionContract.matchOrders.sendTransactionAsync(
buyOrder,
@@ -275,16 +284,14 @@ describe.only(ContractName.DutchAuction, () => {
);
await web3Wrapper.awaitTransactionSuccessAsync(txHash);
const newBalances = await erc20Wrapper.getBalancesAsync();
- expect(newBalances[makerAddress][weth.address]).to.be.bignumber.equal(
- erc20Balances[makerAddress][weth.address].plus(currentPrice),
+ expect(newBalances[makerAddress][wethContract.address]).to.be.bignumber.equal(
+ erc20Balances[makerAddress][wethContract.address].plus(currentAmount),
);
});
it('should revert when auction expires', async () => {
- auctionEndTime = new BigNumber(currentBlockTimestamp - 100);
- encodedParams = await dutchAuctionContract.encodeParameters.callAsync(auctionBeginTime, auctionBeginPrice);
+ auctionEndTimeSeconds = new BigNumber(currentBlockTimestamp - 100);
sellOrder = await sellerOrderFactory.newSignedOrderAsync({
- salt: encodedParams,
- expirationTimeSeconds: auctionEndTime,
+ expirationTimeSeconds: auctionEndTimeSeconds,
});
return expectTransactionFailedAsync(
dutchAuctionContract.matchOrders.sendTransactionAsync(
@@ -314,7 +321,43 @@ describe.only(ContractName.DutchAuction, () => {
from: takerAddress,
},
),
- 'INVALID_PRICE' as any,
+ 'INVALID_AMOUNT' as any,
+ );
+ });
+ it('cannot match an expired auction', async () => {
+ auctionBeginTimeSeconds = new BigNumber(currentBlockTimestamp - 1000);
+ auctionEndTimeSeconds = new BigNumber(currentBlockTimestamp - 100);
+ sellOrder = await sellerOrderFactory.newSignedOrderAsync({
+ expirationTimeSeconds: auctionEndTimeSeconds,
+ });
+ return expectTransactionFailedAsync(
+ dutchAuctionContract.matchOrders.sendTransactionAsync(
+ buyOrder,
+ sellOrder,
+ buyOrder.signature,
+ sellOrder.signature,
+ {
+ from: takerAddress,
+ },
+ ),
+ 'AUCTION_EXPIRED' as any,
+ );
+ });
+ it('auction begin amount must be higher than final amount ', async () => {
+ sellOrder = await sellerOrderFactory.newSignedOrderAsync({
+ takerAssetAmount: auctionBeginAmount.plus(1),
+ });
+ return expectTransactionFailedAsync(
+ dutchAuctionContract.matchOrders.sendTransactionAsync(
+ buyOrder,
+ sellOrder,
+ buyOrder.signature,
+ sellOrder.signature,
+ {
+ from: takerAddress,
+ },
+ ),
+ 'INVALID_AMOUNT' as any,
);
});
describe('ERC721', () => {
@@ -322,11 +365,15 @@ describe.only(ContractName.DutchAuction, () => {
const makerAssetId = erc721MakerAssetIds[0];
sellOrder = await sellerOrderFactory.newSignedOrderAsync({
makerAssetAmount: new BigNumber(1),
- makerAssetData: assetDataUtils.encodeERC721AssetData(erc721Token.address, makerAssetId),
+ makerAssetData: extendMakerAssetData(
+ assetDataUtils.encodeERC721AssetData(erc721Token.address, makerAssetId),
+ auctionBeginTimeSeconds,
+ auctionBeginAmount,
+ ),
});
buyOrder = await buyerOrderFactory.newSignedOrderAsync({
takerAssetAmount: new BigNumber(1),
- takerAssetData: assetDataUtils.encodeERC721AssetData(erc721Token.address, makerAssetId),
+ takerAssetData: sellOrder.makerAssetData,
});
const txHash = await dutchAuctionContract.matchOrders.sendTransactionAsync(
buyOrder,
@@ -339,8 +386,8 @@ describe.only(ContractName.DutchAuction, () => {
);
await web3Wrapper.awaitTransactionSuccessAsync(txHash);
const newBalances = await erc20Wrapper.getBalancesAsync();
- expect(newBalances[makerAddress][weth.address]).to.be.bignumber.equal(
- erc20Balances[makerAddress][weth.address].plus(buyOrder.makerAssetAmount),
+ expect(newBalances[makerAddress][wethContract.address]).to.be.bignumber.equal(
+ erc20Balances[makerAddress][wethContract.address].plus(buyOrder.makerAssetAmount),
);
const newOwner = await erc721Token.ownerOf.callAsync(makerAssetId);
expect(newOwner).to.be.bignumber.equal(takerAddress);