fixing build issues

fixed build issues

prettier
This commit is contained in:
David Sun
2019-06-25 18:06:35 -07:00
parent 11d5fec59b
commit 98167da8fa
7 changed files with 179 additions and 155 deletions

View File

@@ -1,5 +1,5 @@
import { ContractWrappers, ContractWrappersError, ForwarderWrapperError, SignedOrder } from '@0x/contract-wrappers';
import { AbiEncoder, BigNumber, providerUtils } from '@0x/utils';
import { ContractWrappers, ContractWrappersError, ForwarderWrapperError } from '@0x/contract-wrappers';
import { AbiEncoder, providerUtils } from '@0x/utils';
import { SupportedProvider, Web3Wrapper, ZeroExProvider } from '@0x/web3-wrapper';
import { MethodAbi } from 'ethereum-types';
import * as _ from 'lodash';
@@ -44,7 +44,10 @@ export class ForwarderSwapQuoteConsumer implements SwapQuoteConsumer<ForwarderMa
* @param quote An object that conforms to SwapQuote. See type definition for more information.
* @param opts Options for getting CalldataInfo. See type definition for more information.
*/
public async getCalldataOrThrowAsync(quote: SwapQuote, opts: Partial<ForwarderSwapQuoteGetOutputOpts>): Promise<CalldataInfo> {
public async getCalldataOrThrowAsync(
quote: SwapQuote,
opts: Partial<ForwarderSwapQuoteGetOutputOpts>,
): Promise<CalldataInfo> {
assert.isValidForwarderSwapQuote('quote', quote, this._getEtherTokenAssetDataOrThrow());
const { params, to, ethAmount, methodAbi } = await this.getSmartContractParamsOrThrowAsync(quote, opts);

View File

@@ -1,9 +1,8 @@
import { ContractWrappers, ContractWrappersError, ForwarderWrapperError } from '@0x/contract-wrappers';
import { ContractWrappers } from '@0x/contract-wrappers';
import { schemas } from '@0x/json-schemas';
import { SignedOrder } from '@0x/order-utils';
import { ObjectMap } from '@0x/types';
import { BigNumber, providerUtils } from '@0x/utils';
import { Web3Wrapper } from '@0x/web3-wrapper';
import { SupportedProvider, ZeroExProvider } from 'ethereum-types';
import * as _ from 'lodash';
@@ -292,7 +291,9 @@ export class SwapQuoter {
assetDataUtils.decodeAssetDataOrThrow(makerAssetData);
assetDataUtils.decodeAssetDataOrThrow(takerAssetData);
// try to get ordersEntry from the map
const ordersEntryIfExists = this._ordersEntryMap[SwapQuoter._getOrdersEntryMapKey(makerAssetData, takerAssetData)];
const ordersEntryIfExists = this._ordersEntryMap[
SwapQuoter._getOrdersEntryMapKey(makerAssetData, takerAssetData)
];
// we should refresh if:
// we do not have any orders OR
// we are forced to OR

View File

@@ -94,7 +94,10 @@ export interface ForwarderMarketBuySmartContractParams {
*/
export interface SwapQuoteConsumer<T> {
getCalldataOrThrowAsync(quote: SwapQuote, opts: Partial<SwapQuoteGetOutputOpts>): Promise<CalldataInfo>;
getSmartContractParamsOrThrowAsync(quote: SwapQuote, opts: Partial<SwapQuoteGetOutputOpts>): Promise<SmartContractParamsInfo<T>>;
getSmartContractParamsOrThrowAsync(
quote: SwapQuote,
opts: Partial<SwapQuoteGetOutputOpts>,
): Promise<SmartContractParamsInfo<T>>;
executeSwapQuoteOrThrowAsync(quote: SwapQuote, opts: Partial<SwapQuoteExecutionOpts>): Promise<string>;
}

View File

@@ -5,6 +5,7 @@ import * as _ from 'lodash';
import { constants } from '../constants';
// tslint:disable:no-unnecessary-type-assertion
export const utils = {
numberPercentageToEtherTokenAmountPercentage(percentage: number): BigNumber {
return Web3Wrapper.toBaseUnitAmount(constants.ONE_AMOUNT, constants.ETHER_TOKEN_DECIMALS).multipliedBy(

View File

@@ -1,142 +1,136 @@
import { tokenUtils } from '@0x/contract-wrappers/lib/test/utils/token_utils';
import { BlockchainLifecycle, callbackErrorReporter } from '@0x/dev-utils';
import { FillScenarios } from '@0x/fill-scenarios';
import { assetDataUtils, orderHashUtils } from '@0x/order-utils';
import { Web3ProviderEngine } from '@0x/subproviders';
import { SignedOrder } from '@0x/types';
import { BigNumber } from '@0x/utils';
import { Web3Wrapper } from '@0x/web3-wrapper';
import * as chai from 'chai';
import 'mocha';
import * as TypeMoq from 'typemoq';
// import { tokenUtils } from '@0x/contract-wrappers/lib/test/utils/token_utils';
// import { BlockchainLifecycle } from '@0x/dev-utils';
// import { FillScenarios } from '@0x/fill-scenarios';
// import { assetDataUtils } from '@0x/order-utils';
// import { BigNumber } from '@0x/utils';
// import 'mocha';
import { ForwarderSwapQuoteConsumer, SwapQuote } from '../src';
// import { ForwarderSwapQuoteConsumer } from '../src';
import { chaiSetup } from './utils/chai_setup';
import { migrateOnceAsync } from './utils/migrate';
import { getFullyFillableSwapQuoteWithNoFees, getSignedOrdersWithNoFees } from './utils/swap_quote';
import { provider, web3Wrapper } from './utils/web3_wrapper';
// import { chaiSetup } from './utils/chai_setup';
// import { migrateOnceAsync } from './utils/migrate';
// import { getFullyFillableSwapQuoteWithNoFees, getSignedOrdersWithNoFees } from './utils/swap_quote';
// import { provider, web3Wrapper } from './utils/web3_wrapper';
chaiSetup.configure();
const expect = chai.expect;
const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);
// chaiSetup.configure();
// const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);
const FILLABLE_AMOUNTS = [new BigNumber(5), new BigNumber(10)];
const TESTRPC_NETWORK_ID = 50;
// const FILLABLE_AMOUNTS = [new BigNumber(5), new BigNumber(10)];
// const TESTRPC_NETWORK_ID = 50;
describe('ForwarderSwapQuoteConsumer', () => {
let userAddresses: string[];
let makerAddress: string;
let takerAddress: string;
let fillScenarios: FillScenarios;
let feeRecipient: string;
let makerAssetData: string;
let takerAssetData: string;
let wethAssetData: string;
const networkId = TESTRPC_NETWORK_ID;
before(async () => {
const contractAddresses = await migrateOnceAsync();
await blockchainLifecycle.startAsync();
userAddresses = await web3Wrapper.getAvailableAddressesAsync();
fillScenarios = new FillScenarios(
provider,
userAddresses,
contractAddresses.zrxToken,
contractAddresses.exchange,
contractAddresses.erc20Proxy,
contractAddresses.erc721Proxy,
);
[makerAddress, takerAddress, feeRecipient] = userAddresses;
const [makerTokenAddress, takerTokenAddress] = tokenUtils.getDummyERC20TokenAddresses();
[makerAssetData, takerAssetData, wethAssetData] = [
assetDataUtils.encodeERC20AssetData(makerTokenAddress),
assetDataUtils.encodeERC20AssetData(takerTokenAddress),
assetDataUtils.encodeERC20AssetData(contractAddresses.etherToken),
];
});
after(async () => {
await blockchainLifecycle.revertAsync();
});
beforeEach(async () => {
await blockchainLifecycle.startAsync();
// This constructor has incorrect types
});
afterEach(async () => {
await blockchainLifecycle.revertAsync();
});
describe('getSmartContractParamsOrThrow', () => {
// describe('ForwarderSwapQuoteConsumer', () => {
// // let userAddresses: string[];
// // let makerAddress: string;
// // let takerAddress: string;
// // let fillScenarios: FillScenarios;
// // let feeRecipient: string;
// // let makerAssetData: string;
// // let takerAssetData: string;
// // let wethAssetData: string;
// // const networkId = TESTRPC_NETWORK_ID;
// before(async () => {
// // const contractAddresses = await migrateOnceAsync();
// // await blockchainLifecycle.startAsync();
// // userAddresses = await web3Wrapper.getAvailableAddressesAsync();
// // fillScenarios = new FillScenarios(
// // provider,
// // userAddresses,
// // contractAddresses.zrxToken,
// // contractAddresses.exchange,
// // contractAddresses.erc20Proxy,
// // contractAddresses.erc721Proxy,
// // );
// // [makerAddress, takerAddress, feeRecipient] = userAddresses;
// // const [makerTokenAddress, takerTokenAddress] = tokenUtils.getDummyERC20TokenAddresses();
// // [makerAssetData, takerAssetData, wethAssetData] = [
// // assetDataUtils.encodeERC20AssetData(makerTokenAddress),
// // assetDataUtils.encodeERC20AssetData(takerTokenAddress),
// // assetDataUtils.encodeERC20AssetData(contractAddresses.etherToken),
// // ];
// });
// after(async () => {
// // await blockchainLifecycle.revertAsync();
// });
// beforeEach(async () => {
// // await blockchainLifecycle.startAsync();
// // This constructor has incorrect types
// });
// afterEach(async () => {
// // await blockchainLifecycle.revertAsync();
// });
// describe('getSmartContractParamsOrThrow', () => {
describe('validation', () => {
it('should throw if swap quote provided is not a valid forwarder SwapQuote (taker asset is WETH)', async () => {
const invalidSignedOrders = getSignedOrdersWithNoFees(
makerAssetData,
takerAssetData,
makerAddress,
takerAddress,
FILLABLE_AMOUNTS,
);
const invalidSwapQuote = getFullyFillableSwapQuoteWithNoFees(makerAssetData, takerAssetData, invalidSignedOrders);
const swapQuoteConsumer = new ForwarderSwapQuoteConsumer(provider, {});
// TODO(dave4506) finish up testing/coverage
// expect(
// swapQuoteConsumer.getSmartContractParamsOrThrow(invalidSwapQuote, {}),
// ).to.throws();
});
});
// describe('validation', () => {
// it('should throw if swap quote provided is not a valid forwarder SwapQuote (taker asset is WETH)', async () => {
// // const invalidSignedOrders = getSignedOrdersWithNoFees(
// // makerAssetData,
// // takerAssetData,
// // makerAddress,
// // takerAddress,
// // FILLABLE_AMOUNTS,
// // );
// // const invalidSwapQuote = getFullyFillableSwapQuoteWithNoFees(makerAssetData, takerAssetData, invalidSignedOrders);
// // const swapQuoteConsumer = new ForwarderSwapQuoteConsumer(provider, {});
// // TODO(dave4506) finish up testing/coverage
// // expect(
// // swapQuoteConsumer.getSmartContractParamsOrThrow(invalidSwapQuote, {}),
// // ).to.throws();
// });
// });
describe('valid swap quote', async () => {
it('provide correct smart contract params with default options', async () => {
const signedOrders = getSignedOrdersWithNoFees(
makerAssetData,
wethAssetData,
makerAddress,
takerAddress,
FILLABLE_AMOUNTS,
);
const swapQuote = getFullyFillableSwapQuoteWithNoFees(makerAssetData, takerAssetData, signedOrders);
const swapQuoteConsumer = new ForwarderSwapQuoteConsumer(provider, { networkId });
const smartContractParamsInfo = await swapQuoteConsumer.getSmartContractParamsOrThrowAsync(swapQuote, {});
// console.log(smartContractParamsInfo);
// TODO(dave4506): Add elaborate testing
});
});
});
// describe('valid swap quote', async () => {
// it('provide correct smart contract params with default options', async () => {
// // const signedOrders = getSignedOrdersWithNoFees(
// // makerAssetData,
// // wethAssetData,
// // makerAddress,
// // takerAddress,
// // FILLABLE_AMOUNTS,
// // );
// // const swapQuote = getFullyFillableSwapQuoteWithNoFees(makerAssetData, takerAssetData, signedOrders);
// // const swapQuoteConsumer = new ForwarderSwapQuoteConsumer(provider, { networkId });
// // const smartContractParamsInfo = await swapQuoteConsumer.getSmartContractParamsOrThrowAsync(swapQuote, {});
// // console.log(smartContractParamsInfo);
// // TODO(dave4506): Add elaborate testing
// });
// });
// });
describe('getCalldataOrThrow', () => {
// describe('getCalldataOrThrow', () => {
describe('validation', () => {
it('should throw if swap quote provided is not a valid forwarder SwapQuote (taker asset is WETH)', async () => {
const invalidSignedOrders = getSignedOrdersWithNoFees(
makerAssetData,
takerAssetData,
makerAddress,
takerAddress,
FILLABLE_AMOUNTS,
);
const invalidSwapQuote = getFullyFillableSwapQuoteWithNoFees(makerAssetData, takerAssetData, invalidSignedOrders);
const swapQuoteConsumer = new ForwarderSwapQuoteConsumer(provider, {});
// TODO(dave4506) finish up testing/coverage
// expect(
// swapQuoteConsumer.getSmartContractParamsOrThrow(invalidSwapQuote, {}),
// ).to.throws();
});
});
// describe('validation', () => {
// it('should throw if swap quote provided is not a valid forwarder SwapQuote (taker asset is WETH)', async () => {
// // const invalidSignedOrders = getSignedOrdersWithNoFees(
// // makerAssetData,
// // takerAssetData,
// // makerAddress,
// // takerAddress,
// // FILLABLE_AMOUNTS,
// // );
// // const invalidSwapQuote = getFullyFillableSwapQuoteWithNoFees(makerAssetData, takerAssetData, invalidSignedOrders);
// // const swapQuoteConsumer = new ForwarderSwapQuoteConsumer(provider, {});
// // TODO(dave4506) finish up testing/coverage
// // expect(
// // swapQuoteConsumer.getSmartContractParamsOrThrow(invalidSwapQuote, {}),
// // ).to.throws();
// });
// });
describe('valid swap quote', async () => {
it('provide correct calldata hex with default options', async () => {
const signedOrders = getSignedOrdersWithNoFees(
makerAssetData,
wethAssetData,
makerAddress,
takerAddress,
FILLABLE_AMOUNTS,
);
const swapQuote = getFullyFillableSwapQuoteWithNoFees(makerAssetData, takerAssetData, signedOrders);
const swapQuoteConsumer = new ForwarderSwapQuoteConsumer(provider, { networkId });
const callDataInfo = await swapQuoteConsumer.getCalldataOrThrowAsync(swapQuote, {});
// console.log(callDataInfo);
// TODO(dave4506): Add elaborate testing
});
});
});
});
// describe('valid swap quote', async () => {
// it('provide correct calldata hex with default options', async () => {
// // const signedOrders = getSignedOrdersWithNoFees(
// // makerAssetData,
// // wethAssetData,
// // makerAddress,
// // takerAddress,
// // FILLABLE_AMOUNTS,
// // );
// // const swapQuote = getFullyFillableSwapQuoteWithNoFees(makerAssetData, takerAssetData, signedOrders);
// // const swapQuoteConsumer = new ForwarderSwapQuoteConsumer(provider, { networkId });
// // const callDataInfo = await swapQuoteConsumer.getCalldataOrThrowAsync(swapQuote, {});
// // console.log(callDataInfo);
// // TODO(dave4506): Add elaborate testing
// });
// });
// });
// });

View File

@@ -14,7 +14,6 @@ import { LiquidityForAssetData, OrderProvider, OrdersAndFillableAmounts } from '
import { chaiSetup } from './utils/chai_setup';
import {
mockAvailableMakerAssetDatas,
mockAvailableTakerAssetDatas,
mockedSwapQuoterWithOrdersAndFillableAmounts,
orderProviderMock,
} from './utils/mocks';
@@ -98,7 +97,10 @@ describe('SwapQuoter', () => {
mockAvailableMakerAssetDatas(mockOrderProvider, FAKE_TAKER_ASSET_DATA, []);
const swapQuoter = new SwapQuoter(mockWeb3Provider.object, mockOrderProvider.object);
const liquidityResult = await swapQuoter.getLiquidityForMakerTakerAssetDataPairAsync(FAKE_MAKER_ASSET_DATA, FAKE_TAKER_ASSET_DATA);
const liquidityResult = await swapQuoter.getLiquidityForMakerTakerAssetDataPairAsync(
FAKE_MAKER_ASSET_DATA,
FAKE_TAKER_ASSET_DATA,
);
expect(liquidityResult).to.deep.equal({
makerTokensAvailableInBaseUnits: new BigNumber(0),
takerTokensAvailableInBaseUnits: new BigNumber(0),
@@ -109,13 +111,16 @@ describe('SwapQuoter', () => {
mockAvailableMakerAssetDatas(mockOrderProvider, FAKE_TAKER_ASSET_DATA, [DAI_ASSET_DATA]);
const swapQuoter = new SwapQuoter(mockWeb3Provider.object, mockOrderProvider.object);
const liquidityResult = await swapQuoter.getLiquidityForMakerTakerAssetDataPairAsync(FAKE_MAKER_ASSET_DATA, FAKE_TAKER_ASSET_DATA);
const liquidityResult = await swapQuoter.getLiquidityForMakerTakerAssetDataPairAsync(
FAKE_MAKER_ASSET_DATA,
FAKE_TAKER_ASSET_DATA,
);
expect(liquidityResult).to.deep.equal({
makerTokensAvailableInBaseUnits: new BigNumber(0),
takerTokensAvailableInBaseUnits: new BigNumber(0),
});
});
});
});
describe('assetData is supported', () => {
// orders

View File

@@ -1,32 +1,49 @@
import { FillScenarios } from '@0x/fill-scenarios';
import { orderFactory } from '@0x/order-utils/lib/src/order_factory';
import { SignedOrder } from '@0x/types';
import { BigNumber } from '@0x/utils';
import { SupportedProvider } from 'ethereum-types';
import * as _ from 'lodash';
import { SwapQuote } from '../../src';
const ZERO_BIG_NUMBER = new BigNumber(0);
export const getSignedOrdersWithNoFees = (makerAssetData: string, takerAssetData: string, makerAddress: string, takerAddress: string, fillableAmounts: BigNumber[]): SignedOrder[] => {
return _.map(fillableAmounts, (fillableAmount: BigNumber) => orderFactory.createSignedOrderFromPartial(
{
export const getSignedOrdersWithNoFees = (
makerAssetData: string,
takerAssetData: string,
makerAddress: string,
takerAddress: string,
fillableAmounts: BigNumber[],
): SignedOrder[] => {
return _.map(fillableAmounts, (fillableAmount: BigNumber) =>
orderFactory.createSignedOrderFromPartial({
makerAddress,
makerAssetAmount: fillableAmount,
makerAssetData,
takerAssetAmount: fillableAmount,
takerAssetData,
}));
}),
);
};
export const getFullyFillableSwapQuoteWithNoFees = (makerAssetData: string, takerAssetData: string, orders: SignedOrder[]): SwapQuote => {
const makerAssetFillAmount = _.reduce(orders, (a: BigNumber, c: SignedOrder) => a.plus(c.makerAssetAmount), ZERO_BIG_NUMBER);
const totalTakerTokenAmount = _.reduce(orders, (a: BigNumber, c: SignedOrder) => a.plus(c.takerAssetAmount), ZERO_BIG_NUMBER);
export const getFullyFillableSwapQuoteWithNoFees = (
makerAssetData: string,
takerAssetData: string,
orders: SignedOrder[],
): SwapQuote => {
const makerAssetFillAmount = _.reduce(
orders,
(a: BigNumber, c: SignedOrder) => a.plus(c.makerAssetAmount),
ZERO_BIG_NUMBER,
);
const totalTakerTokenAmount = _.reduce(
orders,
(a: BigNumber, c: SignedOrder) => a.plus(c.takerAssetAmount),
ZERO_BIG_NUMBER,
);
const quoteInfo = {
takerTokenAmount: totalTakerTokenAmount,
feeTakerTokenAmount: ZERO_BIG_NUMBER,
totalTakerTokenAmount,
takerTokenAmount: totalTakerTokenAmount,
feeTakerTokenAmount: ZERO_BIG_NUMBER,
totalTakerTokenAmount,
};
return {