fixed wrappers usage in contract-wrappers

This commit is contained in:
David Sun
2019-11-22 10:33:11 -05:00
committed by Jacob Evans
parent a83bc53c6a
commit 79784fc8ee
9 changed files with 131 additions and 94 deletions

View File

@@ -135,13 +135,17 @@ export class ExchangeSwapQuoteConsumer implements SwapQuoteConsumerBase<Exchange
const { orders, gasPrice } = quote;
const finalTakerAddress = await swapQuoteConsumerUtils.getTakerAddressOrThrowAsync(this.provider, opts);
const value = ethAmount || quote.worstCaseQuoteInfo.protocolFeeInEthAmount;
const value = ethAmount || quote.worstCaseQuoteInfo.protocolFeeInWeiAmount;
let txHash: string;
if (quote.type === MarketOperation.Buy) {
const { makerAssetFillAmount } = quote;
txHash = await this._exchangeContract
.marketBuyOrdersFillOrKill(orders, makerAssetFillAmount, orders.map(o => o.signature))
.sendTransactionAsync({
.marketBuyOrdersFillOrKill
.sendTransactionAsync(
orders,
makerAssetFillAmount,
orders.map(o => o.signature),
{
from: finalTakerAddress,
gas: gasLimit,
gasPrice,
@@ -150,8 +154,12 @@ export class ExchangeSwapQuoteConsumer implements SwapQuoteConsumerBase<Exchange
} else {
const { takerAssetFillAmount } = quote;
txHash = await this._exchangeContract
.marketSellOrdersFillOrKill(orders, takerAssetFillAmount, orders.map(o => o.signature))
.sendTransactionAsync({
.marketSellOrdersFillOrKill
.sendTransactionAsync(
orders,
takerAssetFillAmount,
orders.map(o => o.signature),
{
from: finalTakerAddress,
gas: gasLimit,
gasPrice,

View File

@@ -189,14 +189,14 @@ export class ForwarderSwapQuoteConsumer implements SwapQuoteConsumerBase<Forward
if (quote.type === MarketOperation.Buy) {
const { makerAssetFillAmount } = quote;
txHash = await this._forwarder
.marketBuyOrdersWithEth(
.marketBuyOrdersWithEth
.sendTransactionAsync(
orders,
makerAssetFillAmount,
orders.map(o => o.signature),
formattedFeePercentage,
feeRecipient,
)
.sendTransactionAsync({
{
from: finalTakerAddress,
gas: gasLimit,
gasPrice,
@@ -204,8 +204,10 @@ export class ForwarderSwapQuoteConsumer implements SwapQuoteConsumerBase<Forward
});
} else {
txHash = await this._forwarder
.marketSellOrdersWithEth(orders, orders.map(o => o.signature), formattedFeePercentage, feeRecipient)
.sendTransactionAsync({
.marketSellOrdersWithEth
.sendTransactionAsync(
orders, orders.map(o => o.signature), formattedFeePercentage, feeRecipient,
{
from: finalTakerAddress,
gas: gasLimit,
gasPrice,
@@ -219,6 +221,6 @@ export class ForwarderSwapQuoteConsumer implements SwapQuoteConsumerBase<Forward
}
private async _getEtherTokenAssetDataOrThrowAsync(): Promise<string> {
return this._devUtils.encodeERC20AssetData(this._contractAddresses.etherToken).callAsync();
return this._devUtils.encodeERC20AssetData.callAsync(this._contractAddresses.etherToken);
}
}

View File

@@ -1,5 +1,6 @@
import { ContractAddresses, getContractAddressesForChainOrThrow } from '@0x/contract-addresses';
import { DevUtilsContract } from '@0x/contracts-dev-utils';
import { ExchangeContract } from '@0x/contracts-exchange';
import { schemas } from '@0x/json-schemas';
import { SignedOrder } from '@0x/order-utils';
import { MeshOrderProviderOpts, Orderbook, SRAPollingOrderProviderOpts } from '@0x/orderbook';
@@ -26,7 +27,6 @@ import { OrderPruner } from './utils/order_prune_utils';
import { ProtocolFeeUtils } from './utils/protocol_fee_utils';
import { sortingUtils } from './utils/sorting_utils';
import { swapQuoteCalculator } from './utils/swap_quote_calculator';
import { ExchangeContract } from '@0x/contracts-exchange';
export class SwapQuoter {
public readonly provider: ZeroExProvider;
@@ -235,8 +235,8 @@ export class SwapQuoter {
assert.isETHAddressHex('makerTokenAddress', makerTokenAddress);
assert.isETHAddressHex('takerTokenAddress', takerTokenAddress);
assert.isBigNumber('makerAssetBuyAmount', makerAssetBuyAmount);
const makerAssetData = await this._devUtilsContract.encodeERC20AssetData(makerTokenAddress).callAsync();
const takerAssetData = await this._devUtilsContract.encodeERC20AssetData(takerTokenAddress).callAsync();
const makerAssetData = await this._devUtilsContract.encodeERC20AssetData.callAsync(makerTokenAddress);
const takerAssetData = await this._devUtilsContract.encodeERC20AssetData.callAsync(takerTokenAddress);
const swapQuote = this.getMarketBuySwapQuoteForAssetDataAsync(
makerAssetData,
takerAssetData,
@@ -265,8 +265,8 @@ export class SwapQuoter {
assert.isETHAddressHex('makerTokenAddress', makerTokenAddress);
assert.isETHAddressHex('takerTokenAddress', takerTokenAddress);
assert.isBigNumber('takerAssetSellAmount', takerAssetSellAmount);
const makerAssetData = await this._devUtilsContract.encodeERC20AssetData(makerTokenAddress).callAsync();
const takerAssetData = await this._devUtilsContract.encodeERC20AssetData(takerTokenAddress).callAsync();
const makerAssetData = await this._devUtilsContract.encodeERC20AssetData.callAsync(makerTokenAddress);
const takerAssetData = await this._devUtilsContract.encodeERC20AssetData.callAsync(takerTokenAddress);
const swapQuote = this.getMarketSellSwapQuoteForAssetDataAsync(
makerAssetData,
takerAssetData,
@@ -290,8 +290,8 @@ export class SwapQuoter {
): Promise<LiquidityForTakerMakerAssetDataPair> {
assert.isString('makerAssetData', makerAssetData);
assert.isString('takerAssetData', takerAssetData);
await this._devUtilsContract.revertIfInvalidAssetData(takerAssetData).callAsync();
await this._devUtilsContract.revertIfInvalidAssetData(makerAssetData).callAsync();
await this._devUtilsContract.revertIfInvalidAssetData.callAsync(takerAssetData);
await this._devUtilsContract.revertIfInvalidAssetData.callAsync(makerAssetData);
const assetPairs = await this.getAvailableMakerAssetDatasAsync(takerAssetData);
if (!assetPairs.includes(makerAssetData)) {
return {
@@ -311,7 +311,7 @@ export class SwapQuoter {
*/
public async getAvailableTakerAssetDatasAsync(makerAssetData: string): Promise<string[]> {
assert.isString('makerAssetData', makerAssetData);
await this._devUtilsContract.revertIfInvalidAssetData(makerAssetData).callAsync();
await this._devUtilsContract.revertIfInvalidAssetData.callAsync(makerAssetData);
const allAssetPairs = await this.orderbook.getAvailableAssetDatasAsync();
const assetPairs = allAssetPairs
.filter(pair => pair.assetDataA.assetData === makerAssetData)
@@ -326,7 +326,7 @@ export class SwapQuoter {
*/
public async getAvailableMakerAssetDatasAsync(takerAssetData: string): Promise<string[]> {
assert.isString('takerAssetData', takerAssetData);
await this._devUtilsContract.revertIfInvalidAssetData(takerAssetData).callAsync();
await this._devUtilsContract.revertIfInvalidAssetData.callAsync(takerAssetData);
const allAssetPairs = await this.orderbook.getAvailableAssetDatasAsync();
const assetPairs = allAssetPairs
.filter(pair => pair.assetDataB.assetData === takerAssetData)
@@ -347,8 +347,8 @@ export class SwapQuoter {
): Promise<boolean> {
assert.isString('makerAssetData', makerAssetData);
assert.isString('takerAssetData', takerAssetData);
await this._devUtilsContract.revertIfInvalidAssetData(makerAssetData).callAsync();
await this._devUtilsContract.revertIfInvalidAssetData(takerAssetData).callAsync();
await this._devUtilsContract.revertIfInvalidAssetData.callAsync(takerAssetData);
await this._devUtilsContract.revertIfInvalidAssetData.callAsync(makerAssetData);
const availableMakerAssetDatas = await this.getAvailableMakerAssetDatasAsync(takerAssetData);
return _.includes(availableMakerAssetDatas, makerAssetData);
}
@@ -364,8 +364,8 @@ export class SwapQuoter {
): Promise<PrunedSignedOrder[]> {
assert.isString('makerAssetData', makerAssetData);
assert.isString('takerAssetData', takerAssetData);
await this._devUtilsContract.revertIfInvalidAssetData(takerAssetData).callAsync();
await this._devUtilsContract.revertIfInvalidAssetData(makerAssetData).callAsync();
await this._devUtilsContract.revertIfInvalidAssetData.callAsync(takerAssetData);
await this._devUtilsContract.revertIfInvalidAssetData.callAsync(makerAssetData);
// get orders
const apiOrders = await this.orderbook.getOrdersAsync(makerAssetData, takerAssetData);
const orders = _.map(apiOrders, o => o.order);
@@ -384,8 +384,8 @@ export class SwapQuoter {
takerAddress: string,
): Promise<[boolean, boolean]> {
const balanceAndAllowance = await this._devUtilsContract
.getBalanceAndAssetProxyAllowance(takerAddress, swapQuote.takerAssetData)
.callAsync();
.getBalanceAndAssetProxyAllowance
.callAsync(takerAddress, swapQuote.takerAssetData);
return [
balanceAndAllowance[1].isGreaterThanOrEqualTo(swapQuote.bestCaseQuoteInfo.totalTakerAssetAmount),
balanceAndAllowance[1].isGreaterThanOrEqualTo(swapQuote.worstCaseQuoteInfo.totalTakerAssetAmount),
@@ -403,7 +403,7 @@ export class SwapQuoter {
* Utility function to get assetData for Ether token.
*/
public async getEtherTokenAssetDataOrThrowAsync(): Promise<string> {
return this._devUtilsContract.encodeERC20AssetData(this._contractAddresses.etherToken).callAsync();
return this._devUtilsContract.encodeERC20AssetData.callAsync(this._contractAddresses.etherToken);
}
/**

View File

@@ -26,8 +26,8 @@ export class OrderPruner {
const signatures = _.map(unsortedOrders, o => o.signature);
const [ordersInfo, fillableTakerAssetAmounts, isValidSignatures] = await this._devUtils
.getOrderRelevantStates(unsortedOrders, signatures)
.callAsync();
.getOrderRelevantStates
.callAsync(unsortedOrders, signatures);
const ordersOnChainMetadata: OrderPrunerOnChainMetadata[] = ordersInfo.map((orderInfo, index) => {
return {
...orderInfo,

View File

@@ -55,7 +55,7 @@ export const swapQuoteConsumerUtils = {
const weth = new WETH9Contract(contractAddresses.etherToken, provider);
const web3Wrapper = new Web3Wrapper(provider);
const ethBalance = await web3Wrapper.getBalanceInWeiAsync(takerAddress);
const wethBalance = await weth.balanceOf(takerAddress).callAsync();
const wethBalance = await weth.balanceOf.callAsync(takerAddress);
return [ethBalance, wethBalance];
},
isValidForwarderSwapQuote(swapQuote: SwapQuote, wethAssetData: string): boolean {
@@ -74,7 +74,7 @@ export const swapQuoteConsumerUtils = {
opts: Partial<GetExtensionContractTypeOpts>,
): Promise<ExtensionContractType> {
const devUtils = new DevUtilsContract(contractAddresses.devUtils, provider);
const wethAssetData = await devUtils.encodeERC20AssetData(contractAddresses.etherToken).callAsync();
const wethAssetData = await devUtils.encodeERC20AssetData.callAsync(contractAddresses.etherToken);
if (swapQuoteConsumerUtils.isValidForwarderSwapQuote(quote, wethAssetData)) {
if (opts.takerAddress !== undefined) {
assert.isETHAddressHex('takerAddress', opts.takerAddress);

View File

@@ -61,14 +61,13 @@ const expectMakerAndTakerBalancesAsyncFactory = (
makerAddress: string,
takerAddress: string,
) => async (expectedMakerBalance: BigNumber, expectedTakerBalance: BigNumber) => {
const makerBalance = await erc20TokenContract.balanceOf(makerAddress).callAsync();
const takerBalance = await erc20TokenContract.balanceOf(takerAddress).callAsync();
const makerBalance = await erc20TokenContract.balanceOf.callAsync(makerAddress);
const takerBalance = await erc20TokenContract.balanceOf.callAsync(takerAddress);
expect(makerBalance).to.bignumber.equal(expectedMakerBalance);
expect(takerBalance).to.bignumber.equal(expectedTakerBalance);
};
describe('ExchangeSwapQuoteConsumer', () => {
let contractWrappers: ContractWrappers;
let protocolFeeUtils: ProtocolFeeUtils;
let userAddresses: string[];
let erc20MakerTokenContract: ERC20TokenContract;
@@ -109,9 +108,9 @@ describe('ExchangeSwapQuoteConsumer', () => {
[makerTokenAddress, takerTokenAddress] = tokenUtils.getDummyERC20TokenAddresses();
const devUtils = new DevUtilsContract(contractAddresses.devUtils, provider);
[makerAssetData, takerAssetData, wethAssetData] = await Promise.all([
devUtils.encodeERC20AssetData(makerTokenAddress).callAsync(),
devUtils.encodeERC20AssetData(takerTokenAddress).callAsync(),
devUtils.encodeERC20AssetData(contractAddresses.etherToken).callAsync(),
devUtils.encodeERC20AssetData.callAsync(makerTokenAddress),
devUtils.encodeERC20AssetData.callAsync(takerTokenAddress),
devUtils.encodeERC20AssetData.callAsync(contractAddresses.etherToken),
]);
erc20MakerTokenContract = new ERC20TokenContract(makerTokenAddress, provider);
erc20TakerTokenContract = new ERC20TokenContract(takerTokenAddress, provider);
@@ -133,7 +132,7 @@ describe('ExchangeSwapQuoteConsumer', () => {
};
const privateKey = devConstants.TESTRPC_PRIVATE_KEYS[userAddresses.indexOf(makerAddress)];
orderFactory = new OrderFactory(privateKey, defaultOrderParams);
protocolFeeUtils = new ProtocolFeeUtils(contractWrappers.exchange);
protocolFeeUtils = new ProtocolFeeUtils(exchangeContract);
expectMakerAndTakerBalancesForTakerAssetAsync = expectMakerAndTakerBalancesAsyncFactory(
erc20TakerTokenContract,
makerAddress,
@@ -183,21 +182,31 @@ describe('ExchangeSwapQuoteConsumer', () => {
});
await erc20MakerTokenContract
.transfer(makerAddress, marketBuySwapQuote.worstCaseQuoteInfo.makerAssetAmount)
.sendTransactionAsync({
.transfer
.sendTransactionAsync(
makerAddress, marketBuySwapQuote.worstCaseQuoteInfo.makerAssetAmount,
{
from: coinbaseAddress,
});
await erc20TakerTokenContract
.transfer(takerAddress, marketBuySwapQuote.worstCaseQuoteInfo.totalTakerAssetAmount)
.sendTransactionAsync({
.transfer
.sendTransactionAsync(
takerAddress, marketBuySwapQuote.worstCaseQuoteInfo.totalTakerAssetAmount,
{
from: coinbaseAddress,
});
await erc20MakerTokenContract
.approve(contractAddresses.erc20Proxy, UNLIMITED_ALLOWANCE)
.sendTransactionAsync({ from: makerAddress });
.approve
.sendTransactionAsync(
contractAddresses.erc20Proxy,
UNLIMITED_ALLOWANCE,
{ from: makerAddress });
await erc20TakerTokenContract
.approve(contractAddresses.erc20Proxy, UNLIMITED_ALLOWANCE)
.sendTransactionAsync({ from: takerAddress });
.approve
.sendTransactionAsync(
contractAddresses.erc20Proxy,
UNLIMITED_ALLOWANCE,
{ from: takerAddress });
});
afterEach(async () => {
await blockchainLifecycle.revertAsync();

View File

@@ -1,6 +1,7 @@
import { ContractAddresses } from '@0x/contract-addresses';
import { DevUtilsContract } from '@0x/contracts-dev-utils';
import { ERC20TokenContract } from '@0x/contracts-erc20';
import { ExchangeContract } from '@0x/contracts-exchange';
import { ForwarderContract } from '@0x/contracts-exchange-forwarder';
import { constants as devConstants, OrderFactory } from '@0x/contracts-test-utils';
import { BlockchainLifecycle, tokenUtils } from '@0x/dev-utils';
@@ -61,16 +62,14 @@ const expectMakerAndTakerBalancesAsyncFactory = (
makerAddress: string,
takerAddress: string,
) => async (expectedMakerBalance: BigNumber, expectedTakerBalance: BigNumber) => {
const makerBalance = await erc20TokenContract.balanceOf(makerAddress).callAsync();
const takerBalance = await erc20TokenContract.balanceOf(takerAddress).callAsync();
const makerBalance = await erc20TokenContract.balanceOf.callAsync(makerAddress);
const takerBalance = await erc20TokenContract.balanceOf.callAsync(takerAddress);
expect(makerBalance).to.bignumber.equal(expectedMakerBalance);
expect(takerBalance).to.bignumber.equal(expectedTakerBalance);
};
describe('ForwarderSwapQuoteConsumer', () => {
let contractWrappers: ContractWrappers;
let protocolFeeUtils: ProtocolFeeUtils;
let erc20Token: ERC20TokenContract;
let userAddresses: string[];
let coinbaseAddress: string;
let makerAddress: string;
@@ -86,6 +85,7 @@ describe('ForwarderSwapQuoteConsumer', () => {
let contractAddresses: ContractAddresses;
let erc20TokenContract: ERC20TokenContract;
let forwarderContract: ForwarderContract;
let exchangeContract: ExchangeContract;
let orders: PrunedSignedOrder[];
let invalidOrders: PrunedSignedOrder[];
@@ -107,11 +107,12 @@ describe('ForwarderSwapQuoteConsumer', () => {
[makerTokenAddress, takerTokenAddress] = tokenUtils.getDummyERC20TokenAddresses();
erc20TokenContract = new ERC20TokenContract(makerTokenAddress, provider);
forwarderContract = new ForwarderContract(contractAddresses.forwarder, provider);
exchangeContract = new ExchangeContract(contractAddresses.exchange, provider);
const devUtils = new DevUtilsContract(contractAddresses.devUtils, provider);
[makerAssetData, takerAssetData, wethAssetData] = await Promise.all([
devUtils.encodeERC20AssetData(makerTokenAddress).callAsync(),
devUtils.encodeERC20AssetData(takerTokenAddress).callAsync(),
devUtils.encodeERC20AssetData(contractAddresses.etherToken).callAsync(),
devUtils.encodeERC20AssetData.callAsync(makerTokenAddress),
devUtils.encodeERC20AssetData.callAsync(takerTokenAddress),
devUtils.encodeERC20AssetData.callAsync(contractAddresses.etherToken),
]);
// Configure order defaults
const defaultOrderParams = {
@@ -136,7 +137,7 @@ describe('ForwarderSwapQuoteConsumer', () => {
};
const privateKey = devConstants.TESTRPC_PRIVATE_KEYS[userAddresses.indexOf(makerAddress)];
orderFactory = new OrderFactory(privateKey, defaultOrderParams);
protocolFeeUtils = new ProtocolFeeUtils(contractWrappers.exchange);
protocolFeeUtils = new ProtocolFeeUtils(exchangeContract);
expectMakerAndTakerBalancesAsync = expectMakerAndTakerBalancesAsyncFactory(
erc20TokenContract,
makerAddress,
@@ -153,15 +154,18 @@ describe('ForwarderSwapQuoteConsumer', () => {
const totalFillableAmount = new BigNumber(10).multipliedBy(ONE_ETH_IN_WEI);
await erc20TokenContract.transfer(makerAddress, totalFillableAmount).sendTransactionAsync({
await erc20TokenContract.transfer.sendTransactionAsync(
makerAddress,
totalFillableAmount,
{
from: coinbaseAddress,
});
await erc20TokenContract
.approve(contractAddresses.erc20Proxy, UNLIMITED_ALLOWANCE)
.sendTransactionAsync({ from: makerAddress });
.approve
.sendTransactionAsync(contractAddresses.erc20Proxy, UNLIMITED_ALLOWANCE, { from: makerAddress });
await forwarderContract.approveMakerAssetProxy(makerAssetData).sendTransactionAsync({ from: makerAddress });
await forwarderContract.approveMakerAssetProxy.sendTransactionAsync(makerAssetData, { from: makerAddress });
orders = [];
for (const partialOrder of PARTIAL_PRUNED_SIGNED_ORDERS_FEELESS) {
@@ -257,7 +261,6 @@ describe('ForwarderSwapQuoteConsumer', () => {
);
await swapQuoteConsumer.executeSwapQuoteOrThrowAsync(marketSellSwapQuote, {
takerAddress,
gasPrice: GAS_PRICE,
gasLimit: 4000000,
});
await expectMakerAndTakerBalancesAsync(
@@ -274,7 +277,6 @@ describe('ForwarderSwapQuoteConsumer', () => {
const feeRecipientEthBalanceBefore = await web3Wrapper.getBalanceInWeiAsync(feeRecipient);
await swapQuoteConsumer.executeSwapQuoteOrThrowAsync(marketBuySwapQuote, {
takerAddress,
gasPrice: GAS_PRICE,
gasLimit: 4000000,
extensionContractOpts: {
feePercentage: 0.05,
@@ -287,7 +289,7 @@ describe('ForwarderSwapQuoteConsumer', () => {
);
const feeRecipientEthBalanceAfter = await web3Wrapper.getBalanceInWeiAsync(feeRecipient);
const totalEthSpent = marketBuySwapQuote.bestCaseQuoteInfo.totalTakerAssetAmount.plus(
marketBuySwapQuote.bestCaseQuoteInfo.protocolFeeInEthAmount,
marketBuySwapQuote.bestCaseQuoteInfo.protocolFeeInWeiAmount,
);
expect(feeRecipientEthBalanceAfter.minus(feeRecipientEthBalanceBefore)).to.bignumber.equal(
new BigNumber(FEE_PERCENTAGE).times(totalEthSpent),
@@ -314,7 +316,7 @@ describe('ForwarderSwapQuoteConsumer', () => {
);
const feeRecipientEthBalanceAfter = await web3Wrapper.getBalanceInWeiAsync(feeRecipient);
const totalEthSpent = marketBuySwapQuote.bestCaseQuoteInfo.totalTakerAssetAmount.plus(
marketBuySwapQuote.bestCaseQuoteInfo.protocolFeeInEthAmount,
marketBuySwapQuote.bestCaseQuoteInfo.protocolFeeInWeiAmount,
);
expect(feeRecipientEthBalanceAfter.minus(feeRecipientEthBalanceBefore)).to.bignumber.equal(
new BigNumber(FEE_PERCENTAGE).times(totalEthSpent),
@@ -513,7 +515,7 @@ describe('ForwarderSwapQuoteConsumer', () => {
new BigNumber(10).multipliedBy(ONE_ETH_IN_WEI),
);
const totalEthSpent = marketBuySwapQuote.bestCaseQuoteInfo.totalTakerAssetAmount.plus(
marketBuySwapQuote.bestCaseQuoteInfo.protocolFeeInEthAmount,
marketBuySwapQuote.bestCaseQuoteInfo.protocolFeeInWeiAmount,
);
const feeRecipientEthBalanceAfter = await web3Wrapper.getBalanceInWeiAsync(feeRecipient);
expect(feeRecipientEthBalanceAfter.minus(feeRecipientEthBalanceBefore)).to.bignumber.equal(
@@ -549,7 +551,7 @@ describe('ForwarderSwapQuoteConsumer', () => {
new BigNumber(10).multipliedBy(ONE_ETH_IN_WEI),
);
const totalEthSpent = marketBuySwapQuote.bestCaseQuoteInfo.totalTakerAssetAmount.plus(
marketBuySwapQuote.bestCaseQuoteInfo.protocolFeeInEthAmount,
marketBuySwapQuote.bestCaseQuoteInfo.protocolFeeInWeiAmount,
);
const feeRecipientEthBalanceAfter = await web3Wrapper.getBalanceInWeiAsync(feeRecipient);
expect(feeRecipientEthBalanceAfter.minus(feeRecipientEthBalanceBefore)).to.bignumber.equal(

View File

@@ -25,7 +25,8 @@ const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);
const ONE_ETH_IN_WEI = new BigNumber(1000000000000000000);
const TESTRPC_CHAIN_ID = devConstants.TESTRPC_CHAIN_ID;
const GAS_PRICE = new BigNumber(devConstants.DEFAULT_GAS_PRICE);
const PROTOCOL_FEE_PER_FILL = GAS_PRICE.times(constants.PROTOCOL_FEE_MULTIPLIER);
const PROTOCOL_FEE_MULTIPLIER = 150000;
const PROTOCOL_FEE_PER_FILL = GAS_PRICE.times(PROTOCOL_FEE_MULTIPLIER);
const UNLIMITED_ALLOWANCE_IN_BASE_UNITS = new BigNumber(2).pow(256).minus(1); // tslint:disable-line:custom-no-magic-numbers
// tslint:disable: no-unused-expression
@@ -122,20 +123,32 @@ describe('OrderPruner', () => {
// give double fillableAmount to maker and taker as buffer
await erc20MakerTokenContract
.transfer(makerAddress, fillableAmount.multipliedBy(4))
.sendTransactionAsync({ from: coinbaseAddress });
.transfer
.sendTransactionAsync(
makerAddress,
fillableAmount.multipliedBy(4),
{ from: coinbaseAddress });
await erc20TakerTokenContract
.transfer(takerAddress, fillableAmount.multipliedBy(4))
.sendTransactionAsync({ from: coinbaseAddress });
.transfer
.sendTransactionAsync(
takerAddress,
fillableAmount.multipliedBy(4),
{ from: coinbaseAddress });
await erc20MakerTokenContract
.approve(contractAddresses.erc20Proxy, UNLIMITED_ALLOWANCE_IN_BASE_UNITS)
.sendTransactionAsync({ from: makerAddress });
.approve
.sendTransactionAsync(
contractAddresses.erc20Proxy, UNLIMITED_ALLOWANCE_IN_BASE_UNITS,
{ from: makerAddress });
await erc20MakerTokenContract
.approve(contractAddresses.erc20Proxy, UNLIMITED_ALLOWANCE_IN_BASE_UNITS)
.sendTransactionAsync({ from: takerAddress });
.approve
.sendTransactionAsync(
contractAddresses.erc20Proxy, UNLIMITED_ALLOWANCE_IN_BASE_UNITS,
{ from: takerAddress });
await erc20TakerTokenContract
.approve(contractAddresses.erc20Proxy, UNLIMITED_ALLOWANCE_IN_BASE_UNITS)
.sendTransactionAsync({ from: takerAddress });
.approve
.sendTransactionAsync(
contractAddresses.erc20Proxy, UNLIMITED_ALLOWANCE_IN_BASE_UNITS,
{ from: takerAddress });
partiallyFilledOpenSignedOrderFeeless = await orderFactory.newSignedOrderAsync({
takerAssetAmount: fillableAmount,
@@ -143,12 +156,12 @@ describe('OrderPruner', () => {
});
await exchangeContract
.fillOrKillOrder(
.fillOrKillOrder
.sendTransactionAsync(
partiallyFilledOpenSignedOrderFeeless,
partialFillAmount,
partiallyFilledOpenSignedOrderFeeless.signature,
)
.sendTransactionAsync({
{
from: takerAddress,
gasPrice: GAS_PRICE,
gas: 4000000,
@@ -163,12 +176,12 @@ describe('OrderPruner', () => {
});
await exchangeContract
.fillOrKillOrder(
.fillOrKillOrder
.sendTransactionAsync(
partiallyFilledOpenSignedOrderFeeInTakerAsset,
partialFillAmount,
partiallyFilledOpenSignedOrderFeeInTakerAsset.signature,
)
.sendTransactionAsync({
{
from: takerAddress,
gasPrice: GAS_PRICE,
gas: 4000000,
@@ -183,12 +196,12 @@ describe('OrderPruner', () => {
});
await exchangeContract
.fillOrKillOrder(
.fillOrKillOrder
.sendTransactionAsync(
partiallyFilledOpenSignedOrderFeeInMakerAsset,
partialFillAmount,
partiallyFilledOpenSignedOrderFeeInMakerAsset.signature,
)
.sendTransactionAsync({
{
from: takerAddress,
gasPrice: GAS_PRICE,
gas: 4000000,
@@ -201,8 +214,10 @@ describe('OrderPruner', () => {
});
await exchangeContract
.fillOrKillOrder(filledOpenSignedOrder, fillableAmount, filledOpenSignedOrder.signature)
.sendTransactionAsync({
.fillOrKillOrder
.sendTransactionAsync(
filledOpenSignedOrder, fillableAmount, filledOpenSignedOrder.signature,
{
from: takerAddress,
gasPrice: GAS_PRICE,
gas: 4000000,

View File

@@ -1,6 +1,7 @@
import { ContractAddresses } from '@0x/contract-addresses';
import { DevUtilsContract } from '@0x/contracts-dev-utils';
import { WETH9Contract } from '@0x/contracts-erc20';
import { ExchangeContract } from '@0x/contracts-exchange';
import { constants as devConstants, OrderFactory } from '@0x/contracts-test-utils';
import { BlockchainLifecycle, tokenUtils } from '@0x/dev-utils';
import { migrateOnceAsync } from '@0x/migrations';
@@ -15,7 +16,6 @@ import { ProtocolFeeUtils } from '../src/utils/protocol_fee_utils';
import { chaiSetup } from './utils/chai_setup';
import { getFullyFillableSwapQuoteWithNoFeesAsync } from './utils/swap_quote';
import { provider, web3Wrapper } from './utils/web3_wrapper';
chaiSetup.configure();
@@ -70,8 +70,8 @@ const PARTIAL_LARGE_PRUNED_SIGNED_ORDERS: Array<Partial<PrunedSignedOrder>> = [
describe('swapQuoteConsumerUtils', () => {
let wethContract: WETH9Contract;
let contractWrappers: ContractWrappers;
let protocolFeeUtils: ProtocolFeeUtils;
let exchangeContract: ExchangeContract;
let userAddresses: string[];
let makerAddress: string;
let takerAddress: string;
@@ -92,12 +92,13 @@ describe('swapQuoteConsumerUtils', () => {
userAddresses = await web3Wrapper.getAvailableAddressesAsync();
const devUtils = new DevUtilsContract(contractAddresses.devUtils, provider);
wethContract = new WETH9Contract(contractAddresses.etherToken, provider);
exchangeContract = new ExchangeContract(contractAddresses.exchange, provider);
[takerAddress, makerAddress] = userAddresses;
[makerTokenAddress, takerTokenAddress] = tokenUtils.getDummyERC20TokenAddresses();
[makerAssetData, takerAssetData, wethAssetData] = [
await devUtils.encodeERC20AssetData(makerTokenAddress).callAsync(),
await devUtils.encodeERC20AssetData(takerTokenAddress).callAsync(),
await devUtils.encodeERC20AssetData(contractAddresses.etherToken).callAsync(),
await devUtils.encodeERC20AssetData.callAsync(makerTokenAddress),
await devUtils.encodeERC20AssetData.callAsync(takerTokenAddress),
await devUtils.encodeERC20AssetData.callAsync(contractAddresses.etherToken),
];
const defaultOrderParams = {
@@ -122,7 +123,7 @@ describe('swapQuoteConsumerUtils', () => {
};
const privateKey = devConstants.TESTRPC_PRIVATE_KEYS[userAddresses.indexOf(makerAddress)];
orderFactory = new OrderFactory(privateKey, defaultOrderParams);
protocolFeeUtils = new ProtocolFeeUtils(contractWrappers.exchange);
protocolFeeUtils = new ProtocolFeeUtils(exchangeContract);
forwarderOrderFactory = new OrderFactory(privateKey, defaultForwarderOrderParams);
swapQuoteConsumer = new SwapQuoteConsumer(provider, {
@@ -222,7 +223,7 @@ describe('swapQuoteConsumerUtils', () => {
});
it('should return exchange consumer if takerAsset is wEth and taker has enough weth', async () => {
const etherInWei = new BigNumber(20).multipliedBy(ONE_ETH_IN_WEI);
await wethContract.deposit().sendTransactionAsync({ value: etherInWei, from: takerAddress });
await wethContract.deposit.sendTransactionAsync({ value: etherInWei, from: takerAddress });
const extensionContractType = await swapQuoteConsumer.getOptimalExtensionContractTypeAsync(
forwarderSwapQuote,
{ takerAddress },
@@ -231,7 +232,7 @@ describe('swapQuoteConsumerUtils', () => {
});
it('should return forwarder consumer if takerAsset is wEth and takerAddress has no available balance in either weth or eth (defaulting behavior)', async () => {
const etherInWei = new BigNumber(50).multipliedBy(ONE_ETH_IN_WEI);
await wethContract.deposit().sendTransactionAsync({ value: etherInWei, from: takerAddress });
await wethContract.deposit.sendTransactionAsync({ value: etherInWei, from: takerAddress });
const extensionContractType = await swapQuoteConsumer.getOptimalExtensionContractTypeAsync(
largeForwarderSwapQuote,
{ takerAddress },