From 43b648e7dc1ea49aff3ab1e6883aa6e069fae72f Mon Sep 17 00:00:00 2001 From: Greg Hysen Date: Thu, 20 Dec 2018 15:39:19 -0800 Subject: Dutch wrapper --- .../test/dutch_auction_wrapper_test.ts | 156 +++++++++++++++++++++ 1 file changed, 156 insertions(+) create mode 100644 packages/contract-wrappers/test/dutch_auction_wrapper_test.ts (limited to 'packages/contract-wrappers/test') diff --git a/packages/contract-wrappers/test/dutch_auction_wrapper_test.ts b/packages/contract-wrappers/test/dutch_auction_wrapper_test.ts new file mode 100644 index 000000000..ad8b3bd31 --- /dev/null +++ b/packages/contract-wrappers/test/dutch_auction_wrapper_test.ts @@ -0,0 +1,156 @@ +import { BlockchainLifecycle } from '@0x/dev-utils'; +import { FillScenarios } from '@0x/fill-scenarios'; +import { assetDataUtils } from '@0x/order-utils'; +import { SignedOrder } from '@0x/types'; +import { BigNumber } from '@0x/utils'; +import * as chai from 'chai'; +import 'mocha'; + +import { ContractWrappers, OrderStatus } from '../src'; + +import { chaiSetup } from './utils/chai_setup'; +import { constants } from './utils/constants'; +import { migrateOnceAsync } from './utils/migrate'; +import { tokenUtils } from './utils/token_utils'; +import { provider, web3Wrapper } from './utils/web3_wrapper'; +import { getLatestBlockTimestampAsync } from '@0x/contracts-test-utils'; +import { DutchAuction } from '@0x/contract-artifacts'; +import { DutchAuctionWrapper } from '../src/contract_wrappers/dutch_auction_wrapper'; + +chaiSetup.configure(); +const expect = chai.expect; +const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper); + +// tslint:disable:custom-no-magic-numbers +describe.only('DutchAuctionWrapper', () => { + const fillableAmount = new BigNumber(5); + const tenMinutesInSeconds = 10 * 60; + let contractWrappers: ContractWrappers; + let fillScenarios: FillScenarios; + let exchangeContractAddress: string; + let zrxTokenAddress: string; + let userAddresses: string[]; + let makerAddress: string; + let takerAddress: string; + let makerTokenAddress: string; + let takerTokenAddress: string; + let makerAssetData: string; + let takerAssetData: string; + let buyOrder: SignedOrder; + let sellOrder: SignedOrder; + let makerTokenAssetData: string; + let takerTokenAssetData: string; + before(async () => { + console.log(`BEOGIN DEPLOYINH`); + const contractAddresses = await migrateOnceAsync(); + await blockchainLifecycle.startAsync(); + const config = { + networkId: constants.TESTRPC_NETWORK_ID, + contractAddresses, + blockPollingIntervalMs: 10, + }; + + contractWrappers = new ContractWrappers(provider, config); + console.log(`DEPLOYINH`); + exchangeContractAddress = contractWrappers.exchange.address; + userAddresses = await web3Wrapper.getAvailableAddressesAsync(); + zrxTokenAddress = contractWrappers.exchange.zrxTokenAddress; + fillScenarios = new FillScenarios( + provider, + userAddresses, + zrxTokenAddress, + exchangeContractAddress, + contractWrappers.erc20Proxy.address, + contractWrappers.erc721Proxy.address, + ); + [, makerAddress, takerAddress] = userAddresses; + [makerTokenAddress] = tokenUtils.getDummyERC20TokenAddresses(); + takerTokenAddress = contractWrappers.forwarder.etherTokenAddress; + // construct asset data for tokens being swapped + [makerTokenAssetData, takerTokenAssetData] = [ + assetDataUtils.encodeERC20AssetData(makerTokenAddress), + assetDataUtils.encodeERC20AssetData(takerTokenAddress), + ]; + // encode auction details in maker asset data + const auctionBeginAmount = fillableAmount; + const currentBlockTimestamp = await getLatestBlockTimestampAsync(); + const auctionBeginTimeSeconds = new BigNumber(currentBlockTimestamp - tenMinutesInSeconds); + makerAssetData = DutchAuctionWrapper.encodeDutchAuctionAssetData( + makerTokenAssetData, + auctionBeginTimeSeconds, + auctionBeginAmount + ); + takerAssetData = takerTokenAssetData; + // create sell / buy orders for auction + // note that the maker/taker asset datas are swapped in the `buyOrder` + sellOrder = await fillScenarios.createFillableSignedOrderAsync( + makerAssetData, + takerAssetData, + makerAddress, + constants.NULL_ADDRESS, + fillableAmount, + ); + buyOrder = await fillScenarios.createFillableSignedOrderAsync( + takerAssetData, + makerAssetData, + makerAddress, + constants.NULL_ADDRESS, + fillableAmount, + ); + }); + after(async () => { + await blockchainLifecycle.revertAsync(); + }); + beforeEach(async () => { + await blockchainLifecycle.startAsync(); + }); + afterEach(async () => { + await blockchainLifecycle.revertAsync(); + }); + describe('#matchOrdersAsync', () => { + it('should match two orders', async () => { + const txHash = await contractWrappers.dutchAuction.matchOrdersAsync(buyOrder, sellOrder, takerAddress); + await web3Wrapper.awaitTransactionSuccessAsync(txHash, constants.AWAIT_TRANSACTION_MINED_MS); + }); + it('should throw when invalid transaction and shouldValidate is true', async () => { + // request match with bad buy/sell orders + const badSellOrder = buyOrder; + const badBuyOrder = sellOrder; + return expect( + await contractWrappers.dutchAuction.matchOrdersAsync( + badBuyOrder, + badSellOrder, + takerAddress, + { + shouldValidate: true, + }, + ), + ).to.be.rejectedWith('COMPLETE_FILL_FAILED'); + }); + }); + + describe('#getAuctionDetailsAsync', () => { + it('should be worth the begin price at the begining of the auction', async () => { + // setup auction details + const auctionBeginAmount = fillableAmount; + const currentBlockTimestamp = await getLatestBlockTimestampAsync(); + const auctionBeginTimeSeconds = new BigNumber(currentBlockTimestamp + tenMinutesInSeconds); + const makerAssetData = DutchAuctionWrapper.encodeDutchAuctionAssetData( + makerTokenAssetData, + auctionBeginTimeSeconds, + auctionBeginAmount + ); + const order = await fillScenarios.createFillableSignedOrderAsync( + makerAssetData, + takerAssetData, + makerAddress, + constants.NULL_ADDRESS, + fillableAmount, + ); + const auctionDetails = await contractWrappers.dutchAuction.getAuctionDetailsAsync(order); + expect(auctionDetails.currentTimeSeconds).to.be.bignumber.lte(auctionBeginTimeSeconds); + expect(auctionDetails.currentAmount).to.be.bignumber.equal(auctionBeginAmount); + expect(auctionDetails.beginAmount).to.be.bignumber.equal(auctionBeginAmount); + }); + }); +}); -- cgit v1.2.3 From 5da748a062043b46133a2dbce248a756bbefce12 Mon Sep 17 00:00:00 2001 From: Greg Hysen Date: Thu, 20 Dec 2018 19:40:16 -0800 Subject: Progress on dutch auction wrapper. Need to add auction data decoding to it. --- .../test/dutch_auction_wrapper_test.ts | 46 ++++++++++++---------- 1 file changed, 26 insertions(+), 20 deletions(-) (limited to 'packages/contract-wrappers/test') diff --git a/packages/contract-wrappers/test/dutch_auction_wrapper_test.ts b/packages/contract-wrappers/test/dutch_auction_wrapper_test.ts index ad8b3bd31..bfc4e0a58 100644 --- a/packages/contract-wrappers/test/dutch_auction_wrapper_test.ts +++ b/packages/contract-wrappers/test/dutch_auction_wrapper_test.ts @@ -16,6 +16,7 @@ import { provider, web3Wrapper } from './utils/web3_wrapper'; import { getLatestBlockTimestampAsync } from '@0x/contracts-test-utils'; import { DutchAuction } from '@0x/contract-artifacts'; import { DutchAuctionWrapper } from '../src/contract_wrappers/dutch_auction_wrapper'; +import { Web3Wrapper } from '@0x/web3-wrapper'; chaiSetup.configure(); const expect = chai.expect; @@ -23,7 +24,7 @@ const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper); // tslint:disable:custom-no-magic-numbers describe.only('DutchAuctionWrapper', () => { - const fillableAmount = new BigNumber(5); + const fillableAmount = Web3Wrapper.toBaseUnitAmount(new BigNumber(50), 18); const tenMinutesInSeconds = 10 * 60; let contractWrappers: ContractWrappers; let fillScenarios: FillScenarios; @@ -32,10 +33,9 @@ describe.only('DutchAuctionWrapper', () => { let userAddresses: string[]; let makerAddress: string; let takerAddress: string; + let buyerAddress: string; let makerTokenAddress: string; let takerTokenAddress: string; - let makerAssetData: string; - let takerAssetData: string; let buyOrder: SignedOrder; let sellOrder: SignedOrder; let makerTokenAssetData: string; @@ -63,40 +63,44 @@ describe.only('DutchAuctionWrapper', () => { contractWrappers.erc20Proxy.address, contractWrappers.erc721Proxy.address, ); - [, makerAddress, takerAddress] = userAddresses; + [, makerAddress, takerAddress, buyerAddress] = userAddresses; [makerTokenAddress] = tokenUtils.getDummyERC20TokenAddresses(); takerTokenAddress = contractWrappers.forwarder.etherTokenAddress; + console.log(`B`); // construct asset data for tokens being swapped [makerTokenAssetData, takerTokenAssetData] = [ assetDataUtils.encodeERC20AssetData(makerTokenAddress), assetDataUtils.encodeERC20AssetData(takerTokenAddress), ]; + console.log(`C`); // encode auction details in maker asset data const auctionBeginAmount = fillableAmount; const currentBlockTimestamp = await getLatestBlockTimestampAsync(); const auctionBeginTimeSeconds = new BigNumber(currentBlockTimestamp - tenMinutesInSeconds); - makerAssetData = DutchAuctionWrapper.encodeDutchAuctionAssetData( + /* makerAssetData = DutchAuctionWrapper.encodeDutchAuctionAssetData( makerTokenAssetData, auctionBeginTimeSeconds, auctionBeginAmount - ); - takerAssetData = takerTokenAssetData; + );*/ + console.log(`C2`); // create sell / buy orders for auction // note that the maker/taker asset datas are swapped in the `buyOrder` - sellOrder = await fillScenarios.createFillableSignedOrderAsync( - makerAssetData, - takerAssetData, - makerAddress, - constants.NULL_ADDRESS, + sellOrder = await contractWrappers.dutchAuction.createSignedSellOrderAsync( + auctionBeginTimeSeconds, + fillableAmount.times(2), fillableAmount, - ); - buyOrder = await fillScenarios.createFillableSignedOrderAsync( - takerAssetData, - makerAssetData, + new BigNumber(currentBlockTimestamp + tenMinutesInSeconds), + makerTokenAssetData, + takerTokenAssetData, makerAddress, constants.NULL_ADDRESS, fillableAmount, ); + buyOrder = await contractWrappers.dutchAuction.createSignedBuyOrderAsync( + sellOrder, + buyerAddress, + ); + console.log(`CD`); }); after(async () => { await blockchainLifecycle.revertAsync(); @@ -109,8 +113,10 @@ describe.only('DutchAuctionWrapper', () => { }); describe('#matchOrdersAsync', () => { it('should match two orders', async () => { - const txHash = await contractWrappers.dutchAuction.matchOrdersAsync(buyOrder, sellOrder, takerAddress); - await web3Wrapper.awaitTransactionSuccessAsync(txHash, constants.AWAIT_TRANSACTION_MINED_MS); + console.log(await contractWrappers.dutchAuction.getAuctionDetailsAsync(sellOrder)); + + // const txHash = await contractWrappers.dutchAuction.matchOrdersAsync(buyOrder, sellOrder, takerAddress, {gasLimit: 1000000}); + //await web3Wrapper.awaitTransactionSuccessAsync(txHash, constants.AWAIT_TRANSACTION_MINED_MS); }); it('should throw when invalid transaction and shouldValidate is true', async () => { // request match with bad buy/sell orders @@ -130,7 +136,7 @@ describe.only('DutchAuctionWrapper', () => { }); describe('#getAuctionDetailsAsync', () => { - it('should be worth the begin price at the begining of the auction', async () => { + /*it('should be worth the begin price at the begining of the auction', async () => { // setup auction details const auctionBeginAmount = fillableAmount; const currentBlockTimestamp = await getLatestBlockTimestampAsync(); @@ -151,6 +157,6 @@ describe.only('DutchAuctionWrapper', () => { expect(auctionDetails.currentTimeSeconds).to.be.bignumber.lte(auctionBeginTimeSeconds); expect(auctionDetails.currentAmount).to.be.bignumber.equal(auctionBeginAmount); expect(auctionDetails.beginAmount).to.be.bignumber.equal(auctionBeginAmount); - }); + });*/ }); }); -- cgit v1.2.3 From 7203ca90cf9bff2f7accf5fe2ee7da5764d0dac3 Mon Sep 17 00:00:00 2001 From: Greg Hysen Date: Fri, 21 Dec 2018 16:11:59 -0800 Subject: all dutchie wrapper tests passing --- .../test/dutch_auction_wrapper_test.ts | 90 +++++++++++----------- 1 file changed, 46 insertions(+), 44 deletions(-) (limited to 'packages/contract-wrappers/test') diff --git a/packages/contract-wrappers/test/dutch_auction_wrapper_test.ts b/packages/contract-wrappers/test/dutch_auction_wrapper_test.ts index bfc4e0a58..f548e3ff8 100644 --- a/packages/contract-wrappers/test/dutch_auction_wrapper_test.ts +++ b/packages/contract-wrappers/test/dutch_auction_wrapper_test.ts @@ -1,7 +1,7 @@ import { BlockchainLifecycle } from '@0x/dev-utils'; import { FillScenarios } from '@0x/fill-scenarios'; import { assetDataUtils } from '@0x/order-utils'; -import { SignedOrder } from '@0x/types'; +import { RevertReason, SignedOrder } from '@0x/types'; import { BigNumber } from '@0x/utils'; import * as chai from 'chai'; import 'mocha'; @@ -18,13 +18,19 @@ import { DutchAuction } from '@0x/contract-artifacts'; import { DutchAuctionWrapper } from '../src/contract_wrappers/dutch_auction_wrapper'; import { Web3Wrapper } from '@0x/web3-wrapper'; +import { DutchAuctionUtils } from './utils/dutch_auction_utils'; + +import { + expectTransactionFailedAsync, +} from '@0x/contracts-test-utils'; + chaiSetup.configure(); const expect = chai.expect; const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper); // tslint:disable:custom-no-magic-numbers describe.only('DutchAuctionWrapper', () => { - const fillableAmount = Web3Wrapper.toBaseUnitAmount(new BigNumber(50), 18); + const fillableAmount = new BigNumber(2);//Web3Wrapper.toBaseUnitAmount(new BigNumber(50), 18); const tenMinutesInSeconds = 10 * 60; let contractWrappers: ContractWrappers; let fillScenarios: FillScenarios; @@ -33,13 +39,16 @@ describe.only('DutchAuctionWrapper', () => { let userAddresses: string[]; let makerAddress: string; let takerAddress: string; - let buyerAddress: string; let makerTokenAddress: string; let takerTokenAddress: string; let buyOrder: SignedOrder; let sellOrder: SignedOrder; let makerTokenAssetData: string; let takerTokenAssetData: string; + let auctionBeginTimeSeconds: BigNumber; + let auctionBeginAmount: BigNumber; + let auctionEndTimeSeconds: BigNumber; + let auctionEndAmount: BigNumber; before(async () => { console.log(`BEOGIN DEPLOYINH`); const contractAddresses = await migrateOnceAsync(); @@ -63,9 +72,8 @@ describe.only('DutchAuctionWrapper', () => { contractWrappers.erc20Proxy.address, contractWrappers.erc721Proxy.address, ); - [, makerAddress, takerAddress, buyerAddress] = userAddresses; - [makerTokenAddress] = tokenUtils.getDummyERC20TokenAddresses(); - takerTokenAddress = contractWrappers.forwarder.etherTokenAddress; + [, makerAddress, takerAddress] = userAddresses; + [makerTokenAddress, takerTokenAddress] = tokenUtils.getDummyERC20TokenAddresses(); console.log(`B`); // construct asset data for tokens being swapped [makerTokenAssetData, takerTokenAssetData] = [ @@ -74,31 +82,40 @@ describe.only('DutchAuctionWrapper', () => { ]; console.log(`C`); // encode auction details in maker asset data - const auctionBeginAmount = fillableAmount; + auctionEndAmount = fillableAmount; + auctionBeginAmount = auctionEndAmount.times(2); const currentBlockTimestamp = await getLatestBlockTimestampAsync(); - const auctionBeginTimeSeconds = new BigNumber(currentBlockTimestamp - tenMinutesInSeconds); + auctionBeginTimeSeconds = new BigNumber(currentBlockTimestamp - tenMinutesInSeconds); + auctionEndTimeSeconds = new BigNumber(currentBlockTimestamp + tenMinutesInSeconds); /* makerAssetData = DutchAuctionWrapper.encodeDutchAuctionAssetData( makerTokenAssetData, auctionBeginTimeSeconds, auctionBeginAmount );*/ console.log(`C2`); + // Create template orders from + + // create sell / buy orders for auction // note that the maker/taker asset datas are swapped in the `buyOrder` - sellOrder = await contractWrappers.dutchAuction.createSignedSellOrderAsync( + + const coinbase = userAddresses[0]; + const dutchAuctionUtils = new DutchAuctionUtils(web3Wrapper, coinbase, exchangeContractAddress, contractWrappers.erc20Proxy.address); + sellOrder = await dutchAuctionUtils.createSignedSellOrderAsync( auctionBeginTimeSeconds, - fillableAmount.times(2), - fillableAmount, - new BigNumber(currentBlockTimestamp + tenMinutesInSeconds), + auctionBeginAmount, + auctionEndAmount, + auctionEndTimeSeconds, makerTokenAssetData, takerTokenAssetData, makerAddress, constants.NULL_ADDRESS, - fillableAmount, + auctionEndAmount, ); - buyOrder = await contractWrappers.dutchAuction.createSignedBuyOrderAsync( + console.log(`ASDS`); + buyOrder = await dutchAuctionUtils.createSignedBuyOrderAsync( sellOrder, - buyerAddress, + takerAddress, ); console.log(`CD`); }); @@ -113,17 +130,15 @@ describe.only('DutchAuctionWrapper', () => { }); describe('#matchOrdersAsync', () => { it('should match two orders', async () => { - console.log(await contractWrappers.dutchAuction.getAuctionDetailsAsync(sellOrder)); - - // const txHash = await contractWrappers.dutchAuction.matchOrdersAsync(buyOrder, sellOrder, takerAddress, {gasLimit: 1000000}); - //await web3Wrapper.awaitTransactionSuccessAsync(txHash, constants.AWAIT_TRANSACTION_MINED_MS); + const txHash = await contractWrappers.dutchAuction.matchOrdersAsync(buyOrder, sellOrder, takerAddress); + await web3Wrapper.awaitTransactionSuccessAsync(txHash, constants.AWAIT_TRANSACTION_MINED_MS); }); it('should throw when invalid transaction and shouldValidate is true', async () => { // request match with bad buy/sell orders const badSellOrder = buyOrder; const badBuyOrder = sellOrder; - return expect( - await contractWrappers.dutchAuction.matchOrdersAsync( + return expectTransactionFailedAsync( + contractWrappers.dutchAuction.matchOrdersAsync( badBuyOrder, badSellOrder, takerAddress, @@ -131,32 +146,19 @@ describe.only('DutchAuctionWrapper', () => { shouldValidate: true, }, ), - ).to.be.rejectedWith('COMPLETE_FILL_FAILED'); + RevertReason.InvalidAssetData + ); }); }); describe('#getAuctionDetailsAsync', () => { - /*it('should be worth the begin price at the begining of the auction', async () => { - // setup auction details - const auctionBeginAmount = fillableAmount; - const currentBlockTimestamp = await getLatestBlockTimestampAsync(); - const auctionBeginTimeSeconds = new BigNumber(currentBlockTimestamp + tenMinutesInSeconds); - const makerAssetData = DutchAuctionWrapper.encodeDutchAuctionAssetData( - makerTokenAssetData, - auctionBeginTimeSeconds, - auctionBeginAmount - ); - const order = await fillScenarios.createFillableSignedOrderAsync( - makerAssetData, - takerAssetData, - makerAddress, - constants.NULL_ADDRESS, - fillableAmount, - ); - const auctionDetails = await contractWrappers.dutchAuction.getAuctionDetailsAsync(order); - expect(auctionDetails.currentTimeSeconds).to.be.bignumber.lte(auctionBeginTimeSeconds); - expect(auctionDetails.currentAmount).to.be.bignumber.equal(auctionBeginAmount); - expect(auctionDetails.beginAmount).to.be.bignumber.equal(auctionBeginAmount); - });*/ + it('should be worth the begin price at the begining of the auction', async () => { + // get auction details + const auctionDetails = await contractWrappers.dutchAuction.getAuctionDetailsAsync(sellOrder); + // run some basic sanity checks on the return value + expect(auctionDetails.beginTimeSeconds, 'auctionDetails.beginTimeSeconds').to.be.bignumber.equal(auctionBeginTimeSeconds); + expect(auctionDetails.beginAmount, 'auctionDetails.beginAmount').to.be.bignumber.equal(auctionBeginAmount); + expect(auctionDetails.endTimeSeconds, 'auctionDetails.endTimeSeconds').to.be.bignumber.equal(auctionEndTimeSeconds); + }); }); }); -- cgit v1.2.3 From 0432212a346aa761c54b5a9159a7e61e0c2f9b9a Mon Sep 17 00:00:00 2001 From: Greg Hysen Date: Fri, 21 Dec 2018 16:40:07 -0800 Subject: dutch wrapper tests working --- .../test/dutch_auction_wrapper_test.ts | 43 +++------------------- 1 file changed, 5 insertions(+), 38 deletions(-) (limited to 'packages/contract-wrappers/test') diff --git a/packages/contract-wrappers/test/dutch_auction_wrapper_test.ts b/packages/contract-wrappers/test/dutch_auction_wrapper_test.ts index f548e3ff8..697554dd1 100644 --- a/packages/contract-wrappers/test/dutch_auction_wrapper_test.ts +++ b/packages/contract-wrappers/test/dutch_auction_wrapper_test.ts @@ -1,12 +1,11 @@ import { BlockchainLifecycle } from '@0x/dev-utils'; -import { FillScenarios } from '@0x/fill-scenarios'; import { assetDataUtils } from '@0x/order-utils'; import { RevertReason, SignedOrder } from '@0x/types'; import { BigNumber } from '@0x/utils'; import * as chai from 'chai'; import 'mocha'; -import { ContractWrappers, OrderStatus } from '../src'; +import { ContractWrappers } from '../src'; import { chaiSetup } from './utils/chai_setup'; import { constants } from './utils/constants'; @@ -14,10 +13,6 @@ import { migrateOnceAsync } from './utils/migrate'; import { tokenUtils } from './utils/token_utils'; import { provider, web3Wrapper } from './utils/web3_wrapper'; import { getLatestBlockTimestampAsync } from '@0x/contracts-test-utils'; -import { DutchAuction } from '@0x/contract-artifacts'; -import { DutchAuctionWrapper } from '../src/contract_wrappers/dutch_auction_wrapper'; -import { Web3Wrapper } from '@0x/web3-wrapper'; - import { DutchAuctionUtils } from './utils/dutch_auction_utils'; import { @@ -33,9 +28,7 @@ describe.only('DutchAuctionWrapper', () => { const fillableAmount = new BigNumber(2);//Web3Wrapper.toBaseUnitAmount(new BigNumber(50), 18); const tenMinutesInSeconds = 10 * 60; let contractWrappers: ContractWrappers; - let fillScenarios: FillScenarios; let exchangeContractAddress: string; - let zrxTokenAddress: string; let userAddresses: string[]; let makerAddress: string; let takerAddress: string; @@ -50,7 +43,7 @@ describe.only('DutchAuctionWrapper', () => { let auctionEndTimeSeconds: BigNumber; let auctionEndAmount: BigNumber; before(async () => { - console.log(`BEOGIN DEPLOYINH`); + // setup contract wrappers & addresses const contractAddresses = await migrateOnceAsync(); await blockchainLifecycle.startAsync(); const config = { @@ -58,47 +51,23 @@ describe.only('DutchAuctionWrapper', () => { contractAddresses, blockPollingIntervalMs: 10, }; - contractWrappers = new ContractWrappers(provider, config); - console.log(`DEPLOYINH`); exchangeContractAddress = contractWrappers.exchange.address; userAddresses = await web3Wrapper.getAvailableAddressesAsync(); - zrxTokenAddress = contractWrappers.exchange.zrxTokenAddress; - fillScenarios = new FillScenarios( - provider, - userAddresses, - zrxTokenAddress, - exchangeContractAddress, - contractWrappers.erc20Proxy.address, - contractWrappers.erc721Proxy.address, - ); [, makerAddress, takerAddress] = userAddresses; [makerTokenAddress, takerTokenAddress] = tokenUtils.getDummyERC20TokenAddresses(); - console.log(`B`); // construct asset data for tokens being swapped [makerTokenAssetData, takerTokenAssetData] = [ assetDataUtils.encodeERC20AssetData(makerTokenAddress), assetDataUtils.encodeERC20AssetData(takerTokenAddress), ]; - console.log(`C`); - // encode auction details in maker asset data + // setup auction details in maker asset data auctionEndAmount = fillableAmount; auctionBeginAmount = auctionEndAmount.times(2); const currentBlockTimestamp = await getLatestBlockTimestampAsync(); auctionBeginTimeSeconds = new BigNumber(currentBlockTimestamp - tenMinutesInSeconds); auctionEndTimeSeconds = new BigNumber(currentBlockTimestamp + tenMinutesInSeconds); - /* makerAssetData = DutchAuctionWrapper.encodeDutchAuctionAssetData( - makerTokenAssetData, - auctionBeginTimeSeconds, - auctionBeginAmount - );*/ - console.log(`C2`); - // Create template orders from - - - // create sell / buy orders for auction - // note that the maker/taker asset datas are swapped in the `buyOrder` - + // create auction orders const coinbase = userAddresses[0]; const dutchAuctionUtils = new DutchAuctionUtils(web3Wrapper, coinbase, exchangeContractAddress, contractWrappers.erc20Proxy.address); sellOrder = await dutchAuctionUtils.createSignedSellOrderAsync( @@ -112,12 +81,10 @@ describe.only('DutchAuctionWrapper', () => { constants.NULL_ADDRESS, auctionEndAmount, ); - console.log(`ASDS`); buyOrder = await dutchAuctionUtils.createSignedBuyOrderAsync( sellOrder, takerAddress, ); - console.log(`CD`); }); after(async () => { await blockchainLifecycle.revertAsync(); @@ -152,7 +119,7 @@ describe.only('DutchAuctionWrapper', () => { }); describe('#getAuctionDetailsAsync', () => { - it('should be worth the begin price at the begining of the auction', async () => { + it('should get auction details', async () => { // get auction details const auctionDetails = await contractWrappers.dutchAuction.getAuctionDetailsAsync(sellOrder); // run some basic sanity checks on the return value -- cgit v1.2.3 From b249a50d8f0054328a901525af6316133ed64023 Mon Sep 17 00:00:00 2001 From: Greg Hysen Date: Fri, 21 Dec 2018 16:40:11 -0800 Subject: ran prettier --- .../test/dutch_auction_wrapper_test.ts | 39 +++++++++++----------- 1 file changed, 19 insertions(+), 20 deletions(-) (limited to 'packages/contract-wrappers/test') diff --git a/packages/contract-wrappers/test/dutch_auction_wrapper_test.ts b/packages/contract-wrappers/test/dutch_auction_wrapper_test.ts index 697554dd1..fa5ef41fd 100644 --- a/packages/contract-wrappers/test/dutch_auction_wrapper_test.ts +++ b/packages/contract-wrappers/test/dutch_auction_wrapper_test.ts @@ -15,9 +15,7 @@ import { provider, web3Wrapper } from './utils/web3_wrapper'; import { getLatestBlockTimestampAsync } from '@0x/contracts-test-utils'; import { DutchAuctionUtils } from './utils/dutch_auction_utils'; -import { - expectTransactionFailedAsync, -} from '@0x/contracts-test-utils'; +import { expectTransactionFailedAsync } from '@0x/contracts-test-utils'; chaiSetup.configure(); const expect = chai.expect; @@ -25,7 +23,7 @@ const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper); // tslint:disable:custom-no-magic-numbers describe.only('DutchAuctionWrapper', () => { - const fillableAmount = new BigNumber(2);//Web3Wrapper.toBaseUnitAmount(new BigNumber(50), 18); + const fillableAmount = new BigNumber(2); //Web3Wrapper.toBaseUnitAmount(new BigNumber(50), 18); const tenMinutesInSeconds = 10 * 60; let contractWrappers: ContractWrappers; let exchangeContractAddress: string; @@ -69,7 +67,12 @@ describe.only('DutchAuctionWrapper', () => { auctionEndTimeSeconds = new BigNumber(currentBlockTimestamp + tenMinutesInSeconds); // create auction orders const coinbase = userAddresses[0]; - const dutchAuctionUtils = new DutchAuctionUtils(web3Wrapper, coinbase, exchangeContractAddress, contractWrappers.erc20Proxy.address); + const dutchAuctionUtils = new DutchAuctionUtils( + web3Wrapper, + coinbase, + exchangeContractAddress, + contractWrappers.erc20Proxy.address, + ); sellOrder = await dutchAuctionUtils.createSignedSellOrderAsync( auctionBeginTimeSeconds, auctionBeginAmount, @@ -81,10 +84,7 @@ describe.only('DutchAuctionWrapper', () => { constants.NULL_ADDRESS, auctionEndAmount, ); - buyOrder = await dutchAuctionUtils.createSignedBuyOrderAsync( - sellOrder, - takerAddress, - ); + buyOrder = await dutchAuctionUtils.createSignedBuyOrderAsync(sellOrder, takerAddress); }); after(async () => { await blockchainLifecycle.revertAsync(); @@ -105,15 +105,10 @@ describe.only('DutchAuctionWrapper', () => { const badSellOrder = buyOrder; const badBuyOrder = sellOrder; return expectTransactionFailedAsync( - contractWrappers.dutchAuction.matchOrdersAsync( - badBuyOrder, - badSellOrder, - takerAddress, - { - shouldValidate: true, - }, - ), - RevertReason.InvalidAssetData + contractWrappers.dutchAuction.matchOrdersAsync(badBuyOrder, badSellOrder, takerAddress, { + shouldValidate: true, + }), + RevertReason.InvalidAssetData, ); }); }); @@ -123,9 +118,13 @@ describe.only('DutchAuctionWrapper', () => { // get auction details const auctionDetails = await contractWrappers.dutchAuction.getAuctionDetailsAsync(sellOrder); // run some basic sanity checks on the return value - expect(auctionDetails.beginTimeSeconds, 'auctionDetails.beginTimeSeconds').to.be.bignumber.equal(auctionBeginTimeSeconds); + expect(auctionDetails.beginTimeSeconds, 'auctionDetails.beginTimeSeconds').to.be.bignumber.equal( + auctionBeginTimeSeconds, + ); expect(auctionDetails.beginAmount, 'auctionDetails.beginAmount').to.be.bignumber.equal(auctionBeginAmount); - expect(auctionDetails.endTimeSeconds, 'auctionDetails.endTimeSeconds').to.be.bignumber.equal(auctionEndTimeSeconds); + expect(auctionDetails.endTimeSeconds, 'auctionDetails.endTimeSeconds').to.be.bignumber.equal( + auctionEndTimeSeconds, + ); }); }); }); -- cgit v1.2.3 From 06139cbfe59a1a00524de097b7e7fe5364c8d1c0 Mon Sep 17 00:00:00 2001 From: Greg Hysen Date: Fri, 21 Dec 2018 17:05:47 -0800 Subject: Added dutch auction utils to contract-wrappers --- .../test/utils/dutch_auction_utils.ts | 144 +++++++++++++++++++++ 1 file changed, 144 insertions(+) create mode 100644 packages/contract-wrappers/test/utils/dutch_auction_utils.ts (limited to 'packages/contract-wrappers/test') diff --git a/packages/contract-wrappers/test/utils/dutch_auction_utils.ts b/packages/contract-wrappers/test/utils/dutch_auction_utils.ts new file mode 100644 index 000000000..9cff1930d --- /dev/null +++ b/packages/contract-wrappers/test/utils/dutch_auction_utils.ts @@ -0,0 +1,144 @@ +import { DummyERC20TokenContract, DummyERC721TokenContract, ExchangeContract } from '@0x/abi-gen-wrappers'; +import { SignedOrder } from '@0x/types'; +import * as artifacts from '@0x/contract-artifacts'; +import { BigNumber } from '@0x/utils'; +import { Web3Wrapper } from '@0x/web3-wrapper'; +import { orderFactory } from '@0x/order-utils/lib/src/order_factory'; + +import { DutchAuctionWrapper } from '../../src/contract_wrappers/dutch_auction_wrapper'; +import { constants } from './constants'; +import { assetDataUtils } from '@0x/order-utils'; + +export class DutchAuctionUtils { + private _web3Wrapper: Web3Wrapper; + private _coinbase: string; + private _exchangeAddress: string; + private _erc20ProxyAddress: string; + + constructor(web3Wrapper: Web3Wrapper, coinbase: string, exchangeAddress: string, erc20ProxyAddress: string) { + this._web3Wrapper = web3Wrapper; + this._coinbase = coinbase; + this._exchangeAddress = exchangeAddress; + this._erc20ProxyAddress = erc20ProxyAddress; + } + public async createSignedSellOrderAsync( + auctionBeginTimeSections: BigNumber, + auctionBeginAmount: BigNumber, + auctionEndAmount: BigNumber, + acutionEndTime: BigNumber, + makerAssetData: string, + takerAssetData: string, + makerAddress: string, + takerAddress: string, + takerFillableAmount: BigNumber, + senderAddress?: string, + makerFee?: BigNumber, + takerFee?: BigNumber, + feeRecipientAddress?: string, + ): Promise { + console.log(`asdasd`); + const makerAssetAmount = auctionEndAmount; + const makerAssetDataWithAuctionDetails = DutchAuctionWrapper.encodeDutchAuctionAssetData( + makerAssetData, + auctionBeginTimeSections, + auctionBeginAmount, + ); + const signedOrder = await orderFactory.createSignedOrderAsync( + this._web3Wrapper.getProvider(), + makerAddress, + makerAssetAmount, + makerAssetDataWithAuctionDetails, + takerFillableAmount, + takerAssetData, + this._exchangeAddress, + { + takerAddress, + senderAddress, + makerFee, + takerFee, + feeRecipientAddress, + expirationTimeSeconds: acutionEndTime, + }, + ); + const erc20AssetData = assetDataUtils.decodeERC20AssetData(makerAssetData); + await this._increaseERC20BalanceAndAllowanceAsync(erc20AssetData.tokenAddress, makerAddress, makerAssetAmount); + return signedOrder; + } + public async createSignedBuyOrderAsync( + sellOrder: SignedOrder, + buyerAddress: string, + senderAddress?: string, + makerFee?: BigNumber, + takerFee?: BigNumber, + feeRecipientAddress?: string, + ): Promise { + const dutchAuctionData = DutchAuctionWrapper.decodeDutchAuctionData(sellOrder.makerAssetData); + const signedOrder = await orderFactory.createSignedOrderAsync( + this._web3Wrapper.getProvider(), + buyerAddress, + dutchAuctionData.beginAmount, + sellOrder.takerAssetData, + sellOrder.makerAssetAmount, + sellOrder.makerAssetData, + sellOrder.exchangeAddress, + { + senderAddress, + makerFee, + takerFee, + feeRecipientAddress, + expirationTimeSeconds: sellOrder.expirationTimeSeconds, + }, + ); + const buyerERC20AssetData = assetDataUtils.decodeERC20AssetData(sellOrder.takerAssetData); + await this._increaseERC20BalanceAndAllowanceAsync( + buyerERC20AssetData.tokenAddress, + buyerAddress, + dutchAuctionData.beginAmount, + ); + return signedOrder; + } + private async _increaseERC20BalanceAndAllowanceAsync( + tokenAddress: string, + address: string, + amount: BigNumber, + ): Promise { + if (amount.isZero() || address === constants.NULL_ADDRESS) { + return; // noop + } + await Promise.all([ + this._increaseERC20BalanceAsync(tokenAddress, address, amount), + this._increaseERC20AllowanceAsync(tokenAddress, address, amount), + ]); + } + private async _increaseERC20BalanceAsync(tokenAddress: string, address: string, amount: BigNumber): Promise { + const erc20Token = new DummyERC20TokenContract( + artifacts.DummyERC20Token.compilerOutput.abi, + tokenAddress, + this._web3Wrapper.getProvider(), + this._web3Wrapper.getContractDefaults(), + ); + const txHash = await erc20Token.transfer.sendTransactionAsync(address, amount, { + from: this._coinbase, + }); + await this._web3Wrapper.awaitTransactionSuccessAsync(txHash, constants.AWAIT_TRANSACTION_MINED_MS); + } + private async _increaseERC20AllowanceAsync( + tokenAddress: string, + address: string, + amount: BigNumber, + ): Promise { + const erc20Token = new DummyERC20TokenContract( + artifacts.DummyERC20Token.compilerOutput.abi, + tokenAddress, + this._web3Wrapper.getProvider(), + this._web3Wrapper.getContractDefaults(), + ); + const oldMakerAllowance = await erc20Token.allowance.callAsync(address, this._erc20ProxyAddress); + const newMakerAllowance = oldMakerAllowance.plus(amount); + + const txHash = await erc20Token.approve.sendTransactionAsync(this._erc20ProxyAddress, newMakerAllowance, { + from: address, + }); + await this._web3Wrapper.awaitTransactionSuccessAsync(txHash, constants.AWAIT_TRANSACTION_MINED_MS); + } +} -- cgit v1.2.3 From bbd48283407540b630a42f7155e97adc4b825e1b Mon Sep 17 00:00:00 2001 From: Greg Hysen Date: Fri, 21 Dec 2018 17:21:14 -0800 Subject: removed .only --- packages/contract-wrappers/test/dutch_auction_wrapper_test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'packages/contract-wrappers/test') diff --git a/packages/contract-wrappers/test/dutch_auction_wrapper_test.ts b/packages/contract-wrappers/test/dutch_auction_wrapper_test.ts index fa5ef41fd..16d370cb6 100644 --- a/packages/contract-wrappers/test/dutch_auction_wrapper_test.ts +++ b/packages/contract-wrappers/test/dutch_auction_wrapper_test.ts @@ -22,7 +22,7 @@ const expect = chai.expect; const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper); // tslint:disable:custom-no-magic-numbers -describe.only('DutchAuctionWrapper', () => { +describe('DutchAuctionWrapper', () => { const fillableAmount = new BigNumber(2); //Web3Wrapper.toBaseUnitAmount(new BigNumber(50), 18); const tenMinutesInSeconds = 10 * 60; let contractWrappers: ContractWrappers; -- cgit v1.2.3 From c6ab380685098dbf3a0a6ee5fae137e816839c2d Mon Sep 17 00:00:00 2001 From: Greg Hysen Date: Sat, 22 Dec 2018 12:56:52 -0800 Subject: Ran prettier & linter --- .../test/dutch_auction_wrapper_test.ts | 10 ++++------ .../test/utils/dutch_auction_utils.ts | 18 +++++++++--------- 2 files changed, 13 insertions(+), 15 deletions(-) (limited to 'packages/contract-wrappers/test') diff --git a/packages/contract-wrappers/test/dutch_auction_wrapper_test.ts b/packages/contract-wrappers/test/dutch_auction_wrapper_test.ts index 16d370cb6..4e6ad44e9 100644 --- a/packages/contract-wrappers/test/dutch_auction_wrapper_test.ts +++ b/packages/contract-wrappers/test/dutch_auction_wrapper_test.ts @@ -1,3 +1,4 @@ +import { expectTransactionFailedAsync, getLatestBlockTimestampAsync } from '@0x/contracts-test-utils'; import { BlockchainLifecycle } from '@0x/dev-utils'; import { assetDataUtils } from '@0x/order-utils'; import { RevertReason, SignedOrder } from '@0x/types'; @@ -9,13 +10,10 @@ import { ContractWrappers } from '../src'; import { chaiSetup } from './utils/chai_setup'; import { constants } from './utils/constants'; +import { DutchAuctionUtils } from './utils/dutch_auction_utils'; import { migrateOnceAsync } from './utils/migrate'; import { tokenUtils } from './utils/token_utils'; import { provider, web3Wrapper } from './utils/web3_wrapper'; -import { getLatestBlockTimestampAsync } from '@0x/contracts-test-utils'; -import { DutchAuctionUtils } from './utils/dutch_auction_utils'; - -import { expectTransactionFailedAsync } from '@0x/contracts-test-utils'; chaiSetup.configure(); const expect = chai.expect; @@ -23,7 +21,7 @@ const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper); // tslint:disable:custom-no-magic-numbers describe('DutchAuctionWrapper', () => { - const fillableAmount = new BigNumber(2); //Web3Wrapper.toBaseUnitAmount(new BigNumber(50), 18); + const fillableAmount = new BigNumber(2); const tenMinutesInSeconds = 10 * 60; let contractWrappers: ContractWrappers; let exchangeContractAddress: string; @@ -62,7 +60,7 @@ describe('DutchAuctionWrapper', () => { // setup auction details in maker asset data auctionEndAmount = fillableAmount; auctionBeginAmount = auctionEndAmount.times(2); - const currentBlockTimestamp = await getLatestBlockTimestampAsync(); + const currentBlockTimestamp: number = await getLatestBlockTimestampAsync(); auctionBeginTimeSeconds = new BigNumber(currentBlockTimestamp - tenMinutesInSeconds); auctionEndTimeSeconds = new BigNumber(currentBlockTimestamp + tenMinutesInSeconds); // create auction orders diff --git a/packages/contract-wrappers/test/utils/dutch_auction_utils.ts b/packages/contract-wrappers/test/utils/dutch_auction_utils.ts index 9cff1930d..766fc373a 100644 --- a/packages/contract-wrappers/test/utils/dutch_auction_utils.ts +++ b/packages/contract-wrappers/test/utils/dutch_auction_utils.ts @@ -1,19 +1,20 @@ -import { DummyERC20TokenContract, DummyERC721TokenContract, ExchangeContract } from '@0x/abi-gen-wrappers'; -import { SignedOrder } from '@0x/types'; +import { DummyERC20TokenContract } from '@0x/abi-gen-wrappers'; import * as artifacts from '@0x/contract-artifacts'; +import { assetDataUtils } from '@0x/order-utils'; +import { orderFactory } from '@0x/order-utils/lib/src/order_factory'; +import { SignedOrder } from '@0x/types'; import { BigNumber } from '@0x/utils'; import { Web3Wrapper } from '@0x/web3-wrapper'; -import { orderFactory } from '@0x/order-utils/lib/src/order_factory'; import { DutchAuctionWrapper } from '../../src/contract_wrappers/dutch_auction_wrapper'; + import { constants } from './constants'; -import { assetDataUtils } from '@0x/order-utils'; export class DutchAuctionUtils { - private _web3Wrapper: Web3Wrapper; - private _coinbase: string; - private _exchangeAddress: string; - private _erc20ProxyAddress: string; + private readonly _web3Wrapper: Web3Wrapper; + private readonly _coinbase: string; + private readonly _exchangeAddress: string; + private readonly _erc20ProxyAddress: string; constructor(web3Wrapper: Web3Wrapper, coinbase: string, exchangeAddress: string, erc20ProxyAddress: string) { this._web3Wrapper = web3Wrapper; @@ -36,7 +37,6 @@ export class DutchAuctionUtils { takerFee?: BigNumber, feeRecipientAddress?: string, ): Promise { - console.log(`asdasd`); const makerAssetAmount = auctionEndAmount; const makerAssetDataWithAuctionDetails = DutchAuctionWrapper.encodeDutchAuctionAssetData( makerAssetData, -- cgit v1.2.3 From 77a2ca1ddc9a7dd444822ca3cb38b3679dbd4085 Mon Sep 17 00:00:00 2001 From: Greg Hysen Date: Sat, 22 Dec 2018 13:54:57 -0800 Subject: Minor documentation updates to dutch auction wrapper --- .../test/dutch_auction_wrapper_test.ts | 16 ++++++------ .../test/utils/dutch_auction_utils.ts | 29 ++++++++++++++-------- 2 files changed, 26 insertions(+), 19 deletions(-) (limited to 'packages/contract-wrappers/test') diff --git a/packages/contract-wrappers/test/dutch_auction_wrapper_test.ts b/packages/contract-wrappers/test/dutch_auction_wrapper_test.ts index 4e6ad44e9..fb4eb10b4 100644 --- a/packages/contract-wrappers/test/dutch_auction_wrapper_test.ts +++ b/packages/contract-wrappers/test/dutch_auction_wrapper_test.ts @@ -21,7 +21,9 @@ const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper); // tslint:disable:custom-no-magic-numbers describe('DutchAuctionWrapper', () => { - const fillableAmount = new BigNumber(2); + const makerAssetAmount = new BigNumber(5); + const auctionEndTakerAmount = new BigNumber(10); + const auctionBeginTakerAmount = auctionEndTakerAmount.times(2); const tenMinutesInSeconds = 10 * 60; let contractWrappers: ContractWrappers; let exchangeContractAddress: string; @@ -35,9 +37,7 @@ describe('DutchAuctionWrapper', () => { let makerTokenAssetData: string; let takerTokenAssetData: string; let auctionBeginTimeSeconds: BigNumber; - let auctionBeginAmount: BigNumber; let auctionEndTimeSeconds: BigNumber; - let auctionEndAmount: BigNumber; before(async () => { // setup contract wrappers & addresses const contractAddresses = await migrateOnceAsync(); @@ -58,8 +58,6 @@ describe('DutchAuctionWrapper', () => { assetDataUtils.encodeERC20AssetData(takerTokenAddress), ]; // setup auction details in maker asset data - auctionEndAmount = fillableAmount; - auctionBeginAmount = auctionEndAmount.times(2); const currentBlockTimestamp: number = await getLatestBlockTimestampAsync(); auctionBeginTimeSeconds = new BigNumber(currentBlockTimestamp - tenMinutesInSeconds); auctionEndTimeSeconds = new BigNumber(currentBlockTimestamp + tenMinutesInSeconds); @@ -73,14 +71,14 @@ describe('DutchAuctionWrapper', () => { ); sellOrder = await dutchAuctionUtils.createSignedSellOrderAsync( auctionBeginTimeSeconds, - auctionBeginAmount, - auctionEndAmount, auctionEndTimeSeconds, + auctionBeginTakerAmount, + auctionEndTakerAmount, + makerAssetAmount, makerTokenAssetData, takerTokenAssetData, makerAddress, constants.NULL_ADDRESS, - auctionEndAmount, ); buyOrder = await dutchAuctionUtils.createSignedBuyOrderAsync(sellOrder, takerAddress); }); @@ -119,7 +117,7 @@ describe('DutchAuctionWrapper', () => { expect(auctionDetails.beginTimeSeconds, 'auctionDetails.beginTimeSeconds').to.be.bignumber.equal( auctionBeginTimeSeconds, ); - expect(auctionDetails.beginAmount, 'auctionDetails.beginAmount').to.be.bignumber.equal(auctionBeginAmount); + expect(auctionDetails.beginAmount, 'auctionDetails.beginAmount').to.be.bignumber.equal(auctionBeginTakerAmount); expect(auctionDetails.endTimeSeconds, 'auctionDetails.endTimeSeconds').to.be.bignumber.equal( auctionEndTimeSeconds, ); diff --git a/packages/contract-wrappers/test/utils/dutch_auction_utils.ts b/packages/contract-wrappers/test/utils/dutch_auction_utils.ts index 766fc373a..380d0588c 100644 --- a/packages/contract-wrappers/test/utils/dutch_auction_utils.ts +++ b/packages/contract-wrappers/test/utils/dutch_auction_utils.ts @@ -24,31 +24,34 @@ export class DutchAuctionUtils { } public async createSignedSellOrderAsync( auctionBeginTimeSections: BigNumber, - auctionBeginAmount: BigNumber, - auctionEndAmount: BigNumber, - acutionEndTime: BigNumber, + acutionEndTimeSeconds: BigNumber, + auctionBeginTakerAssetAmount: BigNumber, + auctionEndTakerAssetAmount: BigNumber, + makerAssetAmount: BigNumber, makerAssetData: string, takerAssetData: string, makerAddress: string, takerAddress: string, - takerFillableAmount: BigNumber, senderAddress?: string, makerFee?: BigNumber, takerFee?: BigNumber, feeRecipientAddress?: string, ): Promise { - const makerAssetAmount = auctionEndAmount; + // Notes on sell order: + // - The `takerAssetAmount` is set to the `auctionEndTakerAssetAmount`, which is the lowest amount the + // the seller can expect to receive + // - The `makerAssetData` is overloaded to include the auction begin time and begin taker asset amount const makerAssetDataWithAuctionDetails = DutchAuctionWrapper.encodeDutchAuctionAssetData( makerAssetData, auctionBeginTimeSections, - auctionBeginAmount, + auctionBeginTakerAssetAmount, ); const signedOrder = await orderFactory.createSignedOrderAsync( this._web3Wrapper.getProvider(), makerAddress, makerAssetAmount, makerAssetDataWithAuctionDetails, - takerFillableAmount, + auctionEndTakerAssetAmount, takerAssetData, this._exchangeAddress, { @@ -57,7 +60,7 @@ export class DutchAuctionUtils { makerFee, takerFee, feeRecipientAddress, - expirationTimeSeconds: acutionEndTime, + expirationTimeSeconds: acutionEndTimeSeconds, }, ); const erc20AssetData = assetDataUtils.decodeERC20AssetData(makerAssetData); @@ -71,8 +74,15 @@ export class DutchAuctionUtils { makerFee?: BigNumber, takerFee?: BigNumber, feeRecipientAddress?: string, + expirationTimeSeconds?: BigNumber, ): Promise { const dutchAuctionData = DutchAuctionWrapper.decodeDutchAuctionData(sellOrder.makerAssetData); + // Notes on buy order: + // - The `makerAssetAmount` is set to `dutchAuctionData.beginAmount`, which is + // the highest amount the buyer would have to pay out at any point during the auction. + // - The `takerAssetAmount` is set to the seller's `makerAssetAmount`, as the buyer + // receives the entire amount being sold by the seller. + // - The `makerAssetData`/`takerAssetData` are reversed from the sell order const signedOrder = await orderFactory.createSignedOrderAsync( this._web3Wrapper.getProvider(), buyerAddress, @@ -86,7 +96,7 @@ export class DutchAuctionUtils { makerFee, takerFee, feeRecipientAddress, - expirationTimeSeconds: sellOrder.expirationTimeSeconds, + expirationTimeSeconds, }, ); const buyerERC20AssetData = assetDataUtils.decodeERC20AssetData(sellOrder.takerAssetData); @@ -135,7 +145,6 @@ export class DutchAuctionUtils { ); const oldMakerAllowance = await erc20Token.allowance.callAsync(address, this._erc20ProxyAddress); const newMakerAllowance = oldMakerAllowance.plus(amount); - const txHash = await erc20Token.approve.sendTransactionAsync(this._erc20ProxyAddress, newMakerAllowance, { from: address, }); -- cgit v1.2.3 From a00e416a19a5aa7a6d1a615c4886f9d30339c8f6 Mon Sep 17 00:00:00 2001 From: Greg Hysen Date: Sat, 22 Dec 2018 14:50:24 -0800 Subject: ran prettier --- packages/contract-wrappers/test/dutch_auction_wrapper_test.ts | 4 +++- packages/contract-wrappers/test/utils/dutch_auction_utils.ts | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) (limited to 'packages/contract-wrappers/test') diff --git a/packages/contract-wrappers/test/dutch_auction_wrapper_test.ts b/packages/contract-wrappers/test/dutch_auction_wrapper_test.ts index fb4eb10b4..d7a6ca015 100644 --- a/packages/contract-wrappers/test/dutch_auction_wrapper_test.ts +++ b/packages/contract-wrappers/test/dutch_auction_wrapper_test.ts @@ -117,7 +117,9 @@ describe('DutchAuctionWrapper', () => { expect(auctionDetails.beginTimeSeconds, 'auctionDetails.beginTimeSeconds').to.be.bignumber.equal( auctionBeginTimeSeconds, ); - expect(auctionDetails.beginAmount, 'auctionDetails.beginAmount').to.be.bignumber.equal(auctionBeginTakerAmount); + expect(auctionDetails.beginAmount, 'auctionDetails.beginAmount').to.be.bignumber.equal( + auctionBeginTakerAmount, + ); expect(auctionDetails.endTimeSeconds, 'auctionDetails.endTimeSeconds').to.be.bignumber.equal( auctionEndTimeSeconds, ); diff --git a/packages/contract-wrappers/test/utils/dutch_auction_utils.ts b/packages/contract-wrappers/test/utils/dutch_auction_utils.ts index 380d0588c..8e2aef217 100644 --- a/packages/contract-wrappers/test/utils/dutch_auction_utils.ts +++ b/packages/contract-wrappers/test/utils/dutch_auction_utils.ts @@ -38,7 +38,7 @@ export class DutchAuctionUtils { feeRecipientAddress?: string, ): Promise { // Notes on sell order: - // - The `takerAssetAmount` is set to the `auctionEndTakerAssetAmount`, which is the lowest amount the + // - The `takerAssetAmount` is set to the `auctionEndTakerAssetAmount`, which is the lowest amount the // the seller can expect to receive // - The `makerAssetData` is overloaded to include the auction begin time and begin taker asset amount const makerAssetDataWithAuctionDetails = DutchAuctionWrapper.encodeDutchAuctionAssetData( @@ -78,7 +78,7 @@ export class DutchAuctionUtils { ): Promise { const dutchAuctionData = DutchAuctionWrapper.decodeDutchAuctionData(sellOrder.makerAssetData); // Notes on buy order: - // - The `makerAssetAmount` is set to `dutchAuctionData.beginAmount`, which is + // - The `makerAssetAmount` is set to `dutchAuctionData.beginAmount`, which is // the highest amount the buyer would have to pay out at any point during the auction. // - The `takerAssetAmount` is set to the seller's `makerAssetAmount`, as the buyer // receives the entire amount being sold by the seller. -- cgit v1.2.3