aboutsummaryrefslogtreecommitdiffstats
path: root/packages
diff options
context:
space:
mode:
authorGreg Hysen <greg.hysen@gmail.com>2018-12-23 04:56:52 +0800
committerGreg Hysen <greg.hysen@gmail.com>2019-01-08 07:50:48 +0800
commitc6ab380685098dbf3a0a6ee5fae137e816839c2d (patch)
tree2f4e6f2934fde26d5fadbab0eea9a590c1a1b6f1 /packages
parentd6467d707fdc1797eba4a445e805ccadc1f47872 (diff)
downloaddexon-sol-tools-c6ab380685098dbf3a0a6ee5fae137e816839c2d.tar
dexon-sol-tools-c6ab380685098dbf3a0a6ee5fae137e816839c2d.tar.gz
dexon-sol-tools-c6ab380685098dbf3a0a6ee5fae137e816839c2d.tar.bz2
dexon-sol-tools-c6ab380685098dbf3a0a6ee5fae137e816839c2d.tar.lz
dexon-sol-tools-c6ab380685098dbf3a0a6ee5fae137e816839c2d.tar.xz
dexon-sol-tools-c6ab380685098dbf3a0a6ee5fae137e816839c2d.tar.zst
dexon-sol-tools-c6ab380685098dbf3a0a6ee5fae137e816839c2d.zip
Ran prettier & linter
Diffstat (limited to 'packages')
-rw-r--r--packages/contract-wrappers/CHANGELOG.json2
-rw-r--r--packages/contract-wrappers/package.json2
-rw-r--r--packages/contract-wrappers/src/contract_wrappers.ts2
-rw-r--r--packages/contract-wrappers/src/contract_wrappers/dutch_auction_wrapper.ts135
-rw-r--r--packages/contract-wrappers/test/dutch_auction_wrapper_test.ts10
-rw-r--r--packages/contract-wrappers/test/utils/dutch_auction_utils.ts18
6 files changed, 86 insertions, 83 deletions
diff --git a/packages/contract-wrappers/CHANGELOG.json b/packages/contract-wrappers/CHANGELOG.json
index c01e35dcf..677292030 100644
--- a/packages/contract-wrappers/CHANGELOG.json
+++ b/packages/contract-wrappers/CHANGELOG.json
@@ -4,7 +4,7 @@
"changes": [
{
"note": "Added Dutch Auction wrapper",
- "pr": 1465
+ "pr": 1465
}
]
},
diff --git a/packages/contract-wrappers/package.json b/packages/contract-wrappers/package.json
index c6921d70b..222cfa622 100644
--- a/packages/contract-wrappers/package.json
+++ b/packages/contract-wrappers/package.json
@@ -69,6 +69,7 @@
"@0x/assert": "^1.0.20",
"@0x/contract-addresses": "^2.0.0",
"@0x/contract-artifacts": "^1.1.2",
+ "@0x/contracts-test-utils": "^1.0.2",
"@0x/fill-scenarios": "^1.0.16",
"@0x/json-schemas": "^2.1.4",
"@0x/order-utils": "^3.0.7",
@@ -76,6 +77,7 @@
"@0x/typescript-typings": "^3.0.6",
"@0x/utils": "^2.0.8",
"@0x/web3-wrapper": "^3.2.1",
+ "ethereumjs-abi": "0.6.5",
"ethereum-types": "^1.1.4",
"ethereumjs-blockstream": "6.0.0",
"ethereumjs-util": "^5.1.1",
diff --git a/packages/contract-wrappers/src/contract_wrappers.ts b/packages/contract-wrappers/src/contract_wrappers.ts
index 3728d58d3..4e594593e 100644
--- a/packages/contract-wrappers/src/contract_wrappers.ts
+++ b/packages/contract-wrappers/src/contract_wrappers.ts
@@ -12,6 +12,7 @@ import { Web3Wrapper } from '@0x/web3-wrapper';
import { Provider } from 'ethereum-types';
import * as _ from 'lodash';
+import { DutchAuctionWrapper } from './contract_wrappers/dutch_auction_wrapper';
import { ERC20ProxyWrapper } from './contract_wrappers/erc20_proxy_wrapper';
import { ERC20TokenWrapper } from './contract_wrappers/erc20_token_wrapper';
import { ERC721ProxyWrapper } from './contract_wrappers/erc721_proxy_wrapper';
@@ -20,7 +21,6 @@ import { EtherTokenWrapper } from './contract_wrappers/ether_token_wrapper';
import { ExchangeWrapper } from './contract_wrappers/exchange_wrapper';
import { ForwarderWrapper } from './contract_wrappers/forwarder_wrapper';
import { OrderValidatorWrapper } from './contract_wrappers/order_validator_wrapper';
-import { DutchAuctionWrapper } from './contract_wrappers/dutch_auction_wrapper';
import { ContractWrappersConfigSchema } from './schemas/contract_wrappers_config_schema';
import { ContractWrappersConfig } from './types';
import { assert } from './utils/assert';
diff --git a/packages/contract-wrappers/src/contract_wrappers/dutch_auction_wrapper.ts b/packages/contract-wrappers/src/contract_wrappers/dutch_auction_wrapper.ts
index f243d55d9..cb0c10187 100644
--- a/packages/contract-wrappers/src/contract_wrappers/dutch_auction_wrapper.ts
+++ b/packages/contract-wrappers/src/contract_wrappers/dutch_auction_wrapper.ts
@@ -1,40 +1,94 @@
import { DutchAuctionContract } from '@0x/abi-gen-wrappers';
import { DutchAuction } from '@0x/contract-artifacts';
-import { _getDefaultContractAddresses } from '../utils/contract_addresses';
+import { schemas } from '@0x/json-schemas';
+import { assetDataUtils } from '@0x/order-utils';
import { DutchAuctionDetails, SignedOrder } from '@0x/types';
-import { ContractAbi } from 'ethereum-types';
-import { Web3Wrapper } from '@0x/web3-wrapper';
import { BigNumber } from '@0x/utils';
+import { Web3Wrapper } from '@0x/web3-wrapper';
+import { ContractAbi } from 'ethereum-types';
+import * as ethAbi from 'ethereumjs-abi';
+import * as ethUtil from 'ethereumjs-util';
import * as _ from 'lodash';
-import ethAbi = require('ethereumjs-abi');
-import { schemas } from '@0x/json-schemas';
-import { assert } from '../utils/assert';
-import ethUtil = require('ethereumjs-util');
import { orderTxOptsSchema } from '../schemas/order_tx_opts_schema';
import { txOptsSchema } from '../schemas/tx_opts_schema';
-import { OrderTransactionOpts } from '../types';
-import { ContractWrapper } from './contract_wrapper';
-import { DutchAuctionWrapperError, DutchAuctionData } from '../types';
+import { DutchAuctionData, DutchAuctionWrapperError, OrderTransactionOpts } from '../types';
+import { assert } from '../utils/assert';
+import { _getDefaultContractAddresses } from '../utils/contract_addresses';
-import { assetDataUtils } from '@0x/order-utils';
+import { ContractWrapper } from './contract_wrapper';
export class DutchAuctionWrapper extends ContractWrapper {
public abi: ContractAbi = DutchAuction.compilerOutput.abi;
public address: string;
private _dutchAuctionContractIfExists?: DutchAuctionContract;
/**
+ * Dutch auction details are encoded with the asset data for a 0x order. This function produces a hex
+ * encoded assetData string, containing information both about the asset being traded and the
+ * dutch auction; which is usable in the makerAssetData or takerAssetData fields in a 0x order.
+ * @param assetData Hex encoded assetData string for the asset being auctioned.
+ * @param beginTimeSeconds Begin time of the dutch auction.
+ * @param beginAmount Starting amount being sold in the dutch auction.
+ * @return The hex encoded assetData string.
+ */
+ public static encodeDutchAuctionAssetData(
+ assetData: string,
+ beginTimeSeconds: BigNumber,
+ beginAmount: BigNumber,
+ ): string {
+ const assetDataBuffer = ethUtil.toBuffer(assetData);
+ const abiEncodedAuctionData = (ethAbi as any).rawEncode(
+ ['uint256', 'uint256'],
+ [beginTimeSeconds.toString(), beginAmount.toString()],
+ );
+ const abiEncodedAuctionDataBuffer = ethUtil.toBuffer(abiEncodedAuctionData);
+ const dutchAuctionDataBuffer = Buffer.concat([assetDataBuffer, abiEncodedAuctionDataBuffer]);
+ const dutchAuctionData = ethUtil.bufferToHex(dutchAuctionDataBuffer);
+ return dutchAuctionData;
+ }
+ /**
+ * Dutch auction details are encoded with the asset data for a 0x order. This function produces a hex
+ * encoded assetData string, containing information both about the asset being traded and the
+ * dutch auction; which is usable in the makerAssetData or takerAssetData fields in a 0x order.
+ * @param dutchAuctionData Hex encoded assetData string for the asset being auctioned.
+ * @return An object containing the auction asset, auction begin time and auction begin amount.
+ */
+ public static decodeDutchAuctionData(dutchAuctionData: string): DutchAuctionData {
+ const dutchAuctionDataBuffer = ethUtil.toBuffer(dutchAuctionData);
+ // Decode asset data
+ const dutchAuctionDataLengthInBytes = 64;
+ const assetDataBuffer = dutchAuctionDataBuffer.slice(
+ 0,
+ dutchAuctionDataBuffer.byteLength - dutchAuctionDataLengthInBytes,
+ );
+ const assetDataHex = ethUtil.bufferToHex(assetDataBuffer);
+ const assetData = assetDataUtils.decodeAssetDataOrThrow(assetDataHex);
+ // Decode auction details
+ const dutchAuctionDetailsBuffer = dutchAuctionDataBuffer.slice(
+ dutchAuctionDataBuffer.byteLength - dutchAuctionDataLengthInBytes,
+ );
+ const [beginTimeSecondsAsBN, beginAmountAsBN] = ethAbi.rawDecode(
+ ['uint256', 'uint256'],
+ dutchAuctionDetailsBuffer,
+ );
+ const beginTimeSeconds = new BigNumber(`0x${beginTimeSecondsAsBN.toString()}`);
+ const beginAmount = new BigNumber(`0x${beginAmountAsBN.toString()}`);
+ return {
+ assetData,
+ beginTimeSeconds,
+ beginAmount,
+ };
+ }
+ /**
* Instantiate DutchAuctionWrapper
* @param web3Wrapper Web3Wrapper instance to use.
* @param networkId Desired networkId.
* @param address The address of the Dutch Auction contract. If undefined, will
* default to the known address corresponding to the networkId.
*/
- constructor(web3Wrapper: Web3Wrapper, networkId: number, address?: string) {
+ public constructor(web3Wrapper: Web3Wrapper, networkId: number, address?: string) {
super(web3Wrapper, networkId);
- this.address = _.isUndefined(address)
- ? _getDefaultContractAddresses(networkId).dutchAuction
- : address;
+ this.address = _.isUndefined(address) ? _getDefaultContractAddresses(networkId).dutchAuction : address;
}
/**
* Matches the buy and sell orders at an amount given the following: the current block time, the auction
@@ -124,55 +178,4 @@ export class DutchAuctionWrapper extends ContractWrapper {
this._dutchAuctionContractIfExists = contractInstance;
return this._dutchAuctionContractIfExists;
}
- /**
- * Dutch auction details are encoded with the asset data for a 0x order. This function produces a hex
- * encoded assetData string, containing information both about the asset being traded and the
- * dutch auction; which is usable in the makerAssetData or takerAssetData fields in a 0x order.
- * @param assetData Hex encoded assetData string for the asset being auctioned.
- * @param beginTimeSeconds Begin time of the dutch auction.
- * @param beginAmount Starting amount being sold in the dutch auction.
- * @return The hex encoded assetData string.
- */
- public static encodeDutchAuctionAssetData(
- assetData: string,
- beginTimeSeconds: BigNumber,
- beginAmount: BigNumber,
- ): string {
- const assetDataBuffer = ethUtil.toBuffer(assetData);
- const abiEncodedAuctionData = (ethAbi as any).rawEncode(
- ['uint256', 'uint256'],
- [beginTimeSeconds.toString(), beginAmount.toString()],
- );
- const abiEncodedAuctionDataBuffer = ethUtil.toBuffer(abiEncodedAuctionData);
- const dutchAuctionDataBuffer = Buffer.concat([assetDataBuffer, abiEncodedAuctionDataBuffer]);
- const dutchAuctionData = ethUtil.bufferToHex(dutchAuctionDataBuffer);
- return dutchAuctionData;
- }
- /**
- * Dutch auction details are encoded with the asset data for a 0x order. This function produces a hex
- * encoded assetData string, containing information both about the asset being traded and the
- * dutch auction; which is usable in the makerAssetData or takerAssetData fields in a 0x order.
- * @param dutchAuctionData Hex encoded assetData string for the asset being auctioned.
- * @return An object containing the auction asset, auction begin time and auction begin amount.
- */
- public static decodeDutchAuctionData(dutchAuctionData: string): DutchAuctionData {
- const dutchAuctionDataBuffer = ethUtil.toBuffer(dutchAuctionData);
- // Decode asset data
- const assetDataBuffer = dutchAuctionDataBuffer.slice(0, dutchAuctionDataBuffer.byteLength - 64);
- const assetDataHex = ethUtil.bufferToHex(assetDataBuffer);
- const assetData = assetDataUtils.decodeAssetDataOrThrow(assetDataHex);
- // Decode auction details
- const dutchAuctionDetailsBuffer = dutchAuctionDataBuffer.slice(dutchAuctionDataBuffer.byteLength - 64);
- const [beginTimeSecondsAsBN, beginAmountAsBN] = ethAbi.rawDecode(
- ['uint256', 'uint256'],
- dutchAuctionDetailsBuffer,
- );
- const beginTimeSeconds = new BigNumber(`0x${beginTimeSecondsAsBN.toString()}`);
- const beginAmount = new BigNumber(`0x${beginAmountAsBN.toString()}`);
- return {
- assetData,
- beginTimeSeconds,
- beginAmount,
- };
- }
}
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<SignedOrder> {
- console.log(`asdasd`);
const makerAssetAmount = auctionEndAmount;
const makerAssetDataWithAuctionDetails = DutchAuctionWrapper.encodeDutchAuctionAssetData(
makerAssetData,