refactored sampler operations into a single external file

This commit is contained in:
Daniel Pyrathon 2020-03-02 10:06:43 -08:00
parent 82b0f85258
commit 82de5adbe9
13 changed files with 1534 additions and 1479 deletions

View File

@ -144,11 +144,13 @@ export class SwapQuoter {
* @return An instance of SwapQuoter * @return An instance of SwapQuoter
*/ */
constructor(supportedProvider: SupportedProvider, orderbook: Orderbook, options: Partial<SwapQuoterOpts> = {}) { constructor(supportedProvider: SupportedProvider, orderbook: Orderbook, options: Partial<SwapQuoterOpts> = {}) {
const { chainId, expiryBufferMs, permittedOrderFeeTypes, samplerGasLimit, liquidityProviderRegistryAddress } = _.merge( const {
{}, chainId,
constants.DEFAULT_SWAP_QUOTER_OPTS, expiryBufferMs,
options, permittedOrderFeeTypes,
); samplerGasLimit,
liquidityProviderRegistryAddress,
} = _.merge({}, constants.DEFAULT_SWAP_QUOTER_OPTS, options);
const provider = providerUtils.standardizeOrThrow(supportedProvider); const provider = providerUtils.standardizeOrThrow(supportedProvider);
assert.isValidOrderbook('orderbook', orderbook); assert.isValidOrderbook('orderbook', orderbook);
assert.isNumber('chainId', chainId); assert.isNumber('chainId', chainId);

View File

@ -98,7 +98,9 @@ export class CreateOrderUtils {
return this._contractAddress.curveBridge; return this._contractAddress.curveBridge;
case ERC20BridgeSource.LiquidityProvider: case ERC20BridgeSource.LiquidityProvider:
if (liquidityPoolAddress === undefined) { if (liquidityPoolAddress === undefined) {
throw new Error('Cannot create a LiquidityProvider order without a LiquidityProvider pool address.'); throw new Error(
'Cannot create a LiquidityProvider order without a LiquidityProvider pool address.',
);
} }
assert.isETHAddressHex('liquidityPoolAddress', liquidityPoolAddress); assert.isETHAddressHex('liquidityPoolAddress', liquidityPoolAddress);
return liquidityPoolAddress; return liquidityPoolAddress;

View File

@ -73,13 +73,24 @@ export class MarketOperationUtils {
...opts, ...opts,
}; };
const [makerToken, takerToken] = getOrderTokens(nativeOrders[0]); const [makerToken, takerToken] = getOrderTokens(nativeOrders[0]);
const [fillableAmounts, liquidityPoolAddress, ethToMakerAssetRate, dexQuotes] = await this._sampler.executeAsync( const [
fillableAmounts,
liquidityPoolAddress,
ethToMakerAssetRate,
dexQuotes,
] = await this._sampler.executeAsync(
DexOrderSampler.ops.getOrderFillableTakerAmounts(nativeOrders), DexOrderSampler.ops.getOrderFillableTakerAmounts(nativeOrders),
DexOrderSampler.ops.getLiquidityProviderFromRegistry(this._liquidityProviderRegistry, takerToken, makerToken), DexOrderSampler.ops.getLiquidityProviderFromRegistry(
this._liquidityProviderRegistry,
takerToken,
makerToken,
),
makerToken.toLowerCase() === this._wethAddress.toLowerCase() makerToken.toLowerCase() === this._wethAddress.toLowerCase()
? DexOrderSampler.ops.constant(new BigNumber(1)) ? DexOrderSampler.ops.constant(new BigNumber(1))
: DexOrderSampler.ops.getMedianSellRate( : DexOrderSampler.ops.getMedianSellRate(
difference(FEE_QUOTE_SOURCES, _opts.excludedSources).concat(this._liquidityPoolSourceIfAvailable()), difference(FEE_QUOTE_SOURCES, _opts.excludedSources).concat(
this._liquidityPoolSourceIfAvailable(),
),
makerToken, makerToken,
this._wethAddress, this._wethAddress,
ONE_ETHER, ONE_ETHER,
@ -160,13 +171,24 @@ export class MarketOperationUtils {
...opts, ...opts,
}; };
const [makerToken, takerToken] = getOrderTokens(nativeOrders[0]); const [makerToken, takerToken] = getOrderTokens(nativeOrders[0]);
const [fillableAmounts, liquidityPoolAddress, ethToTakerAssetRate, dexQuotes] = await this._sampler.executeAsync( const [
fillableAmounts,
liquidityPoolAddress,
ethToTakerAssetRate,
dexQuotes,
] = await this._sampler.executeAsync(
DexOrderSampler.ops.getOrderFillableMakerAmounts(nativeOrders), DexOrderSampler.ops.getOrderFillableMakerAmounts(nativeOrders),
DexOrderSampler.ops.getLiquidityProviderFromRegistry(this._liquidityProviderRegistry, takerToken, makerToken), DexOrderSampler.ops.getLiquidityProviderFromRegistry(
this._liquidityProviderRegistry,
takerToken,
makerToken,
),
takerToken.toLowerCase() === this._wethAddress.toLowerCase() takerToken.toLowerCase() === this._wethAddress.toLowerCase()
? DexOrderSampler.ops.constant(new BigNumber(1)) ? DexOrderSampler.ops.constant(new BigNumber(1))
: DexOrderSampler.ops.getMedianSellRate( : DexOrderSampler.ops.getMedianSellRate(
difference(FEE_QUOTE_SOURCES, _opts.excludedSources).concat(this._liquidityPoolSourceIfAvailable()), difference(FEE_QUOTE_SOURCES, _opts.excludedSources).concat(
this._liquidityPoolSourceIfAvailable(),
),
takerToken, takerToken,
this._wethAddress, this._wethAddress,
ONE_ETHER, ONE_ETHER,

View File

@ -1,10 +1,7 @@
import { IERC20BridgeSamplerContract } from '@0x/contract-wrappers'; import { IERC20BridgeSamplerContract } from '@0x/contract-wrappers';
import { SignedOrder } from '@0x/types';
import { BigNumber } from '@0x/utils'; import { BigNumber } from '@0x/utils';
import { constants } from '../../constants'; import { samplerOperations } from './sampler_operations';
import { DexSample, ERC20BridgeSource } from './types';
/** /**
* A composable operation the be run in `DexOrderSampler.executeAsync()`. * A composable operation the be run in `DexOrderSampler.executeAsync()`.
@ -14,369 +11,6 @@ export interface BatchedOperation<TResult> {
handleCallResultsAsync(contract: IERC20BridgeSamplerContract, callResults: string): Promise<TResult>; handleCallResultsAsync(contract: IERC20BridgeSamplerContract, callResults: string): Promise<TResult>;
} }
/**
* Composable operations that can be batched in a single transaction,
* for use with `DexOrderSampler.executeAsync()`.
*/
const samplerOperations = {
getOrderFillableTakerAmounts(orders: SignedOrder[]): BatchedOperation<BigNumber[]> {
return {
encodeCall: contract => {
return contract
.getOrderFillableTakerAssetAmounts(orders, orders.map(o => o.signature))
.getABIEncodedTransactionData();
},
handleCallResultsAsync: async (contract, callResults) => {
return contract.getABIDecodedReturnData<BigNumber[]>('getOrderFillableTakerAssetAmounts', callResults);
},
};
},
getOrderFillableMakerAmounts(orders: SignedOrder[]): BatchedOperation<BigNumber[]> {
return {
encodeCall: contract => {
return contract
.getOrderFillableMakerAssetAmounts(orders, orders.map(o => o.signature))
.getABIEncodedTransactionData();
},
handleCallResultsAsync: async (contract, callResults) => {
return contract.getABIDecodedReturnData<BigNumber[]>('getOrderFillableMakerAssetAmounts', callResults);
},
};
},
getKyberSellQuotes(
makerToken: string,
takerToken: string,
takerFillAmounts: BigNumber[],
): BatchedOperation<BigNumber[]> {
return {
encodeCall: contract => {
return contract
.sampleSellsFromKyberNetwork(takerToken, makerToken, takerFillAmounts)
.getABIEncodedTransactionData();
},
handleCallResultsAsync: async (contract, callResults) => {
return contract.getABIDecodedReturnData<BigNumber[]>('sampleSellsFromKyberNetwork', callResults);
},
};
},
getUniswapSellQuotes(
makerToken: string,
takerToken: string,
takerFillAmounts: BigNumber[],
): BatchedOperation<BigNumber[]> {
return {
encodeCall: contract => {
return contract
.sampleSellsFromUniswap(takerToken, makerToken, takerFillAmounts)
.getABIEncodedTransactionData();
},
handleCallResultsAsync: async (contract, callResults) => {
return contract.getABIDecodedReturnData<BigNumber[]>('sampleSellsFromUniswap', callResults);
},
};
},
getLiquidityProviderSellQuotes(
liquidityProviderRegistryAddress: string,
takerToken: string,
makerToken: string,
takerFillAmounts: BigNumber[],
): BatchedOperation<BigNumber[]> {
return {
encodeCall: contract => {
return contract
.sampleSellsFromLiquidityProviderRegistry(
liquidityProviderRegistryAddress,
takerToken,
makerToken,
takerFillAmounts,
)
.getABIEncodedTransactionData();
},
handleCallResultsAsync: async (contract, callResults) => {
return contract.getABIDecodedReturnData<BigNumber[]>(
'sampleSellsFromLiquidityProviderRegistry',
callResults,
);
},
};
},
getLiquidityProviderBuyQuotes(
liquidityProviderRegistryAddress: string,
takerToken: string,
makerToken: string,
makerFillAmounts: BigNumber[],
): BatchedOperation<BigNumber[]> {
return {
encodeCall: contract => {
return contract
.sampleBuysFromLiquidityProviderRegistry(
liquidityProviderRegistryAddress,
takerToken,
makerToken,
makerFillAmounts,
)
.getABIEncodedTransactionData();
},
handleCallResultsAsync: async (contract, callResults) => {
return contract.getABIDecodedReturnData<BigNumber[]>(
'sampleBuysFromLiquidityProviderRegistry',
callResults,
);
},
};
},
getEth2DaiSellQuotes(
makerToken: string,
takerToken: string,
takerFillAmounts: BigNumber[],
): BatchedOperation<BigNumber[]> {
return {
encodeCall: contract => {
return contract
.sampleSellsFromEth2Dai(takerToken, makerToken, takerFillAmounts)
.getABIEncodedTransactionData();
},
handleCallResultsAsync: async (contract, callResults) => {
return contract.getABIDecodedReturnData<BigNumber[]>('sampleSellsFromEth2Dai', callResults);
},
};
},
getCurveSellQuotes(
curveAddress: string,
fromTokenIdx: number,
toTokenIdx: number,
takerFillAmounts: BigNumber[],
): BatchedOperation<BigNumber[]> {
return {
encodeCall: contract => {
return contract
.sampleSellsFromCurve(
curveAddress,
new BigNumber(fromTokenIdx),
new BigNumber(toTokenIdx),
takerFillAmounts,
)
.getABIEncodedTransactionData();
},
handleCallResultsAsync: async (contract, callResults) => {
return contract.getABIDecodedReturnData<BigNumber[]>('sampleSellsFromCurve', callResults);
},
};
},
getUniswapBuyQuotes(
makerToken: string,
takerToken: string,
makerFillAmounts: BigNumber[],
): BatchedOperation<BigNumber[]> {
return {
encodeCall: contract => {
return contract
.sampleBuysFromUniswap(takerToken, makerToken, makerFillAmounts)
.getABIEncodedTransactionData();
},
handleCallResultsAsync: async (contract, callResults) => {
return contract.getABIDecodedReturnData<BigNumber[]>('sampleBuysFromUniswap', callResults);
},
};
},
getEth2DaiBuyQuotes(
makerToken: string,
takerToken: string,
makerFillAmounts: BigNumber[],
): BatchedOperation<BigNumber[]> {
return {
encodeCall: contract => {
return contract
.sampleBuysFromEth2Dai(takerToken, makerToken, makerFillAmounts)
.getABIEncodedTransactionData();
},
handleCallResultsAsync: async (contract, callResults) => {
return contract.getABIDecodedReturnData<BigNumber[]>('sampleBuysFromEth2Dai', callResults);
},
};
},
getMedianSellRate(
sources: ERC20BridgeSource[],
makerToken: string,
takerToken: string,
takerFillAmount: BigNumber,
liquidityProviderRegistryAddress?: string | undefined,
): BatchedOperation<BigNumber> {
const getSellQuotes = samplerOperations.getSellQuotes(
sources,
makerToken,
takerToken,
[takerFillAmount],
liquidityProviderRegistryAddress,
);
return {
encodeCall: contract => {
const subCalls = [getSellQuotes.encodeCall(contract)];
return contract.batchCall(subCalls).getABIEncodedTransactionData();
},
handleCallResultsAsync: async (contract, callResults) => {
const rawSubCallResults = contract.getABIDecodedReturnData<string[]>('batchCall', callResults);
const samples = await getSellQuotes.handleCallResultsAsync(contract, rawSubCallResults[0]);
if (samples.length === 0) {
return new BigNumber(0);
}
const flatSortedSamples = samples
.reduce((acc, v) => acc.concat(...v))
.sort((a, b) => a.output.comparedTo(b.output));
if (flatSortedSamples.length === 0) {
return new BigNumber(0);
}
const medianSample = flatSortedSamples[Math.floor(flatSortedSamples.length / 2)];
return medianSample.output.div(medianSample.input);
},
};
},
constant<T>(result: T): BatchedOperation<T> {
return {
encodeCall: contract => {
return '0x';
},
handleCallResultsAsync: async (contract, callResults) => {
return result;
},
};
},
getLiquidityProviderFromRegistry(
registryAddress: string,
takerToken: string,
makerToken: string,
): BatchedOperation<string> {
return {
encodeCall: contract => {
return contract
.getLiquidityProviderFromRegistry(registryAddress, takerToken, makerToken)
.getABIEncodedTransactionData();
},
handleCallResultsAsync: async (contract, callResults) => {
return contract.getABIDecodedReturnData<string>('getLiquidityProviderFromRegistry', callResults);
},
};
},
getSellQuotes(
sources: ERC20BridgeSource[],
makerToken: string,
takerToken: string,
takerFillAmounts: BigNumber[],
liquidityProviderRegistryAddress?: string | undefined,
): BatchedOperation<DexSample[][]> {
const subOps = sources
.map(source => {
let batchedOperation;
if (source === ERC20BridgeSource.Eth2Dai) {
batchedOperation = samplerOperations.getEth2DaiSellQuotes(makerToken, takerToken, takerFillAmounts);
} else if (source === ERC20BridgeSource.Uniswap) {
batchedOperation = samplerOperations.getUniswapSellQuotes(makerToken, takerToken, takerFillAmounts);
} else if (source === ERC20BridgeSource.Kyber) {
batchedOperation = samplerOperations.getKyberSellQuotes(makerToken, takerToken, takerFillAmounts);
} else if (
source === ERC20BridgeSource.CurveUsdcDai ||
source === ERC20BridgeSource.CurveUsdcDaiUsdt ||
source === ERC20BridgeSource.CurveUsdcDaiUsdtTusd
) {
const { curveAddress, tokens } = constants.DEFAULT_CURVE_OPTS[source];
const fromTokenIdx = tokens.indexOf(takerToken);
const toTokenIdx = tokens.indexOf(makerToken);
if (fromTokenIdx !== -1 && toTokenIdx !== -1) {
batchedOperation = samplerOperations.getCurveSellQuotes(
curveAddress,
fromTokenIdx,
toTokenIdx,
takerFillAmounts,
);
}
} else if (source === ERC20BridgeSource.LiquidityProvider) {
if (liquidityProviderRegistryAddress === undefined) {
throw new Error(
'Cannot sample liquidity from a LiquidityProvider liquidity pool, if a registry is not provided.',
);
}
batchedOperation = samplerOperations.getLiquidityProviderSellQuotes(
liquidityProviderRegistryAddress,
takerToken,
makerToken,
takerFillAmounts,
);
} else {
throw new Error(`Unsupported sell sample source: ${source}`);
}
return { batchedOperation, source };
})
.filter(op => op.batchedOperation) as Array<{
batchedOperation: BatchedOperation<BigNumber[]>;
source: ERC20BridgeSource;
}>;
return {
encodeCall: contract => {
const subCalls = subOps.map(op => op.batchedOperation.encodeCall(contract));
return contract.batchCall(subCalls).getABIEncodedTransactionData();
},
handleCallResultsAsync: async (contract, callResults) => {
const rawSubCallResults = contract.getABIDecodedReturnData<string[]>('batchCall', callResults);
const samples = await Promise.all(
subOps.map(async (op, i) =>
op.batchedOperation.handleCallResultsAsync(contract, rawSubCallResults[i]),
),
);
return subOps.map((op, i) => {
return samples[i].map((output, j) => ({
source: op.source,
output,
input: takerFillAmounts[j],
}));
});
},
};
},
getBuyQuotes(
sources: ERC20BridgeSource[],
makerToken: string,
takerToken: string,
makerFillAmounts: BigNumber[],
liquidityProviderRegistryAddress?: string | undefined,
): BatchedOperation<DexSample[][]> {
const subOps = sources.map(source => {
if (source === ERC20BridgeSource.Eth2Dai) {
return samplerOperations.getEth2DaiBuyQuotes(makerToken, takerToken, makerFillAmounts);
} else if (source === ERC20BridgeSource.Uniswap) {
return samplerOperations.getUniswapBuyQuotes(makerToken, takerToken, makerFillAmounts);
} else if (source === ERC20BridgeSource.LiquidityProvider) {
if (liquidityProviderRegistryAddress === undefined) {
throw new Error(
'Cannot sample liquidity from a LiquidityProvider liquidity pool, if a registry is not provided.',
);
}
return samplerOperations.getLiquidityProviderBuyQuotes(liquidityProviderRegistryAddress, takerToken, makerToken, makerFillAmounts);
} else {
throw new Error(`Unsupported buy sample source: ${source}`);
}
});
return {
encodeCall: contract => {
const subCalls = subOps.map(op => op.encodeCall(contract));
return contract.batchCall(subCalls).getABIEncodedTransactionData();
},
handleCallResultsAsync: async (contract, callResults) => {
const rawSubCallResults = contract.getABIDecodedReturnData<string[]>('batchCall', callResults);
const samples = await Promise.all(
subOps.map(async (op, i) => op.handleCallResultsAsync(contract, rawSubCallResults[i])),
);
return sources.map((source, i) => {
return samples[i].map((output, j) => ({
source,
output,
input: makerFillAmounts[j],
}));
});
},
};
},
};
/** /**
* Generate sample amounts up to `maxFillAmount`. * Generate sample amounts up to `maxFillAmount`.
*/ */

View File

@ -0,0 +1,374 @@
import { constants } from 'zlib';
import { BigNumber, ERC20BridgeSource, SignedOrder } from '../..';
import { BatchedOperation } from './sampler';
import { DexSample } from './types';
/**
* Composable operations that can be batched in a single transaction,
* for use with `DexOrderSampler.executeAsync()`.
*/
export const samplerOperations = {
getOrderFillableTakerAmounts(orders: SignedOrder[]): BatchedOperation<BigNumber[]> {
return {
encodeCall: contract => {
return contract
.getOrderFillableTakerAssetAmounts(orders, orders.map(o => o.signature))
.getABIEncodedTransactionData();
},
handleCallResultsAsync: async (contract, callResults) => {
return contract.getABIDecodedReturnData<BigNumber[]>('getOrderFillableTakerAssetAmounts', callResults);
},
};
},
getOrderFillableMakerAmounts(orders: SignedOrder[]): BatchedOperation<BigNumber[]> {
return {
encodeCall: contract => {
return contract
.getOrderFillableMakerAssetAmounts(orders, orders.map(o => o.signature))
.getABIEncodedTransactionData();
},
handleCallResultsAsync: async (contract, callResults) => {
return contract.getABIDecodedReturnData<BigNumber[]>('getOrderFillableMakerAssetAmounts', callResults);
},
};
},
getKyberSellQuotes(
makerToken: string,
takerToken: string,
takerFillAmounts: BigNumber[],
): BatchedOperation<BigNumber[]> {
return {
encodeCall: contract => {
return contract
.sampleSellsFromKyberNetwork(takerToken, makerToken, takerFillAmounts)
.getABIEncodedTransactionData();
},
handleCallResultsAsync: async (contract, callResults) => {
return contract.getABIDecodedReturnData<BigNumber[]>('sampleSellsFromKyberNetwork', callResults);
},
};
},
getUniswapSellQuotes(
makerToken: string,
takerToken: string,
takerFillAmounts: BigNumber[],
): BatchedOperation<BigNumber[]> {
return {
encodeCall: contract => {
return contract
.sampleSellsFromUniswap(takerToken, makerToken, takerFillAmounts)
.getABIEncodedTransactionData();
},
handleCallResultsAsync: async (contract, callResults) => {
return contract.getABIDecodedReturnData<BigNumber[]>('sampleSellsFromUniswap', callResults);
},
};
},
getLiquidityProviderSellQuotes(
liquidityProviderRegistryAddress: string,
takerToken: string,
makerToken: string,
takerFillAmounts: BigNumber[],
): BatchedOperation<BigNumber[]> {
return {
encodeCall: contract => {
return contract
.sampleSellsFromLiquidityProviderRegistry(
liquidityProviderRegistryAddress,
takerToken,
makerToken,
takerFillAmounts,
)
.getABIEncodedTransactionData();
},
handleCallResultsAsync: async (contract, callResults) => {
return contract.getABIDecodedReturnData<BigNumber[]>(
'sampleSellsFromLiquidityProviderRegistry',
callResults,
);
},
};
},
getLiquidityProviderBuyQuotes(
liquidityProviderRegistryAddress: string,
takerToken: string,
makerToken: string,
makerFillAmounts: BigNumber[],
): BatchedOperation<BigNumber[]> {
return {
encodeCall: contract => {
return contract
.sampleBuysFromLiquidityProviderRegistry(
liquidityProviderRegistryAddress,
takerToken,
makerToken,
makerFillAmounts,
)
.getABIEncodedTransactionData();
},
handleCallResultsAsync: async (contract, callResults) => {
return contract.getABIDecodedReturnData<BigNumber[]>(
'sampleBuysFromLiquidityProviderRegistry',
callResults,
);
},
};
},
getEth2DaiSellQuotes(
makerToken: string,
takerToken: string,
takerFillAmounts: BigNumber[],
): BatchedOperation<BigNumber[]> {
return {
encodeCall: contract => {
return contract
.sampleSellsFromEth2Dai(takerToken, makerToken, takerFillAmounts)
.getABIEncodedTransactionData();
},
handleCallResultsAsync: async (contract, callResults) => {
return contract.getABIDecodedReturnData<BigNumber[]>('sampleSellsFromEth2Dai', callResults);
},
};
},
getCurveSellQuotes(
curveAddress: string,
fromTokenIdx: number,
toTokenIdx: number,
takerFillAmounts: BigNumber[],
): BatchedOperation<BigNumber[]> {
return {
encodeCall: contract => {
return contract
.sampleSellsFromCurve(
curveAddress,
new BigNumber(fromTokenIdx),
new BigNumber(toTokenIdx),
takerFillAmounts,
)
.getABIEncodedTransactionData();
},
handleCallResultsAsync: async (contract, callResults) => {
return contract.getABIDecodedReturnData<BigNumber[]>('sampleSellsFromCurve', callResults);
},
};
},
getUniswapBuyQuotes(
makerToken: string,
takerToken: string,
makerFillAmounts: BigNumber[],
): BatchedOperation<BigNumber[]> {
return {
encodeCall: contract => {
return contract
.sampleBuysFromUniswap(takerToken, makerToken, makerFillAmounts)
.getABIEncodedTransactionData();
},
handleCallResultsAsync: async (contract, callResults) => {
return contract.getABIDecodedReturnData<BigNumber[]>('sampleBuysFromUniswap', callResults);
},
};
},
getEth2DaiBuyQuotes(
makerToken: string,
takerToken: string,
makerFillAmounts: BigNumber[],
): BatchedOperation<BigNumber[]> {
return {
encodeCall: contract => {
return contract
.sampleBuysFromEth2Dai(takerToken, makerToken, makerFillAmounts)
.getABIEncodedTransactionData();
},
handleCallResultsAsync: async (contract, callResults) => {
return contract.getABIDecodedReturnData<BigNumber[]>('sampleBuysFromEth2Dai', callResults);
},
};
},
getMedianSellRate(
sources: ERC20BridgeSource[],
makerToken: string,
takerToken: string,
takerFillAmount: BigNumber,
liquidityProviderRegistryAddress?: string | undefined,
): BatchedOperation<BigNumber> {
const getSellQuotes = samplerOperations.getSellQuotes(
sources,
makerToken,
takerToken,
[takerFillAmount],
liquidityProviderRegistryAddress,
);
return {
encodeCall: contract => {
const subCalls = [getSellQuotes.encodeCall(contract)];
return contract.batchCall(subCalls).getABIEncodedTransactionData();
},
handleCallResultsAsync: async (contract, callResults) => {
const rawSubCallResults = contract.getABIDecodedReturnData<string[]>('batchCall', callResults);
const samples = await getSellQuotes.handleCallResultsAsync(contract, rawSubCallResults[0]);
if (samples.length === 0) {
return new BigNumber(0);
}
const flatSortedSamples = samples
.reduce((acc, v) => acc.concat(...v))
.sort((a, b) => a.output.comparedTo(b.output));
if (flatSortedSamples.length === 0) {
return new BigNumber(0);
}
const medianSample = flatSortedSamples[Math.floor(flatSortedSamples.length / 2)];
return medianSample.output.div(medianSample.input);
},
};
},
constant<T>(result: T): BatchedOperation<T> {
return {
encodeCall: contract => {
return '0x';
},
handleCallResultsAsync: async (contract, callResults) => {
return result;
},
};
},
getLiquidityProviderFromRegistry(
registryAddress: string,
takerToken: string,
makerToken: string,
): BatchedOperation<string> {
return {
encodeCall: contract => {
return contract
.getLiquidityProviderFromRegistry(registryAddress, takerToken, makerToken)
.getABIEncodedTransactionData();
},
handleCallResultsAsync: async (contract, callResults) => {
return contract.getABIDecodedReturnData<string>('getLiquidityProviderFromRegistry', callResults);
},
};
},
getSellQuotes(
sources: ERC20BridgeSource[],
makerToken: string,
takerToken: string,
takerFillAmounts: BigNumber[],
liquidityProviderRegistryAddress?: string | undefined,
): BatchedOperation<DexSample[][]> {
const subOps = sources
.map(source => {
let batchedOperation;
if (source === ERC20BridgeSource.Eth2Dai) {
batchedOperation = samplerOperations.getEth2DaiSellQuotes(makerToken, takerToken, takerFillAmounts);
} else if (source === ERC20BridgeSource.Uniswap) {
batchedOperation = samplerOperations.getUniswapSellQuotes(makerToken, takerToken, takerFillAmounts);
} else if (source === ERC20BridgeSource.Kyber) {
batchedOperation = samplerOperations.getKyberSellQuotes(makerToken, takerToken, takerFillAmounts);
} else if (
source === ERC20BridgeSource.CurveUsdcDai ||
source === ERC20BridgeSource.CurveUsdcDaiUsdt ||
source === ERC20BridgeSource.CurveUsdcDaiUsdtTusd
) {
const { curveAddress, tokens } = constants.DEFAULT_CURVE_OPTS[source];
const fromTokenIdx = tokens.indexOf(takerToken);
const toTokenIdx = tokens.indexOf(makerToken);
if (fromTokenIdx !== -1 && toTokenIdx !== -1) {
batchedOperation = samplerOperations.getCurveSellQuotes(
curveAddress,
fromTokenIdx,
toTokenIdx,
takerFillAmounts,
);
}
} else if (source === ERC20BridgeSource.LiquidityProvider) {
if (liquidityProviderRegistryAddress === undefined) {
throw new Error(
'Cannot sample liquidity from a LiquidityProvider liquidity pool, if a registry is not provided.',
);
}
batchedOperation = samplerOperations.getLiquidityProviderSellQuotes(
liquidityProviderRegistryAddress,
takerToken,
makerToken,
takerFillAmounts,
);
} else {
throw new Error(`Unsupported sell sample source: ${source}`);
}
return { batchedOperation, source };
})
.filter(op => op.batchedOperation) as Array<{
batchedOperation: BatchedOperation<BigNumber[]>;
source: ERC20BridgeSource;
}>;
return {
encodeCall: contract => {
const subCalls = subOps.map(op => op.batchedOperation.encodeCall(contract));
return contract.batchCall(subCalls).getABIEncodedTransactionData();
},
handleCallResultsAsync: async (contract, callResults) => {
const rawSubCallResults = contract.getABIDecodedReturnData<string[]>('batchCall', callResults);
const samples = await Promise.all(
subOps.map(async (op, i) =>
op.batchedOperation.handleCallResultsAsync(contract, rawSubCallResults[i]),
),
);
return subOps.map((op, i) => {
return samples[i].map((output, j) => ({
source: op.source,
output,
input: takerFillAmounts[j],
}));
});
},
};
},
getBuyQuotes(
sources: ERC20BridgeSource[],
makerToken: string,
takerToken: string,
makerFillAmounts: BigNumber[],
liquidityProviderRegistryAddress?: string | undefined,
): BatchedOperation<DexSample[][]> {
const subOps = sources.map(source => {
if (source === ERC20BridgeSource.Eth2Dai) {
return samplerOperations.getEth2DaiBuyQuotes(makerToken, takerToken, makerFillAmounts);
} else if (source === ERC20BridgeSource.Uniswap) {
return samplerOperations.getUniswapBuyQuotes(makerToken, takerToken, makerFillAmounts);
} else if (source === ERC20BridgeSource.LiquidityProvider) {
if (liquidityProviderRegistryAddress === undefined) {
throw new Error(
'Cannot sample liquidity from a LiquidityProvider liquidity pool, if a registry is not provided.',
);
}
return samplerOperations.getLiquidityProviderBuyQuotes(
liquidityProviderRegistryAddress,
takerToken,
makerToken,
makerFillAmounts,
);
} else {
throw new Error(`Unsupported buy sample source: ${source}`);
}
});
return {
encodeCall: contract => {
const subCalls = subOps.map(op => op.encodeCall(contract));
return contract.batchCall(subCalls).getABIEncodedTransactionData();
},
handleCallResultsAsync: async (contract, callResults) => {
const rawSubCallResults = contract.getABIDecodedReturnData<string[]>('batchCall', callResults);
const samples = await Promise.all(
subOps.map(async (op, i) => op.handleCallResultsAsync(contract, rawSubCallResults[i])),
);
return sources.map((source, i) => {
return samples[i].map((output, j) => ({
source,
output,
input: makerFillAmounts[j],
}));
});
},
};
},
};

View File

@ -393,7 +393,9 @@ describe('MarketOperationUtils tests', () => {
...DEFAULT_OPTS, ...DEFAULT_OPTS,
excludedSources: [], excludedSources: [],
}); });
expect(args.sources.sort()).to.deep.eq(SELL_SOURCES.concat([ERC20BridgeSource.LiquidityProvider]).sort()); expect(args.sources.sort()).to.deep.eq(
SELL_SOURCES.concat([ERC20BridgeSource.LiquidityProvider]).sort(),
);
expect(args.liquidityProviderAddress).to.eql(registryAddress); expect(args.liquidityProviderAddress).to.eql(registryAddress);
}); });
@ -687,7 +689,9 @@ describe('MarketOperationUtils tests', () => {
...DEFAULT_OPTS, ...DEFAULT_OPTS,
excludedSources: [], excludedSources: [],
}); });
expect(args.sources.sort()).to.deep.eq(BUY_SOURCES.concat([ERC20BridgeSource.LiquidityProvider]).sort()); expect(args.sources.sort()).to.deep.eq(
BUY_SOURCES.concat([ERC20BridgeSource.LiquidityProvider]).sort(),
);
expect(args.liquidityProviderAddress).to.eql(registryAddress); expect(args.liquidityProviderAddress).to.eql(registryAddress);
}); });

View File

@ -33,8 +33,6 @@ import { assert } from '@0x/assert';
import * as ethers from 'ethers'; import * as ethers from 'ethers';
// tslint:enable:no-unused-variable // tslint:enable:no-unused-variable
/* istanbul ignore next */ /* istanbul ignore next */
// tslint:disable:array-type // tslint:disable:array-type
// tslint:disable:no-parameter-reassignment // tslint:disable:no-parameter-reassignment
@ -50,7 +48,7 @@ public static async deployFrom0xArtifactAsync(
artifact: ContractArtifact | SimpleContractArtifact, artifact: ContractArtifact | SimpleContractArtifact,
supportedProvider: SupportedProvider, supportedProvider: SupportedProvider,
txDefaults: Partial<TxData>, txDefaults: Partial<TxData>,
logDecodeDependencies: { [contractName: string]: (ContractArtifact | SimpleContractArtifact) }, logDecodeDependencies: { [contractName: string]: ContractArtifact | SimpleContractArtifact },
): Promise<DummyLiquidityProviderContract> { ): Promise<DummyLiquidityProviderContract> {
assert.doesConformToSchema('txDefaults', txDefaults, schemas.txDataSchema, [ assert.doesConformToSchema('txDefaults', txDefaults, schemas.txDataSchema, [
schemas.addressSchema, schemas.addressSchema,
@ -69,7 +67,13 @@ public static async deployFrom0xArtifactAsync(
logDecodeDependenciesAbiOnly[key] = logDecodeDependencies[key].compilerOutput.abi; logDecodeDependenciesAbiOnly[key] = logDecodeDependencies[key].compilerOutput.abi;
} }
} }
return DummyLiquidityProviderContract.deployAsync(bytecode, abi, provider, txDefaults, logDecodeDependenciesAbiOnly, ); return DummyLiquidityProviderContract.deployAsync(
bytecode,
abi,
provider,
txDefaults,
logDecodeDependenciesAbiOnly,
);
} }
public static async deployWithLibrariesFrom0xArtifactAsync( public static async deployWithLibrariesFrom0xArtifactAsync(
@ -77,7 +81,7 @@ public static async deployFrom0xArtifactAsync(
libraryArtifacts: { [libraryName: string]: ContractArtifact }, libraryArtifacts: { [libraryName: string]: ContractArtifact },
supportedProvider: SupportedProvider, supportedProvider: SupportedProvider,
txDefaults: Partial<TxData>, txDefaults: Partial<TxData>,
logDecodeDependencies: { [contractName: string]: (ContractArtifact | SimpleContractArtifact) }, logDecodeDependencies: { [contractName: string]: ContractArtifact | SimpleContractArtifact },
): Promise<DummyLiquidityProviderContract> { ): Promise<DummyLiquidityProviderContract> {
assert.doesConformToSchema('txDefaults', txDefaults, schemas.txDataSchema, [ assert.doesConformToSchema('txDefaults', txDefaults, schemas.txDataSchema, [
schemas.addressSchema, schemas.addressSchema,
@ -99,13 +103,16 @@ public static async deployFrom0xArtifactAsync(
artifact, artifact,
libraryArtifacts, libraryArtifacts,
new Web3Wrapper(provider), new Web3Wrapper(provider),
txDefaults txDefaults,
); );
const bytecode = linkLibrariesInBytecode( const bytecode = linkLibrariesInBytecode(artifact, libraryAddresses);
artifact, return DummyLiquidityProviderContract.deployAsync(
libraryAddresses, bytecode,
abi,
provider,
txDefaults,
logDecodeDependenciesAbiOnly,
); );
return DummyLiquidityProviderContract.deployAsync(bytecode, abi, provider, txDefaults, logDecodeDependenciesAbiOnly, );
} }
public static async deployAsync( public static async deployAsync(
@ -123,11 +130,7 @@ public static async deployFrom0xArtifactAsync(
]); ]);
const provider = providerUtils.standardizeOrThrow(supportedProvider); const provider = providerUtils.standardizeOrThrow(supportedProvider);
const constructorAbi = BaseContract._lookupConstructorAbi(abi); const constructorAbi = BaseContract._lookupConstructorAbi(abi);
[] = BaseContract._formatABIDataItemList( [] = BaseContract._formatABIDataItemList(constructorAbi.inputs, [], BaseContract._bigNumberToString);
constructorAbi.inputs,
[],
BaseContract._bigNumberToString,
);
const iface = new ethers.utils.Interface(abi); const iface = new ethers.utils.Interface(abi);
const deployInfo = iface.deployFunction; const deployInfo = iface.deployFunction;
const txData = deployInfo.encode(bytecode, []); const txData = deployInfo.encode(bytecode, []);
@ -143,7 +146,12 @@ public static async deployFrom0xArtifactAsync(
logUtils.log(`transactionHash: ${txHash}`); logUtils.log(`transactionHash: ${txHash}`);
const txReceipt = await web3Wrapper.awaitTransactionSuccessAsync(txHash); const txReceipt = await web3Wrapper.awaitTransactionSuccessAsync(txHash);
logUtils.log(`DummyLiquidityProvider successfully deployed at ${txReceipt.contractAddress}`); logUtils.log(`DummyLiquidityProvider successfully deployed at ${txReceipt.contractAddress}`);
const contractInstance = new DummyLiquidityProviderContract(txReceipt.contractAddress as string, provider, txDefaults, logDecodeDependencies); const contractInstance = new DummyLiquidityProviderContract(
txReceipt.contractAddress as string,
provider,
txDefaults,
logDecodeDependencies,
);
contractInstance.constructorArgs = []; contractInstance.constructorArgs = [];
return contractInstance; return contractInstance;
} }
@ -154,10 +162,8 @@ public static async deployFrom0xArtifactAsync(
public static ABI(): ContractAbi { public static ABI(): ContractAbi {
const abi = [ const abi = [
{ {
inputs: [ inputs: [],
], outputs: [],
outputs: [
],
payable: false, payable: false,
stateMutability: 'nonpayable', stateMutability: 'nonpayable',
type: 'constructor', type: 'constructor',
@ -246,10 +252,7 @@ public static async deployFrom0xArtifactAsync(
libraryAddresses, libraryAddresses,
); );
// Deploy this library. // Deploy this library.
const linkedLibraryBytecode = linkLibrariesInBytecode( const linkedLibraryBytecode = linkLibrariesInBytecode(libraryArtifact, libraryAddresses);
libraryArtifact,
libraryAddresses,
);
const txDataWithDefaults = await BaseContract._applyDefaultsToContractTxDataAsync( const txDataWithDefaults = await BaseContract._applyDefaultsToContractTxDataAsync(
{ {
data: linkedLibraryBytecode, data: linkedLibraryBytecode,
@ -306,39 +309,33 @@ public static async deployFrom0xArtifactAsync(
* @param buyAmount Amount of `makerToken` to buy. * @param buyAmount Amount of `makerToken` to buy.
* @returns takerTokenAmount Amount of &#x60;takerToken&#x60; that would need to be sold. * @returns takerTokenAmount Amount of &#x60;takerToken&#x60; that would need to be sold.
*/ */
public getBuyQuote( public getBuyQuote(takerToken: string, makerToken: string, buyAmount: BigNumber): ContractFunctionObj<BigNumber> {
takerToken: string, const self = (this as any) as DummyLiquidityProviderContract;
makerToken: string,
buyAmount: BigNumber,
): ContractFunctionObj<BigNumber
> {
const self = this as any as DummyLiquidityProviderContract;
assert.isString('takerToken', takerToken); assert.isString('takerToken', takerToken);
assert.isString('makerToken', makerToken); assert.isString('makerToken', makerToken);
assert.isBigNumber('buyAmount', buyAmount); assert.isBigNumber('buyAmount', buyAmount);
const functionSignature = 'getBuyQuote(address,address,uint256)'; const functionSignature = 'getBuyQuote(address,address,uint256)';
return { return {
async callAsync( async callAsync(callData: Partial<CallData> = {}, defaultBlock?: BlockParam): Promise<BigNumber> {
callData: Partial<CallData> = {},
defaultBlock?: BlockParam,
): Promise<BigNumber
> {
BaseContract._assertCallParams(callData, defaultBlock); BaseContract._assertCallParams(callData, defaultBlock);
const rawCallResult = await self._performCallAsync({ ...callData, data: this.getABIEncodedTransactionData() }, defaultBlock); const rawCallResult = await self._performCallAsync(
{ ...callData, data: this.getABIEncodedTransactionData() },
defaultBlock,
);
const abiEncoder = self._lookupAbiEncoder(functionSignature); const abiEncoder = self._lookupAbiEncoder(functionSignature);
BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder); BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder);
return abiEncoder.strictDecodeReturnValue<BigNumber return abiEncoder.strictDecodeReturnValue<BigNumber>(rawCallResult);
>(rawCallResult);
}, },
getABIEncodedTransactionData(): string { getABIEncodedTransactionData(): string {
return self._strictEncodeArguments(functionSignature, [takerToken.toLowerCase(), return self._strictEncodeArguments(functionSignature, [
takerToken.toLowerCase(),
makerToken.toLowerCase(), makerToken.toLowerCase(),
buyAmount buyAmount,
]); ]);
}, },
}
}; };
}
/** /**
* Quotes the amount of `makerToken` that would be obtained by * Quotes the amount of `makerToken` that would be obtained by
* selling `sellAmount` of `takerToken`. * selling `sellAmount` of `takerToken`.
@ -347,41 +344,33 @@ public static async deployFrom0xArtifactAsync(
* @param sellAmount Amount of `takerToken` to sell. * @param sellAmount Amount of `takerToken` to sell.
* @returns makerTokenAmount Amount of &#x60;makerToken&#x60; that would be obtained. * @returns makerTokenAmount Amount of &#x60;makerToken&#x60; that would be obtained.
*/ */
public getSellQuote( public getSellQuote(takerToken: string, makerToken: string, sellAmount: BigNumber): ContractFunctionObj<BigNumber> {
takerToken: string, const self = (this as any) as DummyLiquidityProviderContract;
makerToken: string,
sellAmount: BigNumber,
): ContractFunctionObj<BigNumber
> {
const self = this as any as DummyLiquidityProviderContract;
assert.isString('takerToken', takerToken); assert.isString('takerToken', takerToken);
assert.isString('makerToken', makerToken); assert.isString('makerToken', makerToken);
assert.isBigNumber('sellAmount', sellAmount); assert.isBigNumber('sellAmount', sellAmount);
const functionSignature = 'getSellQuote(address,address,uint256)'; const functionSignature = 'getSellQuote(address,address,uint256)';
return { return {
async callAsync( async callAsync(callData: Partial<CallData> = {}, defaultBlock?: BlockParam): Promise<BigNumber> {
callData: Partial<CallData> = {},
defaultBlock?: BlockParam,
): Promise<BigNumber
> {
BaseContract._assertCallParams(callData, defaultBlock); BaseContract._assertCallParams(callData, defaultBlock);
const rawCallResult = await self._performCallAsync({ ...callData, data: this.getABIEncodedTransactionData() }, defaultBlock); const rawCallResult = await self._performCallAsync(
{ ...callData, data: this.getABIEncodedTransactionData() },
defaultBlock,
);
const abiEncoder = self._lookupAbiEncoder(functionSignature); const abiEncoder = self._lookupAbiEncoder(functionSignature);
BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder); BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder);
return abiEncoder.strictDecodeReturnValue<BigNumber return abiEncoder.strictDecodeReturnValue<BigNumber>(rawCallResult);
>(rawCallResult);
}, },
getABIEncodedTransactionData(): string { getABIEncodedTransactionData(): string {
return self._strictEncodeArguments(functionSignature, [takerToken.toLowerCase(), return self._strictEncodeArguments(functionSignature, [
takerToken.toLowerCase(),
makerToken.toLowerCase(), makerToken.toLowerCase(),
sellAmount sellAmount,
]); ]);
}, },
}
}; };
}
constructor( constructor(
address: string, address: string,
@ -390,7 +379,15 @@ public static async deployFrom0xArtifactAsync(
logDecodeDependencies?: { [contractName: string]: ContractAbi }, logDecodeDependencies?: { [contractName: string]: ContractAbi },
deployedBytecode: string | undefined = DummyLiquidityProviderContract.deployedBytecode, deployedBytecode: string | undefined = DummyLiquidityProviderContract.deployedBytecode,
) { ) {
super('DummyLiquidityProvider', DummyLiquidityProviderContract.ABI(), address, supportedProvider, txDefaults, logDecodeDependencies, deployedBytecode); super(
'DummyLiquidityProvider',
DummyLiquidityProviderContract.ABI(),
address,
supportedProvider,
txDefaults,
logDecodeDependencies,
deployedBytecode,
);
classUtils.bindAll(this, ['_abiEncoderByFunctionSignature', 'address', '_web3Wrapper']); classUtils.bindAll(this, ['_abiEncoderByFunctionSignature', 'address', '_web3Wrapper']);
DummyLiquidityProviderContract.ABI().forEach((item, index) => { DummyLiquidityProviderContract.ABI().forEach((item, index) => {
if (item.type === 'function') { if (item.type === 'function') {

View File

@ -33,8 +33,6 @@ import { assert } from '@0x/assert';
import * as ethers from 'ethers'; import * as ethers from 'ethers';
// tslint:enable:no-unused-variable // tslint:enable:no-unused-variable
/* istanbul ignore next */ /* istanbul ignore next */
// tslint:disable:array-type // tslint:disable:array-type
// tslint:disable:no-parameter-reassignment // tslint:disable:no-parameter-reassignment
@ -50,7 +48,7 @@ public static async deployFrom0xArtifactAsync(
artifact: ContractArtifact | SimpleContractArtifact, artifact: ContractArtifact | SimpleContractArtifact,
supportedProvider: SupportedProvider, supportedProvider: SupportedProvider,
txDefaults: Partial<TxData>, txDefaults: Partial<TxData>,
logDecodeDependencies: { [contractName: string]: (ContractArtifact | SimpleContractArtifact) }, logDecodeDependencies: { [contractName: string]: ContractArtifact | SimpleContractArtifact },
): Promise<DummyLiquidityProviderRegistryContract> { ): Promise<DummyLiquidityProviderRegistryContract> {
assert.doesConformToSchema('txDefaults', txDefaults, schemas.txDataSchema, [ assert.doesConformToSchema('txDefaults', txDefaults, schemas.txDataSchema, [
schemas.addressSchema, schemas.addressSchema,
@ -69,7 +67,13 @@ public static async deployFrom0xArtifactAsync(
logDecodeDependenciesAbiOnly[key] = logDecodeDependencies[key].compilerOutput.abi; logDecodeDependenciesAbiOnly[key] = logDecodeDependencies[key].compilerOutput.abi;
} }
} }
return DummyLiquidityProviderRegistryContract.deployAsync(bytecode, abi, provider, txDefaults, logDecodeDependenciesAbiOnly, ); return DummyLiquidityProviderRegistryContract.deployAsync(
bytecode,
abi,
provider,
txDefaults,
logDecodeDependenciesAbiOnly,
);
} }
public static async deployWithLibrariesFrom0xArtifactAsync( public static async deployWithLibrariesFrom0xArtifactAsync(
@ -77,7 +81,7 @@ public static async deployFrom0xArtifactAsync(
libraryArtifacts: { [libraryName: string]: ContractArtifact }, libraryArtifacts: { [libraryName: string]: ContractArtifact },
supportedProvider: SupportedProvider, supportedProvider: SupportedProvider,
txDefaults: Partial<TxData>, txDefaults: Partial<TxData>,
logDecodeDependencies: { [contractName: string]: (ContractArtifact | SimpleContractArtifact) }, logDecodeDependencies: { [contractName: string]: ContractArtifact | SimpleContractArtifact },
): Promise<DummyLiquidityProviderRegistryContract> { ): Promise<DummyLiquidityProviderRegistryContract> {
assert.doesConformToSchema('txDefaults', txDefaults, schemas.txDataSchema, [ assert.doesConformToSchema('txDefaults', txDefaults, schemas.txDataSchema, [
schemas.addressSchema, schemas.addressSchema,
@ -99,13 +103,16 @@ public static async deployFrom0xArtifactAsync(
artifact, artifact,
libraryArtifacts, libraryArtifacts,
new Web3Wrapper(provider), new Web3Wrapper(provider),
txDefaults txDefaults,
); );
const bytecode = linkLibrariesInBytecode( const bytecode = linkLibrariesInBytecode(artifact, libraryAddresses);
artifact, return DummyLiquidityProviderRegistryContract.deployAsync(
libraryAddresses, bytecode,
abi,
provider,
txDefaults,
logDecodeDependenciesAbiOnly,
); );
return DummyLiquidityProviderRegistryContract.deployAsync(bytecode, abi, provider, txDefaults, logDecodeDependenciesAbiOnly, );
} }
public static async deployAsync( public static async deployAsync(
@ -123,11 +130,7 @@ public static async deployFrom0xArtifactAsync(
]); ]);
const provider = providerUtils.standardizeOrThrow(supportedProvider); const provider = providerUtils.standardizeOrThrow(supportedProvider);
const constructorAbi = BaseContract._lookupConstructorAbi(abi); const constructorAbi = BaseContract._lookupConstructorAbi(abi);
[] = BaseContract._formatABIDataItemList( [] = BaseContract._formatABIDataItemList(constructorAbi.inputs, [], BaseContract._bigNumberToString);
constructorAbi.inputs,
[],
BaseContract._bigNumberToString,
);
const iface = new ethers.utils.Interface(abi); const iface = new ethers.utils.Interface(abi);
const deployInfo = iface.deployFunction; const deployInfo = iface.deployFunction;
const txData = deployInfo.encode(bytecode, []); const txData = deployInfo.encode(bytecode, []);
@ -143,7 +146,12 @@ public static async deployFrom0xArtifactAsync(
logUtils.log(`transactionHash: ${txHash}`); logUtils.log(`transactionHash: ${txHash}`);
const txReceipt = await web3Wrapper.awaitTransactionSuccessAsync(txHash); const txReceipt = await web3Wrapper.awaitTransactionSuccessAsync(txHash);
logUtils.log(`DummyLiquidityProviderRegistry successfully deployed at ${txReceipt.contractAddress}`); logUtils.log(`DummyLiquidityProviderRegistry successfully deployed at ${txReceipt.contractAddress}`);
const contractInstance = new DummyLiquidityProviderRegistryContract(txReceipt.contractAddress as string, provider, txDefaults, logDecodeDependencies); const contractInstance = new DummyLiquidityProviderRegistryContract(
txReceipt.contractAddress as string,
provider,
txDefaults,
logDecodeDependencies,
);
contractInstance.constructorArgs = []; contractInstance.constructorArgs = [];
return contractInstance; return contractInstance;
} }
@ -154,10 +162,8 @@ public static async deployFrom0xArtifactAsync(
public static ABI(): ContractAbi { public static ABI(): ContractAbi {
const abi = [ const abi = [
{ {
inputs: [ inputs: [],
], outputs: [],
outputs: [
],
payable: false, payable: false,
stateMutability: 'nonpayable', stateMutability: 'nonpayable',
type: 'constructor', type: 'constructor',
@ -202,8 +208,7 @@ public static async deployFrom0xArtifactAsync(
}, },
], ],
name: 'setLiquidityProviderForMarket', name: 'setLiquidityProviderForMarket',
outputs: [ outputs: [],
],
payable: false, payable: false,
stateMutability: 'nonpayable', stateMutability: 'nonpayable',
type: 'function', type: 'function',
@ -238,10 +243,7 @@ public static async deployFrom0xArtifactAsync(
libraryAddresses, libraryAddresses,
); );
// Deploy this library. // Deploy this library.
const linkedLibraryBytecode = linkLibrariesInBytecode( const linkedLibraryBytecode = linkLibrariesInBytecode(libraryArtifact, libraryAddresses);
libraryArtifact,
libraryAddresses,
);
const txDataWithDefaults = await BaseContract._applyDefaultsToContractTxDataAsync( const txDataWithDefaults = await BaseContract._applyDefaultsToContractTxDataAsync(
{ {
data: linkedLibraryBytecode, data: linkedLibraryBytecode,
@ -296,36 +298,31 @@ public static async deployFrom0xArtifactAsync(
* @param makerToken Second asset managed by pool. * @param makerToken Second asset managed by pool.
* @returns Address of pool. * @returns Address of pool.
*/ */
public getLiquidityProviderForMarket( public getLiquidityProviderForMarket(takerToken: string, makerToken: string): ContractFunctionObj<string> {
takerToken: string, const self = (this as any) as DummyLiquidityProviderRegistryContract;
makerToken: string,
): ContractFunctionObj<string
> {
const self = this as any as DummyLiquidityProviderRegistryContract;
assert.isString('takerToken', takerToken); assert.isString('takerToken', takerToken);
assert.isString('makerToken', makerToken); assert.isString('makerToken', makerToken);
const functionSignature = 'getLiquidityProviderForMarket(address,address)'; const functionSignature = 'getLiquidityProviderForMarket(address,address)';
return { return {
async callAsync( async callAsync(callData: Partial<CallData> = {}, defaultBlock?: BlockParam): Promise<string> {
callData: Partial<CallData> = {},
defaultBlock?: BlockParam,
): Promise<string
> {
BaseContract._assertCallParams(callData, defaultBlock); BaseContract._assertCallParams(callData, defaultBlock);
const rawCallResult = await self._performCallAsync({ ...callData, data: this.getABIEncodedTransactionData() }, defaultBlock); const rawCallResult = await self._performCallAsync(
{ ...callData, data: this.getABIEncodedTransactionData() },
defaultBlock,
);
const abiEncoder = self._lookupAbiEncoder(functionSignature); const abiEncoder = self._lookupAbiEncoder(functionSignature);
BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder); BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder);
return abiEncoder.strictDecodeReturnValue<string return abiEncoder.strictDecodeReturnValue<string>(rawCallResult);
>(rawCallResult);
}, },
getABIEncodedTransactionData(): string { getABIEncodedTransactionData(): string {
return self._strictEncodeArguments(functionSignature, [takerToken.toLowerCase(), return self._strictEncodeArguments(functionSignature, [
makerToken.toLowerCase() takerToken.toLowerCase(),
makerToken.toLowerCase(),
]); ]);
}, },
}
}; };
}
/** /**
* Sets address of pool for a market given market (xAsset, yAsset). * Sets address of pool for a market given market (xAsset, yAsset).
* @param takerToken First asset managed by pool. * @param takerToken First asset managed by pool.
@ -336,9 +333,8 @@ public static async deployFrom0xArtifactAsync(
takerToken: string, takerToken: string,
makerToken: string, makerToken: string,
poolAddress: string, poolAddress: string,
): ContractTxFunctionObj<void ): ContractTxFunctionObj<void> {
> { const self = (this as any) as DummyLiquidityProviderRegistryContract;
const self = this as any as DummyLiquidityProviderRegistryContract;
assert.isString('takerToken', takerToken); assert.isString('takerToken', takerToken);
assert.isString('makerToken', makerToken); assert.isString('makerToken', makerToken);
assert.isString('poolAddress', poolAddress); assert.isString('poolAddress', poolAddress);
@ -364,36 +360,32 @@ public static async deployFrom0xArtifactAsync(
): PromiseWithTransactionHash<TransactionReceiptWithDecodedLogs> { ): PromiseWithTransactionHash<TransactionReceiptWithDecodedLogs> {
return self._promiseWithTransactionHash(this.sendTransactionAsync(txData, opts), opts); return self._promiseWithTransactionHash(this.sendTransactionAsync(txData, opts), opts);
}, },
async estimateGasAsync( async estimateGasAsync(txData?: Partial<TxData> | undefined): Promise<number> {
txData?: Partial<TxData> | undefined, const txDataWithDefaults = await self._applyDefaultsToTxDataAsync({
): Promise<number> { ...txData,
const txDataWithDefaults = await self._applyDefaultsToTxDataAsync( data: this.getABIEncodedTransactionData(),
{ ...txData, data: this.getABIEncodedTransactionData() } });
);
return self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return self._web3Wrapper.estimateGasAsync(txDataWithDefaults);
}, },
async callAsync( async callAsync(callData: Partial<CallData> = {}, defaultBlock?: BlockParam): Promise<void> {
callData: Partial<CallData> = {},
defaultBlock?: BlockParam,
): Promise<void
> {
BaseContract._assertCallParams(callData, defaultBlock); BaseContract._assertCallParams(callData, defaultBlock);
const rawCallResult = await self._performCallAsync({ ...callData, data: this.getABIEncodedTransactionData() }, defaultBlock); const rawCallResult = await self._performCallAsync(
{ ...callData, data: this.getABIEncodedTransactionData() },
defaultBlock,
);
const abiEncoder = self._lookupAbiEncoder(functionSignature); const abiEncoder = self._lookupAbiEncoder(functionSignature);
BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder); BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder);
return abiEncoder.strictDecodeReturnValue<void return abiEncoder.strictDecodeReturnValue<void>(rawCallResult);
>(rawCallResult);
}, },
getABIEncodedTransactionData(): string { getABIEncodedTransactionData(): string {
return self._strictEncodeArguments(functionSignature, [takerToken.toLowerCase(), return self._strictEncodeArguments(functionSignature, [
takerToken.toLowerCase(),
makerToken.toLowerCase(), makerToken.toLowerCase(),
poolAddress.toLowerCase() poolAddress.toLowerCase(),
]); ]);
}, },
}
}; };
}
constructor( constructor(
address: string, address: string,
@ -402,7 +394,15 @@ public static async deployFrom0xArtifactAsync(
logDecodeDependencies?: { [contractName: string]: ContractAbi }, logDecodeDependencies?: { [contractName: string]: ContractAbi },
deployedBytecode: string | undefined = DummyLiquidityProviderRegistryContract.deployedBytecode, deployedBytecode: string | undefined = DummyLiquidityProviderRegistryContract.deployedBytecode,
) { ) {
super('DummyLiquidityProviderRegistry', DummyLiquidityProviderRegistryContract.ABI(), address, supportedProvider, txDefaults, logDecodeDependencies, deployedBytecode); super(
'DummyLiquidityProviderRegistry',
DummyLiquidityProviderRegistryContract.ABI(),
address,
supportedProvider,
txDefaults,
logDecodeDependencies,
deployedBytecode,
);
classUtils.bindAll(this, ['_abiEncoderByFunctionSignature', 'address', '_web3Wrapper']); classUtils.bindAll(this, ['_abiEncoderByFunctionSignature', 'address', '_web3Wrapper']);
DummyLiquidityProviderRegistryContract.ABI().forEach((item, index) => { DummyLiquidityProviderRegistryContract.ABI().forEach((item, index) => {
if (item.type === 'function') { if (item.type === 'function') {

View File

@ -33,8 +33,6 @@ import { assert } from '@0x/assert';
import * as ethers from 'ethers'; import * as ethers from 'ethers';
// tslint:enable:no-unused-variable // tslint:enable:no-unused-variable
/* istanbul ignore next */ /* istanbul ignore next */
// tslint:disable:array-type // tslint:disable:array-type
// tslint:disable:no-parameter-reassignment // tslint:disable:no-parameter-reassignment
@ -50,7 +48,7 @@ public static async deployFrom0xArtifactAsync(
artifact: ContractArtifact | SimpleContractArtifact, artifact: ContractArtifact | SimpleContractArtifact,
supportedProvider: SupportedProvider, supportedProvider: SupportedProvider,
txDefaults: Partial<TxData>, txDefaults: Partial<TxData>,
logDecodeDependencies: { [contractName: string]: (ContractArtifact | SimpleContractArtifact) }, logDecodeDependencies: { [contractName: string]: ContractArtifact | SimpleContractArtifact },
): Promise<ERC20BridgeSamplerContract> { ): Promise<ERC20BridgeSamplerContract> {
assert.doesConformToSchema('txDefaults', txDefaults, schemas.txDataSchema, [ assert.doesConformToSchema('txDefaults', txDefaults, schemas.txDataSchema, [
schemas.addressSchema, schemas.addressSchema,
@ -69,7 +67,13 @@ public static async deployFrom0xArtifactAsync(
logDecodeDependenciesAbiOnly[key] = logDecodeDependencies[key].compilerOutput.abi; logDecodeDependenciesAbiOnly[key] = logDecodeDependencies[key].compilerOutput.abi;
} }
} }
return ERC20BridgeSamplerContract.deployAsync(bytecode, abi, provider, txDefaults, logDecodeDependenciesAbiOnly, ); return ERC20BridgeSamplerContract.deployAsync(
bytecode,
abi,
provider,
txDefaults,
logDecodeDependenciesAbiOnly,
);
} }
public static async deployWithLibrariesFrom0xArtifactAsync( public static async deployWithLibrariesFrom0xArtifactAsync(
@ -77,7 +81,7 @@ public static async deployFrom0xArtifactAsync(
libraryArtifacts: { [libraryName: string]: ContractArtifact }, libraryArtifacts: { [libraryName: string]: ContractArtifact },
supportedProvider: SupportedProvider, supportedProvider: SupportedProvider,
txDefaults: Partial<TxData>, txDefaults: Partial<TxData>,
logDecodeDependencies: { [contractName: string]: (ContractArtifact | SimpleContractArtifact) }, logDecodeDependencies: { [contractName: string]: ContractArtifact | SimpleContractArtifact },
): Promise<ERC20BridgeSamplerContract> { ): Promise<ERC20BridgeSamplerContract> {
assert.doesConformToSchema('txDefaults', txDefaults, schemas.txDataSchema, [ assert.doesConformToSchema('txDefaults', txDefaults, schemas.txDataSchema, [
schemas.addressSchema, schemas.addressSchema,
@ -99,13 +103,16 @@ public static async deployFrom0xArtifactAsync(
artifact, artifact,
libraryArtifacts, libraryArtifacts,
new Web3Wrapper(provider), new Web3Wrapper(provider),
txDefaults txDefaults,
); );
const bytecode = linkLibrariesInBytecode( const bytecode = linkLibrariesInBytecode(artifact, libraryAddresses);
artifact, return ERC20BridgeSamplerContract.deployAsync(
libraryAddresses, bytecode,
abi,
provider,
txDefaults,
logDecodeDependenciesAbiOnly,
); );
return ERC20BridgeSamplerContract.deployAsync(bytecode, abi, provider, txDefaults, logDecodeDependenciesAbiOnly, );
} }
public static async deployAsync( public static async deployAsync(
@ -123,11 +130,7 @@ public static async deployFrom0xArtifactAsync(
]); ]);
const provider = providerUtils.standardizeOrThrow(supportedProvider); const provider = providerUtils.standardizeOrThrow(supportedProvider);
const constructorAbi = BaseContract._lookupConstructorAbi(abi); const constructorAbi = BaseContract._lookupConstructorAbi(abi);
[] = BaseContract._formatABIDataItemList( [] = BaseContract._formatABIDataItemList(constructorAbi.inputs, [], BaseContract._bigNumberToString);
constructorAbi.inputs,
[],
BaseContract._bigNumberToString,
);
const iface = new ethers.utils.Interface(abi); const iface = new ethers.utils.Interface(abi);
const deployInfo = iface.deployFunction; const deployInfo = iface.deployFunction;
const txData = deployInfo.encode(bytecode, []); const txData = deployInfo.encode(bytecode, []);
@ -143,7 +146,12 @@ public static async deployFrom0xArtifactAsync(
logUtils.log(`transactionHash: ${txHash}`); logUtils.log(`transactionHash: ${txHash}`);
const txReceipt = await web3Wrapper.awaitTransactionSuccessAsync(txHash); const txReceipt = await web3Wrapper.awaitTransactionSuccessAsync(txHash);
logUtils.log(`ERC20BridgeSampler successfully deployed at ${txReceipt.contractAddress}`); logUtils.log(`ERC20BridgeSampler successfully deployed at ${txReceipt.contractAddress}`);
const contractInstance = new ERC20BridgeSamplerContract(txReceipt.contractAddress as string, provider, txDefaults, logDecodeDependencies); const contractInstance = new ERC20BridgeSamplerContract(
txReceipt.contractAddress as string,
provider,
txDefaults,
logDecodeDependencies,
);
contractInstance.constructorArgs = []; contractInstance.constructorArgs = [];
return contractInstance; return contractInstance;
} }
@ -262,7 +270,7 @@ public static async deployFrom0xArtifactAsync(
name: 'takerFeeAssetData', name: 'takerFeeAssetData',
type: 'bytes', type: 'bytes',
}, },
] ],
}, },
{ {
name: 'orderSignatures', name: 'orderSignatures',
@ -343,7 +351,7 @@ public static async deployFrom0xArtifactAsync(
name: 'takerFeeAssetData', name: 'takerFeeAssetData',
type: 'bytes', type: 'bytes',
}, },
] ],
}, },
{ {
name: 'orderSignatures', name: 'orderSignatures',
@ -619,10 +627,7 @@ public static async deployFrom0xArtifactAsync(
libraryAddresses, libraryAddresses,
); );
// Deploy this library. // Deploy this library.
const linkedLibraryBytecode = linkLibrariesInBytecode( const linkedLibraryBytecode = linkLibrariesInBytecode(libraryArtifact, libraryAddresses);
libraryArtifact,
libraryAddresses,
);
const txDataWithDefaults = await BaseContract._applyDefaultsToContractTxDataAsync( const txDataWithDefaults = await BaseContract._applyDefaultsToContractTxDataAsync(
{ {
data: linkedLibraryBytecode, data: linkedLibraryBytecode,
@ -676,33 +681,27 @@ public static async deployFrom0xArtifactAsync(
* @param callDatas ABI-encoded call data for each function call. * @param callDatas ABI-encoded call data for each function call.
* @returns callResults ABI-encoded results data for each call. * @returns callResults ABI-encoded results data for each call.
*/ */
public batchCall( public batchCall(callDatas: string[]): ContractFunctionObj<string[]> {
callDatas: string[], const self = (this as any) as ERC20BridgeSamplerContract;
): ContractFunctionObj<string[]
> {
const self = this as any as ERC20BridgeSamplerContract;
assert.isArray('callDatas', callDatas); assert.isArray('callDatas', callDatas);
const functionSignature = 'batchCall(bytes[])'; const functionSignature = 'batchCall(bytes[])';
return { return {
async callAsync( async callAsync(callData: Partial<CallData> = {}, defaultBlock?: BlockParam): Promise<string[]> {
callData: Partial<CallData> = {},
defaultBlock?: BlockParam,
): Promise<string[]
> {
BaseContract._assertCallParams(callData, defaultBlock); BaseContract._assertCallParams(callData, defaultBlock);
const rawCallResult = await self._performCallAsync({ ...callData, data: this.getABIEncodedTransactionData() }, defaultBlock); const rawCallResult = await self._performCallAsync(
{ ...callData, data: this.getABIEncodedTransactionData() },
defaultBlock,
);
const abiEncoder = self._lookupAbiEncoder(functionSignature); const abiEncoder = self._lookupAbiEncoder(functionSignature);
BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder); BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder);
return abiEncoder.strictDecodeReturnValue<string[] return abiEncoder.strictDecodeReturnValue<string[]>(rawCallResult);
>(rawCallResult);
}, },
getABIEncodedTransactionData(): string { getABIEncodedTransactionData(): string {
return self._strictEncodeArguments(functionSignature, [callDatas return self._strictEncodeArguments(functionSignature, [callDatas]);
]);
}, },
}
}; };
}
/** /**
* Returns the address of a liquidity provider for the given market * Returns the address of a liquidity provider for the given market
* (takerToken, makerToken), from a registry of liquidity providers. * (takerToken, makerToken), from a registry of liquidity providers.
@ -715,35 +714,33 @@ public static async deployFrom0xArtifactAsync(
registryAddress: string, registryAddress: string,
takerToken: string, takerToken: string,
makerToken: string, makerToken: string,
): ContractFunctionObj<string ): ContractFunctionObj<string> {
> { const self = (this as any) as ERC20BridgeSamplerContract;
const self = this as any as ERC20BridgeSamplerContract;
assert.isString('registryAddress', registryAddress); assert.isString('registryAddress', registryAddress);
assert.isString('takerToken', takerToken); assert.isString('takerToken', takerToken);
assert.isString('makerToken', makerToken); assert.isString('makerToken', makerToken);
const functionSignature = 'getLiquidityProviderFromRegistry(address,address,address)'; const functionSignature = 'getLiquidityProviderFromRegistry(address,address,address)';
return { return {
async callAsync( async callAsync(callData: Partial<CallData> = {}, defaultBlock?: BlockParam): Promise<string> {
callData: Partial<CallData> = {},
defaultBlock?: BlockParam,
): Promise<string
> {
BaseContract._assertCallParams(callData, defaultBlock); BaseContract._assertCallParams(callData, defaultBlock);
const rawCallResult = await self._performCallAsync({ ...callData, data: this.getABIEncodedTransactionData() }, defaultBlock); const rawCallResult = await self._performCallAsync(
{ ...callData, data: this.getABIEncodedTransactionData() },
defaultBlock,
);
const abiEncoder = self._lookupAbiEncoder(functionSignature); const abiEncoder = self._lookupAbiEncoder(functionSignature);
BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder); BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder);
return abiEncoder.strictDecodeReturnValue<string return abiEncoder.strictDecodeReturnValue<string>(rawCallResult);
>(rawCallResult);
}, },
getABIEncodedTransactionData(): string { getABIEncodedTransactionData(): string {
return self._strictEncodeArguments(functionSignature, [registryAddress.toLowerCase(), return self._strictEncodeArguments(functionSignature, [
registryAddress.toLowerCase(),
takerToken.toLowerCase(), takerToken.toLowerCase(),
makerToken.toLowerCase() makerToken.toLowerCase(),
]); ]);
}, },
}
}; };
}
/** /**
* Queries the fillable taker asset amounts of native orders. * Queries the fillable taker asset amounts of native orders.
* Effectively ignores orders that have empty signatures or * Effectively ignores orders that have empty signatures or
@ -752,35 +749,46 @@ public static async deployFrom0xArtifactAsync(
* @returns orderFillableMakerAssetAmounts How much maker asset can be filled by each order in &#x60;orders&#x60;. * @returns orderFillableMakerAssetAmounts How much maker asset can be filled by each order in &#x60;orders&#x60;.
*/ */
public getOrderFillableMakerAssetAmounts( public getOrderFillableMakerAssetAmounts(
orders: Array<{makerAddress: string;takerAddress: string;feeRecipientAddress: string;senderAddress: string;makerAssetAmount: BigNumber;takerAssetAmount: BigNumber;makerFee: BigNumber;takerFee: BigNumber;expirationTimeSeconds: BigNumber;salt: BigNumber;makerAssetData: string;takerAssetData: string;makerFeeAssetData: string;takerFeeAssetData: string}>, orders: Array<{
makerAddress: string;
takerAddress: string;
feeRecipientAddress: string;
senderAddress: string;
makerAssetAmount: BigNumber;
takerAssetAmount: BigNumber;
makerFee: BigNumber;
takerFee: BigNumber;
expirationTimeSeconds: BigNumber;
salt: BigNumber;
makerAssetData: string;
takerAssetData: string;
makerFeeAssetData: string;
takerFeeAssetData: string;
}>,
orderSignatures: string[], orderSignatures: string[],
): ContractFunctionObj<BigNumber[] ): ContractFunctionObj<BigNumber[]> {
> { const self = (this as any) as ERC20BridgeSamplerContract;
const self = this as any as ERC20BridgeSamplerContract;
assert.isArray('orders', orders); assert.isArray('orders', orders);
assert.isArray('orderSignatures', orderSignatures); assert.isArray('orderSignatures', orderSignatures);
const functionSignature = 'getOrderFillableMakerAssetAmounts((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes)[],bytes[])'; const functionSignature =
'getOrderFillableMakerAssetAmounts((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes)[],bytes[])';
return { return {
async callAsync( async callAsync(callData: Partial<CallData> = {}, defaultBlock?: BlockParam): Promise<BigNumber[]> {
callData: Partial<CallData> = {},
defaultBlock?: BlockParam,
): Promise<BigNumber[]
> {
BaseContract._assertCallParams(callData, defaultBlock); BaseContract._assertCallParams(callData, defaultBlock);
const rawCallResult = await self._performCallAsync({ ...callData, data: this.getABIEncodedTransactionData() }, defaultBlock); const rawCallResult = await self._performCallAsync(
{ ...callData, data: this.getABIEncodedTransactionData() },
defaultBlock,
);
const abiEncoder = self._lookupAbiEncoder(functionSignature); const abiEncoder = self._lookupAbiEncoder(functionSignature);
BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder); BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder);
return abiEncoder.strictDecodeReturnValue<BigNumber[] return abiEncoder.strictDecodeReturnValue<BigNumber[]>(rawCallResult);
>(rawCallResult);
}, },
getABIEncodedTransactionData(): string { getABIEncodedTransactionData(): string {
return self._strictEncodeArguments(functionSignature, [orders, return self._strictEncodeArguments(functionSignature, [orders, orderSignatures]);
orderSignatures
]);
}, },
}
}; };
}
/** /**
* Queries the fillable taker asset amounts of native orders. * Queries the fillable taker asset amounts of native orders.
* Effectively ignores orders that have empty signatures or * Effectively ignores orders that have empty signatures or
@ -790,35 +798,46 @@ public static async deployFrom0xArtifactAsync(
* @returns orderFillableTakerAssetAmounts How much taker asset can be filled by each order in &#x60;orders&#x60;. * @returns orderFillableTakerAssetAmounts How much taker asset can be filled by each order in &#x60;orders&#x60;.
*/ */
public getOrderFillableTakerAssetAmounts( public getOrderFillableTakerAssetAmounts(
orders: Array<{makerAddress: string;takerAddress: string;feeRecipientAddress: string;senderAddress: string;makerAssetAmount: BigNumber;takerAssetAmount: BigNumber;makerFee: BigNumber;takerFee: BigNumber;expirationTimeSeconds: BigNumber;salt: BigNumber;makerAssetData: string;takerAssetData: string;makerFeeAssetData: string;takerFeeAssetData: string}>, orders: Array<{
makerAddress: string;
takerAddress: string;
feeRecipientAddress: string;
senderAddress: string;
makerAssetAmount: BigNumber;
takerAssetAmount: BigNumber;
makerFee: BigNumber;
takerFee: BigNumber;
expirationTimeSeconds: BigNumber;
salt: BigNumber;
makerAssetData: string;
takerAssetData: string;
makerFeeAssetData: string;
takerFeeAssetData: string;
}>,
orderSignatures: string[], orderSignatures: string[],
): ContractFunctionObj<BigNumber[] ): ContractFunctionObj<BigNumber[]> {
> { const self = (this as any) as ERC20BridgeSamplerContract;
const self = this as any as ERC20BridgeSamplerContract;
assert.isArray('orders', orders); assert.isArray('orders', orders);
assert.isArray('orderSignatures', orderSignatures); assert.isArray('orderSignatures', orderSignatures);
const functionSignature = 'getOrderFillableTakerAssetAmounts((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes)[],bytes[])'; const functionSignature =
'getOrderFillableTakerAssetAmounts((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes)[],bytes[])';
return { return {
async callAsync( async callAsync(callData: Partial<CallData> = {}, defaultBlock?: BlockParam): Promise<BigNumber[]> {
callData: Partial<CallData> = {},
defaultBlock?: BlockParam,
): Promise<BigNumber[]
> {
BaseContract._assertCallParams(callData, defaultBlock); BaseContract._assertCallParams(callData, defaultBlock);
const rawCallResult = await self._performCallAsync({ ...callData, data: this.getABIEncodedTransactionData() }, defaultBlock); const rawCallResult = await self._performCallAsync(
{ ...callData, data: this.getABIEncodedTransactionData() },
defaultBlock,
);
const abiEncoder = self._lookupAbiEncoder(functionSignature); const abiEncoder = self._lookupAbiEncoder(functionSignature);
BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder); BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder);
return abiEncoder.strictDecodeReturnValue<BigNumber[] return abiEncoder.strictDecodeReturnValue<BigNumber[]>(rawCallResult);
>(rawCallResult);
}, },
getABIEncodedTransactionData(): string { getABIEncodedTransactionData(): string {
return self._strictEncodeArguments(functionSignature, [orders, return self._strictEncodeArguments(functionSignature, [orders, orderSignatures]);
orderSignatures
]);
}, },
}
}; };
}
/** /**
* Sample buy quotes from Eth2Dai/Oasis. * Sample buy quotes from Eth2Dai/Oasis.
* @param takerToken Address of the taker token (what to sell). * @param takerToken Address of the taker token (what to sell).
@ -829,35 +848,33 @@ public static async deployFrom0xArtifactAsync(
takerToken: string, takerToken: string,
makerToken: string, makerToken: string,
makerTokenAmounts: BigNumber[], makerTokenAmounts: BigNumber[],
): ContractFunctionObj<BigNumber[] ): ContractFunctionObj<BigNumber[]> {
> { const self = (this as any) as ERC20BridgeSamplerContract;
const self = this as any as ERC20BridgeSamplerContract;
assert.isString('takerToken', takerToken); assert.isString('takerToken', takerToken);
assert.isString('makerToken', makerToken); assert.isString('makerToken', makerToken);
assert.isArray('makerTokenAmounts', makerTokenAmounts); assert.isArray('makerTokenAmounts', makerTokenAmounts);
const functionSignature = 'sampleBuysFromEth2Dai(address,address,uint256[])'; const functionSignature = 'sampleBuysFromEth2Dai(address,address,uint256[])';
return { return {
async callAsync( async callAsync(callData: Partial<CallData> = {}, defaultBlock?: BlockParam): Promise<BigNumber[]> {
callData: Partial<CallData> = {},
defaultBlock?: BlockParam,
): Promise<BigNumber[]
> {
BaseContract._assertCallParams(callData, defaultBlock); BaseContract._assertCallParams(callData, defaultBlock);
const rawCallResult = await self._performCallAsync({ ...callData, data: this.getABIEncodedTransactionData() }, defaultBlock); const rawCallResult = await self._performCallAsync(
{ ...callData, data: this.getABIEncodedTransactionData() },
defaultBlock,
);
const abiEncoder = self._lookupAbiEncoder(functionSignature); const abiEncoder = self._lookupAbiEncoder(functionSignature);
BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder); BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder);
return abiEncoder.strictDecodeReturnValue<BigNumber[] return abiEncoder.strictDecodeReturnValue<BigNumber[]>(rawCallResult);
>(rawCallResult);
}, },
getABIEncodedTransactionData(): string { getABIEncodedTransactionData(): string {
return self._strictEncodeArguments(functionSignature, [takerToken.toLowerCase(), return self._strictEncodeArguments(functionSignature, [
takerToken.toLowerCase(),
makerToken.toLowerCase(), makerToken.toLowerCase(),
makerTokenAmounts makerTokenAmounts,
]); ]);
}, },
}
}; };
}
/** /**
* Sample buy quotes from an arbitrary on-chain liquidity provider. * Sample buy quotes from an arbitrary on-chain liquidity provider.
* @param registryAddress Address of the liquidity provider registry contract. * @param registryAddress Address of the liquidity provider registry contract.
@ -871,9 +888,8 @@ public static async deployFrom0xArtifactAsync(
takerToken: string, takerToken: string,
makerToken: string, makerToken: string,
makerTokenAmounts: BigNumber[], makerTokenAmounts: BigNumber[],
): ContractFunctionObj<BigNumber[] ): ContractFunctionObj<BigNumber[]> {
> { const self = (this as any) as ERC20BridgeSamplerContract;
const self = this as any as ERC20BridgeSamplerContract;
assert.isString('registryAddress', registryAddress); assert.isString('registryAddress', registryAddress);
assert.isString('takerToken', takerToken); assert.isString('takerToken', takerToken);
assert.isString('makerToken', makerToken); assert.isString('makerToken', makerToken);
@ -881,27 +897,26 @@ public static async deployFrom0xArtifactAsync(
const functionSignature = 'sampleBuysFromLiquidityProviderRegistry(address,address,address,uint256[])'; const functionSignature = 'sampleBuysFromLiquidityProviderRegistry(address,address,address,uint256[])';
return { return {
async callAsync( async callAsync(callData: Partial<CallData> = {}, defaultBlock?: BlockParam): Promise<BigNumber[]> {
callData: Partial<CallData> = {},
defaultBlock?: BlockParam,
): Promise<BigNumber[]
> {
BaseContract._assertCallParams(callData, defaultBlock); BaseContract._assertCallParams(callData, defaultBlock);
const rawCallResult = await self._performCallAsync({ ...callData, data: this.getABIEncodedTransactionData() }, defaultBlock); const rawCallResult = await self._performCallAsync(
{ ...callData, data: this.getABIEncodedTransactionData() },
defaultBlock,
);
const abiEncoder = self._lookupAbiEncoder(functionSignature); const abiEncoder = self._lookupAbiEncoder(functionSignature);
BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder); BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder);
return abiEncoder.strictDecodeReturnValue<BigNumber[] return abiEncoder.strictDecodeReturnValue<BigNumber[]>(rawCallResult);
>(rawCallResult);
}, },
getABIEncodedTransactionData(): string { getABIEncodedTransactionData(): string {
return self._strictEncodeArguments(functionSignature, [registryAddress.toLowerCase(), return self._strictEncodeArguments(functionSignature, [
registryAddress.toLowerCase(),
takerToken.toLowerCase(), takerToken.toLowerCase(),
makerToken.toLowerCase(), makerToken.toLowerCase(),
makerTokenAmounts makerTokenAmounts,
]); ]);
}, },
}
}; };
}
/** /**
* Sample buy quotes from Uniswap. * Sample buy quotes from Uniswap.
* @param takerToken Address of the taker token (what to sell). * @param takerToken Address of the taker token (what to sell).
@ -913,35 +928,33 @@ public static async deployFrom0xArtifactAsync(
takerToken: string, takerToken: string,
makerToken: string, makerToken: string,
makerTokenAmounts: BigNumber[], makerTokenAmounts: BigNumber[],
): ContractFunctionObj<BigNumber[] ): ContractFunctionObj<BigNumber[]> {
> { const self = (this as any) as ERC20BridgeSamplerContract;
const self = this as any as ERC20BridgeSamplerContract;
assert.isString('takerToken', takerToken); assert.isString('takerToken', takerToken);
assert.isString('makerToken', makerToken); assert.isString('makerToken', makerToken);
assert.isArray('makerTokenAmounts', makerTokenAmounts); assert.isArray('makerTokenAmounts', makerTokenAmounts);
const functionSignature = 'sampleBuysFromUniswap(address,address,uint256[])'; const functionSignature = 'sampleBuysFromUniswap(address,address,uint256[])';
return { return {
async callAsync( async callAsync(callData: Partial<CallData> = {}, defaultBlock?: BlockParam): Promise<BigNumber[]> {
callData: Partial<CallData> = {},
defaultBlock?: BlockParam,
): Promise<BigNumber[]
> {
BaseContract._assertCallParams(callData, defaultBlock); BaseContract._assertCallParams(callData, defaultBlock);
const rawCallResult = await self._performCallAsync({ ...callData, data: this.getABIEncodedTransactionData() }, defaultBlock); const rawCallResult = await self._performCallAsync(
{ ...callData, data: this.getABIEncodedTransactionData() },
defaultBlock,
);
const abiEncoder = self._lookupAbiEncoder(functionSignature); const abiEncoder = self._lookupAbiEncoder(functionSignature);
BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder); BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder);
return abiEncoder.strictDecodeReturnValue<BigNumber[] return abiEncoder.strictDecodeReturnValue<BigNumber[]>(rawCallResult);
>(rawCallResult);
}, },
getABIEncodedTransactionData(): string { getABIEncodedTransactionData(): string {
return self._strictEncodeArguments(functionSignature, [takerToken.toLowerCase(), return self._strictEncodeArguments(functionSignature, [
takerToken.toLowerCase(),
makerToken.toLowerCase(), makerToken.toLowerCase(),
makerTokenAmounts makerTokenAmounts,
]); ]);
}, },
}
}; };
}
/** /**
* Sample sell quotes from Curve. * Sample sell quotes from Curve.
* @param curveAddress Address of the Curve contract. * @param curveAddress Address of the Curve contract.
@ -955,9 +968,8 @@ public static async deployFrom0xArtifactAsync(
fromTokenIdx: BigNumber, fromTokenIdx: BigNumber,
toTokenIdx: BigNumber, toTokenIdx: BigNumber,
takerTokenAmounts: BigNumber[], takerTokenAmounts: BigNumber[],
): ContractFunctionObj<BigNumber[] ): ContractFunctionObj<BigNumber[]> {
> { const self = (this as any) as ERC20BridgeSamplerContract;
const self = this as any as ERC20BridgeSamplerContract;
assert.isString('curveAddress', curveAddress); assert.isString('curveAddress', curveAddress);
assert.isBigNumber('fromTokenIdx', fromTokenIdx); assert.isBigNumber('fromTokenIdx', fromTokenIdx);
assert.isBigNumber('toTokenIdx', toTokenIdx); assert.isBigNumber('toTokenIdx', toTokenIdx);
@ -965,27 +977,26 @@ public static async deployFrom0xArtifactAsync(
const functionSignature = 'sampleSellsFromCurve(address,int128,int128,uint256[])'; const functionSignature = 'sampleSellsFromCurve(address,int128,int128,uint256[])';
return { return {
async callAsync( async callAsync(callData: Partial<CallData> = {}, defaultBlock?: BlockParam): Promise<BigNumber[]> {
callData: Partial<CallData> = {},
defaultBlock?: BlockParam,
): Promise<BigNumber[]
> {
BaseContract._assertCallParams(callData, defaultBlock); BaseContract._assertCallParams(callData, defaultBlock);
const rawCallResult = await self._performCallAsync({ ...callData, data: this.getABIEncodedTransactionData() }, defaultBlock); const rawCallResult = await self._performCallAsync(
{ ...callData, data: this.getABIEncodedTransactionData() },
defaultBlock,
);
const abiEncoder = self._lookupAbiEncoder(functionSignature); const abiEncoder = self._lookupAbiEncoder(functionSignature);
BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder); BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder);
return abiEncoder.strictDecodeReturnValue<BigNumber[] return abiEncoder.strictDecodeReturnValue<BigNumber[]>(rawCallResult);
>(rawCallResult);
}, },
getABIEncodedTransactionData(): string { getABIEncodedTransactionData(): string {
return self._strictEncodeArguments(functionSignature, [curveAddress.toLowerCase(), return self._strictEncodeArguments(functionSignature, [
curveAddress.toLowerCase(),
fromTokenIdx, fromTokenIdx,
toTokenIdx, toTokenIdx,
takerTokenAmounts takerTokenAmounts,
]); ]);
}, },
}
}; };
}
/** /**
* Sample sell quotes from Eth2Dai/Oasis. * Sample sell quotes from Eth2Dai/Oasis.
* @param takerToken Address of the taker token (what to sell). * @param takerToken Address of the taker token (what to sell).
@ -997,35 +1008,33 @@ public static async deployFrom0xArtifactAsync(
takerToken: string, takerToken: string,
makerToken: string, makerToken: string,
takerTokenAmounts: BigNumber[], takerTokenAmounts: BigNumber[],
): ContractFunctionObj<BigNumber[] ): ContractFunctionObj<BigNumber[]> {
> { const self = (this as any) as ERC20BridgeSamplerContract;
const self = this as any as ERC20BridgeSamplerContract;
assert.isString('takerToken', takerToken); assert.isString('takerToken', takerToken);
assert.isString('makerToken', makerToken); assert.isString('makerToken', makerToken);
assert.isArray('takerTokenAmounts', takerTokenAmounts); assert.isArray('takerTokenAmounts', takerTokenAmounts);
const functionSignature = 'sampleSellsFromEth2Dai(address,address,uint256[])'; const functionSignature = 'sampleSellsFromEth2Dai(address,address,uint256[])';
return { return {
async callAsync( async callAsync(callData: Partial<CallData> = {}, defaultBlock?: BlockParam): Promise<BigNumber[]> {
callData: Partial<CallData> = {},
defaultBlock?: BlockParam,
): Promise<BigNumber[]
> {
BaseContract._assertCallParams(callData, defaultBlock); BaseContract._assertCallParams(callData, defaultBlock);
const rawCallResult = await self._performCallAsync({ ...callData, data: this.getABIEncodedTransactionData() }, defaultBlock); const rawCallResult = await self._performCallAsync(
{ ...callData, data: this.getABIEncodedTransactionData() },
defaultBlock,
);
const abiEncoder = self._lookupAbiEncoder(functionSignature); const abiEncoder = self._lookupAbiEncoder(functionSignature);
BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder); BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder);
return abiEncoder.strictDecodeReturnValue<BigNumber[] return abiEncoder.strictDecodeReturnValue<BigNumber[]>(rawCallResult);
>(rawCallResult);
}, },
getABIEncodedTransactionData(): string { getABIEncodedTransactionData(): string {
return self._strictEncodeArguments(functionSignature, [takerToken.toLowerCase(), return self._strictEncodeArguments(functionSignature, [
takerToken.toLowerCase(),
makerToken.toLowerCase(), makerToken.toLowerCase(),
takerTokenAmounts takerTokenAmounts,
]); ]);
}, },
}
}; };
}
/** /**
* Sample sell quotes from Kyber. * Sample sell quotes from Kyber.
* @param takerToken Address of the taker token (what to sell). * @param takerToken Address of the taker token (what to sell).
@ -1037,35 +1046,33 @@ public static async deployFrom0xArtifactAsync(
takerToken: string, takerToken: string,
makerToken: string, makerToken: string,
takerTokenAmounts: BigNumber[], takerTokenAmounts: BigNumber[],
): ContractFunctionObj<BigNumber[] ): ContractFunctionObj<BigNumber[]> {
> { const self = (this as any) as ERC20BridgeSamplerContract;
const self = this as any as ERC20BridgeSamplerContract;
assert.isString('takerToken', takerToken); assert.isString('takerToken', takerToken);
assert.isString('makerToken', makerToken); assert.isString('makerToken', makerToken);
assert.isArray('takerTokenAmounts', takerTokenAmounts); assert.isArray('takerTokenAmounts', takerTokenAmounts);
const functionSignature = 'sampleSellsFromKyberNetwork(address,address,uint256[])'; const functionSignature = 'sampleSellsFromKyberNetwork(address,address,uint256[])';
return { return {
async callAsync( async callAsync(callData: Partial<CallData> = {}, defaultBlock?: BlockParam): Promise<BigNumber[]> {
callData: Partial<CallData> = {},
defaultBlock?: BlockParam,
): Promise<BigNumber[]
> {
BaseContract._assertCallParams(callData, defaultBlock); BaseContract._assertCallParams(callData, defaultBlock);
const rawCallResult = await self._performCallAsync({ ...callData, data: this.getABIEncodedTransactionData() }, defaultBlock); const rawCallResult = await self._performCallAsync(
{ ...callData, data: this.getABIEncodedTransactionData() },
defaultBlock,
);
const abiEncoder = self._lookupAbiEncoder(functionSignature); const abiEncoder = self._lookupAbiEncoder(functionSignature);
BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder); BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder);
return abiEncoder.strictDecodeReturnValue<BigNumber[] return abiEncoder.strictDecodeReturnValue<BigNumber[]>(rawCallResult);
>(rawCallResult);
}, },
getABIEncodedTransactionData(): string { getABIEncodedTransactionData(): string {
return self._strictEncodeArguments(functionSignature, [takerToken.toLowerCase(), return self._strictEncodeArguments(functionSignature, [
takerToken.toLowerCase(),
makerToken.toLowerCase(), makerToken.toLowerCase(),
takerTokenAmounts takerTokenAmounts,
]); ]);
}, },
}
}; };
}
/** /**
* Sample sell quotes from an arbitrary on-chain liquidity provider. * Sample sell quotes from an arbitrary on-chain liquidity provider.
* @param registryAddress Address of the liquidity provider registry contract. * @param registryAddress Address of the liquidity provider registry contract.
@ -1079,9 +1086,8 @@ public static async deployFrom0xArtifactAsync(
takerToken: string, takerToken: string,
makerToken: string, makerToken: string,
takerTokenAmounts: BigNumber[], takerTokenAmounts: BigNumber[],
): ContractFunctionObj<BigNumber[] ): ContractFunctionObj<BigNumber[]> {
> { const self = (this as any) as ERC20BridgeSamplerContract;
const self = this as any as ERC20BridgeSamplerContract;
assert.isString('registryAddress', registryAddress); assert.isString('registryAddress', registryAddress);
assert.isString('takerToken', takerToken); assert.isString('takerToken', takerToken);
assert.isString('makerToken', makerToken); assert.isString('makerToken', makerToken);
@ -1089,27 +1095,26 @@ public static async deployFrom0xArtifactAsync(
const functionSignature = 'sampleSellsFromLiquidityProviderRegistry(address,address,address,uint256[])'; const functionSignature = 'sampleSellsFromLiquidityProviderRegistry(address,address,address,uint256[])';
return { return {
async callAsync( async callAsync(callData: Partial<CallData> = {}, defaultBlock?: BlockParam): Promise<BigNumber[]> {
callData: Partial<CallData> = {},
defaultBlock?: BlockParam,
): Promise<BigNumber[]
> {
BaseContract._assertCallParams(callData, defaultBlock); BaseContract._assertCallParams(callData, defaultBlock);
const rawCallResult = await self._performCallAsync({ ...callData, data: this.getABIEncodedTransactionData() }, defaultBlock); const rawCallResult = await self._performCallAsync(
{ ...callData, data: this.getABIEncodedTransactionData() },
defaultBlock,
);
const abiEncoder = self._lookupAbiEncoder(functionSignature); const abiEncoder = self._lookupAbiEncoder(functionSignature);
BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder); BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder);
return abiEncoder.strictDecodeReturnValue<BigNumber[] return abiEncoder.strictDecodeReturnValue<BigNumber[]>(rawCallResult);
>(rawCallResult);
}, },
getABIEncodedTransactionData(): string { getABIEncodedTransactionData(): string {
return self._strictEncodeArguments(functionSignature, [registryAddress.toLowerCase(), return self._strictEncodeArguments(functionSignature, [
registryAddress.toLowerCase(),
takerToken.toLowerCase(), takerToken.toLowerCase(),
makerToken.toLowerCase(), makerToken.toLowerCase(),
takerTokenAmounts takerTokenAmounts,
]); ]);
}, },
}
}; };
}
/** /**
* Sample sell quotes from Uniswap. * Sample sell quotes from Uniswap.
* @param takerToken Address of the taker token (what to sell). * @param takerToken Address of the taker token (what to sell).
@ -1121,37 +1126,33 @@ public static async deployFrom0xArtifactAsync(
takerToken: string, takerToken: string,
makerToken: string, makerToken: string,
takerTokenAmounts: BigNumber[], takerTokenAmounts: BigNumber[],
): ContractFunctionObj<BigNumber[] ): ContractFunctionObj<BigNumber[]> {
> { const self = (this as any) as ERC20BridgeSamplerContract;
const self = this as any as ERC20BridgeSamplerContract;
assert.isString('takerToken', takerToken); assert.isString('takerToken', takerToken);
assert.isString('makerToken', makerToken); assert.isString('makerToken', makerToken);
assert.isArray('takerTokenAmounts', takerTokenAmounts); assert.isArray('takerTokenAmounts', takerTokenAmounts);
const functionSignature = 'sampleSellsFromUniswap(address,address,uint256[])'; const functionSignature = 'sampleSellsFromUniswap(address,address,uint256[])';
return { return {
async callAsync( async callAsync(callData: Partial<CallData> = {}, defaultBlock?: BlockParam): Promise<BigNumber[]> {
callData: Partial<CallData> = {},
defaultBlock?: BlockParam,
): Promise<BigNumber[]
> {
BaseContract._assertCallParams(callData, defaultBlock); BaseContract._assertCallParams(callData, defaultBlock);
const rawCallResult = await self._performCallAsync({ ...callData, data: this.getABIEncodedTransactionData() }, defaultBlock); const rawCallResult = await self._performCallAsync(
{ ...callData, data: this.getABIEncodedTransactionData() },
defaultBlock,
);
const abiEncoder = self._lookupAbiEncoder(functionSignature); const abiEncoder = self._lookupAbiEncoder(functionSignature);
BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder); BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder);
return abiEncoder.strictDecodeReturnValue<BigNumber[] return abiEncoder.strictDecodeReturnValue<BigNumber[]>(rawCallResult);
>(rawCallResult);
}, },
getABIEncodedTransactionData(): string { getABIEncodedTransactionData(): string {
return self._strictEncodeArguments(functionSignature, [takerToken.toLowerCase(), return self._strictEncodeArguments(functionSignature, [
takerToken.toLowerCase(),
makerToken.toLowerCase(), makerToken.toLowerCase(),
takerTokenAmounts takerTokenAmounts,
]); ]);
}, },
}
}; };
}
constructor( constructor(
address: string, address: string,
@ -1160,7 +1161,15 @@ public static async deployFrom0xArtifactAsync(
logDecodeDependencies?: { [contractName: string]: ContractAbi }, logDecodeDependencies?: { [contractName: string]: ContractAbi },
deployedBytecode: string | undefined = ERC20BridgeSamplerContract.deployedBytecode, deployedBytecode: string | undefined = ERC20BridgeSamplerContract.deployedBytecode,
) { ) {
super('ERC20BridgeSampler', ERC20BridgeSamplerContract.ABI(), address, supportedProvider, txDefaults, logDecodeDependencies, deployedBytecode); super(
'ERC20BridgeSampler',
ERC20BridgeSamplerContract.ABI(),
address,
supportedProvider,
txDefaults,
logDecodeDependencies,
deployedBytecode,
);
classUtils.bindAll(this, ['_abiEncoderByFunctionSignature', 'address', '_web3Wrapper']); classUtils.bindAll(this, ['_abiEncoderByFunctionSignature', 'address', '_web3Wrapper']);
ERC20BridgeSamplerContract.ABI().forEach((item, index) => { ERC20BridgeSamplerContract.ABI().forEach((item, index) => {
if (item.type === 'function') { if (item.type === 'function') {

View File

@ -33,8 +33,6 @@ import { assert } from '@0x/assert';
import * as ethers from 'ethers'; import * as ethers from 'ethers';
// tslint:enable:no-unused-variable // tslint:enable:no-unused-variable
/* istanbul ignore next */ /* istanbul ignore next */
// tslint:disable:array-type // tslint:disable:array-type
// tslint:disable:no-parameter-reassignment // tslint:disable:no-parameter-reassignment
@ -50,7 +48,7 @@ public static async deployFrom0xArtifactAsync(
artifact: ContractArtifact | SimpleContractArtifact, artifact: ContractArtifact | SimpleContractArtifact,
supportedProvider: SupportedProvider, supportedProvider: SupportedProvider,
txDefaults: Partial<TxData>, txDefaults: Partial<TxData>,
logDecodeDependencies: { [contractName: string]: (ContractArtifact | SimpleContractArtifact) }, logDecodeDependencies: { [contractName: string]: ContractArtifact | SimpleContractArtifact },
): Promise<IERC20BridgeSamplerContract> { ): Promise<IERC20BridgeSamplerContract> {
assert.doesConformToSchema('txDefaults', txDefaults, schemas.txDataSchema, [ assert.doesConformToSchema('txDefaults', txDefaults, schemas.txDataSchema, [
schemas.addressSchema, schemas.addressSchema,
@ -69,7 +67,13 @@ public static async deployFrom0xArtifactAsync(
logDecodeDependenciesAbiOnly[key] = logDecodeDependencies[key].compilerOutput.abi; logDecodeDependenciesAbiOnly[key] = logDecodeDependencies[key].compilerOutput.abi;
} }
} }
return IERC20BridgeSamplerContract.deployAsync(bytecode, abi, provider, txDefaults, logDecodeDependenciesAbiOnly, ); return IERC20BridgeSamplerContract.deployAsync(
bytecode,
abi,
provider,
txDefaults,
logDecodeDependenciesAbiOnly,
);
} }
public static async deployWithLibrariesFrom0xArtifactAsync( public static async deployWithLibrariesFrom0xArtifactAsync(
@ -77,7 +81,7 @@ public static async deployFrom0xArtifactAsync(
libraryArtifacts: { [libraryName: string]: ContractArtifact }, libraryArtifacts: { [libraryName: string]: ContractArtifact },
supportedProvider: SupportedProvider, supportedProvider: SupportedProvider,
txDefaults: Partial<TxData>, txDefaults: Partial<TxData>,
logDecodeDependencies: { [contractName: string]: (ContractArtifact | SimpleContractArtifact) }, logDecodeDependencies: { [contractName: string]: ContractArtifact | SimpleContractArtifact },
): Promise<IERC20BridgeSamplerContract> { ): Promise<IERC20BridgeSamplerContract> {
assert.doesConformToSchema('txDefaults', txDefaults, schemas.txDataSchema, [ assert.doesConformToSchema('txDefaults', txDefaults, schemas.txDataSchema, [
schemas.addressSchema, schemas.addressSchema,
@ -99,13 +103,16 @@ public static async deployFrom0xArtifactAsync(
artifact, artifact,
libraryArtifacts, libraryArtifacts,
new Web3Wrapper(provider), new Web3Wrapper(provider),
txDefaults txDefaults,
); );
const bytecode = linkLibrariesInBytecode( const bytecode = linkLibrariesInBytecode(artifact, libraryAddresses);
artifact, return IERC20BridgeSamplerContract.deployAsync(
libraryAddresses, bytecode,
abi,
provider,
txDefaults,
logDecodeDependenciesAbiOnly,
); );
return IERC20BridgeSamplerContract.deployAsync(bytecode, abi, provider, txDefaults, logDecodeDependenciesAbiOnly, );
} }
public static async deployAsync( public static async deployAsync(
@ -123,11 +130,7 @@ public static async deployFrom0xArtifactAsync(
]); ]);
const provider = providerUtils.standardizeOrThrow(supportedProvider); const provider = providerUtils.standardizeOrThrow(supportedProvider);
const constructorAbi = BaseContract._lookupConstructorAbi(abi); const constructorAbi = BaseContract._lookupConstructorAbi(abi);
[] = BaseContract._formatABIDataItemList( [] = BaseContract._formatABIDataItemList(constructorAbi.inputs, [], BaseContract._bigNumberToString);
constructorAbi.inputs,
[],
BaseContract._bigNumberToString,
);
const iface = new ethers.utils.Interface(abi); const iface = new ethers.utils.Interface(abi);
const deployInfo = iface.deployFunction; const deployInfo = iface.deployFunction;
const txData = deployInfo.encode(bytecode, []); const txData = deployInfo.encode(bytecode, []);
@ -143,7 +146,12 @@ public static async deployFrom0xArtifactAsync(
logUtils.log(`transactionHash: ${txHash}`); logUtils.log(`transactionHash: ${txHash}`);
const txReceipt = await web3Wrapper.awaitTransactionSuccessAsync(txHash); const txReceipt = await web3Wrapper.awaitTransactionSuccessAsync(txHash);
logUtils.log(`IERC20BridgeSampler successfully deployed at ${txReceipt.contractAddress}`); logUtils.log(`IERC20BridgeSampler successfully deployed at ${txReceipt.contractAddress}`);
const contractInstance = new IERC20BridgeSamplerContract(txReceipt.contractAddress as string, provider, txDefaults, logDecodeDependencies); const contractInstance = new IERC20BridgeSamplerContract(
txReceipt.contractAddress as string,
provider,
txDefaults,
logDecodeDependencies,
);
contractInstance.constructorArgs = []; contractInstance.constructorArgs = [];
return contractInstance; return contractInstance;
} }
@ -262,7 +270,7 @@ public static async deployFrom0xArtifactAsync(
name: 'takerFeeAssetData', name: 'takerFeeAssetData',
type: 'bytes', type: 'bytes',
}, },
] ],
}, },
{ {
name: 'orderSignatures', name: 'orderSignatures',
@ -343,7 +351,7 @@ public static async deployFrom0xArtifactAsync(
name: 'takerFeeAssetData', name: 'takerFeeAssetData',
type: 'bytes', type: 'bytes',
}, },
] ],
}, },
{ {
name: 'orderSignatures', name: 'orderSignatures',
@ -619,10 +627,7 @@ public static async deployFrom0xArtifactAsync(
libraryAddresses, libraryAddresses,
); );
// Deploy this library. // Deploy this library.
const linkedLibraryBytecode = linkLibrariesInBytecode( const linkedLibraryBytecode = linkLibrariesInBytecode(libraryArtifact, libraryAddresses);
libraryArtifact,
libraryAddresses,
);
const txDataWithDefaults = await BaseContract._applyDefaultsToContractTxDataAsync( const txDataWithDefaults = await BaseContract._applyDefaultsToContractTxDataAsync(
{ {
data: linkedLibraryBytecode, data: linkedLibraryBytecode,
@ -676,33 +681,27 @@ public static async deployFrom0xArtifactAsync(
* @param callDatas ABI-encoded call data for each function call. * @param callDatas ABI-encoded call data for each function call.
* @returns callResults ABI-encoded results data for each call. * @returns callResults ABI-encoded results data for each call.
*/ */
public batchCall( public batchCall(callDatas: string[]): ContractFunctionObj<string[]> {
callDatas: string[], const self = (this as any) as IERC20BridgeSamplerContract;
): ContractFunctionObj<string[]
> {
const self = this as any as IERC20BridgeSamplerContract;
assert.isArray('callDatas', callDatas); assert.isArray('callDatas', callDatas);
const functionSignature = 'batchCall(bytes[])'; const functionSignature = 'batchCall(bytes[])';
return { return {
async callAsync( async callAsync(callData: Partial<CallData> = {}, defaultBlock?: BlockParam): Promise<string[]> {
callData: Partial<CallData> = {},
defaultBlock?: BlockParam,
): Promise<string[]
> {
BaseContract._assertCallParams(callData, defaultBlock); BaseContract._assertCallParams(callData, defaultBlock);
const rawCallResult = await self._performCallAsync({ ...callData, data: this.getABIEncodedTransactionData() }, defaultBlock); const rawCallResult = await self._performCallAsync(
{ ...callData, data: this.getABIEncodedTransactionData() },
defaultBlock,
);
const abiEncoder = self._lookupAbiEncoder(functionSignature); const abiEncoder = self._lookupAbiEncoder(functionSignature);
BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder); BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder);
return abiEncoder.strictDecodeReturnValue<string[] return abiEncoder.strictDecodeReturnValue<string[]>(rawCallResult);
>(rawCallResult);
}, },
getABIEncodedTransactionData(): string { getABIEncodedTransactionData(): string {
return self._strictEncodeArguments(functionSignature, [callDatas return self._strictEncodeArguments(functionSignature, [callDatas]);
]);
}, },
}
}; };
}
/** /**
* Returns the address of a liquidity provider for the given market * Returns the address of a liquidity provider for the given market
* (takerToken, makerToken), from a registry of liquidity providers. * (takerToken, makerToken), from a registry of liquidity providers.
@ -715,35 +714,33 @@ public static async deployFrom0xArtifactAsync(
registryAddress: string, registryAddress: string,
takerToken: string, takerToken: string,
makerToken: string, makerToken: string,
): ContractFunctionObj<string ): ContractFunctionObj<string> {
> { const self = (this as any) as IERC20BridgeSamplerContract;
const self = this as any as IERC20BridgeSamplerContract;
assert.isString('registryAddress', registryAddress); assert.isString('registryAddress', registryAddress);
assert.isString('takerToken', takerToken); assert.isString('takerToken', takerToken);
assert.isString('makerToken', makerToken); assert.isString('makerToken', makerToken);
const functionSignature = 'getLiquidityProviderFromRegistry(address,address,address)'; const functionSignature = 'getLiquidityProviderFromRegistry(address,address,address)';
return { return {
async callAsync( async callAsync(callData: Partial<CallData> = {}, defaultBlock?: BlockParam): Promise<string> {
callData: Partial<CallData> = {},
defaultBlock?: BlockParam,
): Promise<string
> {
BaseContract._assertCallParams(callData, defaultBlock); BaseContract._assertCallParams(callData, defaultBlock);
const rawCallResult = await self._performCallAsync({ ...callData, data: this.getABIEncodedTransactionData() }, defaultBlock); const rawCallResult = await self._performCallAsync(
{ ...callData, data: this.getABIEncodedTransactionData() },
defaultBlock,
);
const abiEncoder = self._lookupAbiEncoder(functionSignature); const abiEncoder = self._lookupAbiEncoder(functionSignature);
BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder); BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder);
return abiEncoder.strictDecodeReturnValue<string return abiEncoder.strictDecodeReturnValue<string>(rawCallResult);
>(rawCallResult);
}, },
getABIEncodedTransactionData(): string { getABIEncodedTransactionData(): string {
return self._strictEncodeArguments(functionSignature, [registryAddress.toLowerCase(), return self._strictEncodeArguments(functionSignature, [
registryAddress.toLowerCase(),
takerToken.toLowerCase(), takerToken.toLowerCase(),
makerToken.toLowerCase() makerToken.toLowerCase(),
]); ]);
}, },
}
}; };
}
/** /**
* Queries the fillable maker asset amounts of native orders. * Queries the fillable maker asset amounts of native orders.
* @param orders Native orders to query. * @param orders Native orders to query.
@ -751,35 +748,46 @@ public static async deployFrom0xArtifactAsync(
* @returns orderFillableMakerAssetAmounts How much maker asset can be filled by each order in &#x60;orders&#x60;. * @returns orderFillableMakerAssetAmounts How much maker asset can be filled by each order in &#x60;orders&#x60;.
*/ */
public getOrderFillableMakerAssetAmounts( public getOrderFillableMakerAssetAmounts(
orders: Array<{makerAddress: string;takerAddress: string;feeRecipientAddress: string;senderAddress: string;makerAssetAmount: BigNumber;takerAssetAmount: BigNumber;makerFee: BigNumber;takerFee: BigNumber;expirationTimeSeconds: BigNumber;salt: BigNumber;makerAssetData: string;takerAssetData: string;makerFeeAssetData: string;takerFeeAssetData: string}>, orders: Array<{
makerAddress: string;
takerAddress: string;
feeRecipientAddress: string;
senderAddress: string;
makerAssetAmount: BigNumber;
takerAssetAmount: BigNumber;
makerFee: BigNumber;
takerFee: BigNumber;
expirationTimeSeconds: BigNumber;
salt: BigNumber;
makerAssetData: string;
takerAssetData: string;
makerFeeAssetData: string;
takerFeeAssetData: string;
}>,
orderSignatures: string[], orderSignatures: string[],
): ContractFunctionObj<BigNumber[] ): ContractFunctionObj<BigNumber[]> {
> { const self = (this as any) as IERC20BridgeSamplerContract;
const self = this as any as IERC20BridgeSamplerContract;
assert.isArray('orders', orders); assert.isArray('orders', orders);
assert.isArray('orderSignatures', orderSignatures); assert.isArray('orderSignatures', orderSignatures);
const functionSignature = 'getOrderFillableMakerAssetAmounts((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes)[],bytes[])'; const functionSignature =
'getOrderFillableMakerAssetAmounts((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes)[],bytes[])';
return { return {
async callAsync( async callAsync(callData: Partial<CallData> = {}, defaultBlock?: BlockParam): Promise<BigNumber[]> {
callData: Partial<CallData> = {},
defaultBlock?: BlockParam,
): Promise<BigNumber[]
> {
BaseContract._assertCallParams(callData, defaultBlock); BaseContract._assertCallParams(callData, defaultBlock);
const rawCallResult = await self._performCallAsync({ ...callData, data: this.getABIEncodedTransactionData() }, defaultBlock); const rawCallResult = await self._performCallAsync(
{ ...callData, data: this.getABIEncodedTransactionData() },
defaultBlock,
);
const abiEncoder = self._lookupAbiEncoder(functionSignature); const abiEncoder = self._lookupAbiEncoder(functionSignature);
BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder); BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder);
return abiEncoder.strictDecodeReturnValue<BigNumber[] return abiEncoder.strictDecodeReturnValue<BigNumber[]>(rawCallResult);
>(rawCallResult);
}, },
getABIEncodedTransactionData(): string { getABIEncodedTransactionData(): string {
return self._strictEncodeArguments(functionSignature, [orders, return self._strictEncodeArguments(functionSignature, [orders, orderSignatures]);
orderSignatures
]);
}, },
}
}; };
}
/** /**
* Queries the fillable taker asset amounts of native orders. * Queries the fillable taker asset amounts of native orders.
* @param orders Native orders to query. * @param orders Native orders to query.
@ -787,35 +795,46 @@ public static async deployFrom0xArtifactAsync(
* @returns orderFillableTakerAssetAmounts How much taker asset can be filled by each order in &#x60;orders&#x60;. * @returns orderFillableTakerAssetAmounts How much taker asset can be filled by each order in &#x60;orders&#x60;.
*/ */
public getOrderFillableTakerAssetAmounts( public getOrderFillableTakerAssetAmounts(
orders: Array<{makerAddress: string;takerAddress: string;feeRecipientAddress: string;senderAddress: string;makerAssetAmount: BigNumber;takerAssetAmount: BigNumber;makerFee: BigNumber;takerFee: BigNumber;expirationTimeSeconds: BigNumber;salt: BigNumber;makerAssetData: string;takerAssetData: string;makerFeeAssetData: string;takerFeeAssetData: string}>, orders: Array<{
makerAddress: string;
takerAddress: string;
feeRecipientAddress: string;
senderAddress: string;
makerAssetAmount: BigNumber;
takerAssetAmount: BigNumber;
makerFee: BigNumber;
takerFee: BigNumber;
expirationTimeSeconds: BigNumber;
salt: BigNumber;
makerAssetData: string;
takerAssetData: string;
makerFeeAssetData: string;
takerFeeAssetData: string;
}>,
orderSignatures: string[], orderSignatures: string[],
): ContractFunctionObj<BigNumber[] ): ContractFunctionObj<BigNumber[]> {
> { const self = (this as any) as IERC20BridgeSamplerContract;
const self = this as any as IERC20BridgeSamplerContract;
assert.isArray('orders', orders); assert.isArray('orders', orders);
assert.isArray('orderSignatures', orderSignatures); assert.isArray('orderSignatures', orderSignatures);
const functionSignature = 'getOrderFillableTakerAssetAmounts((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes)[],bytes[])'; const functionSignature =
'getOrderFillableTakerAssetAmounts((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes)[],bytes[])';
return { return {
async callAsync( async callAsync(callData: Partial<CallData> = {}, defaultBlock?: BlockParam): Promise<BigNumber[]> {
callData: Partial<CallData> = {},
defaultBlock?: BlockParam,
): Promise<BigNumber[]
> {
BaseContract._assertCallParams(callData, defaultBlock); BaseContract._assertCallParams(callData, defaultBlock);
const rawCallResult = await self._performCallAsync({ ...callData, data: this.getABIEncodedTransactionData() }, defaultBlock); const rawCallResult = await self._performCallAsync(
{ ...callData, data: this.getABIEncodedTransactionData() },
defaultBlock,
);
const abiEncoder = self._lookupAbiEncoder(functionSignature); const abiEncoder = self._lookupAbiEncoder(functionSignature);
BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder); BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder);
return abiEncoder.strictDecodeReturnValue<BigNumber[] return abiEncoder.strictDecodeReturnValue<BigNumber[]>(rawCallResult);
>(rawCallResult);
}, },
getABIEncodedTransactionData(): string { getABIEncodedTransactionData(): string {
return self._strictEncodeArguments(functionSignature, [orders, return self._strictEncodeArguments(functionSignature, [orders, orderSignatures]);
orderSignatures
]);
}, },
}
}; };
}
/** /**
* Sample buy quotes from Eth2Dai/Oasis. * Sample buy quotes from Eth2Dai/Oasis.
* @param takerToken Address of the taker token (what to sell). * @param takerToken Address of the taker token (what to sell).
@ -826,35 +845,33 @@ public static async deployFrom0xArtifactAsync(
takerToken: string, takerToken: string,
makerToken: string, makerToken: string,
makerTokenAmounts: BigNumber[], makerTokenAmounts: BigNumber[],
): ContractFunctionObj<BigNumber[] ): ContractFunctionObj<BigNumber[]> {
> { const self = (this as any) as IERC20BridgeSamplerContract;
const self = this as any as IERC20BridgeSamplerContract;
assert.isString('takerToken', takerToken); assert.isString('takerToken', takerToken);
assert.isString('makerToken', makerToken); assert.isString('makerToken', makerToken);
assert.isArray('makerTokenAmounts', makerTokenAmounts); assert.isArray('makerTokenAmounts', makerTokenAmounts);
const functionSignature = 'sampleBuysFromEth2Dai(address,address,uint256[])'; const functionSignature = 'sampleBuysFromEth2Dai(address,address,uint256[])';
return { return {
async callAsync( async callAsync(callData: Partial<CallData> = {}, defaultBlock?: BlockParam): Promise<BigNumber[]> {
callData: Partial<CallData> = {},
defaultBlock?: BlockParam,
): Promise<BigNumber[]
> {
BaseContract._assertCallParams(callData, defaultBlock); BaseContract._assertCallParams(callData, defaultBlock);
const rawCallResult = await self._performCallAsync({ ...callData, data: this.getABIEncodedTransactionData() }, defaultBlock); const rawCallResult = await self._performCallAsync(
{ ...callData, data: this.getABIEncodedTransactionData() },
defaultBlock,
);
const abiEncoder = self._lookupAbiEncoder(functionSignature); const abiEncoder = self._lookupAbiEncoder(functionSignature);
BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder); BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder);
return abiEncoder.strictDecodeReturnValue<BigNumber[] return abiEncoder.strictDecodeReturnValue<BigNumber[]>(rawCallResult);
>(rawCallResult);
}, },
getABIEncodedTransactionData(): string { getABIEncodedTransactionData(): string {
return self._strictEncodeArguments(functionSignature, [takerToken.toLowerCase(), return self._strictEncodeArguments(functionSignature, [
takerToken.toLowerCase(),
makerToken.toLowerCase(), makerToken.toLowerCase(),
makerTokenAmounts makerTokenAmounts,
]); ]);
}, },
}
}; };
}
/** /**
* Sample buy quotes from an arbitrary on-chain liquidity provider. * Sample buy quotes from an arbitrary on-chain liquidity provider.
* @param registryAddress Address of the liquidity provider registry contract. * @param registryAddress Address of the liquidity provider registry contract.
@ -868,9 +885,8 @@ public static async deployFrom0xArtifactAsync(
takerToken: string, takerToken: string,
makerToken: string, makerToken: string,
makerTokenAmounts: BigNumber[], makerTokenAmounts: BigNumber[],
): ContractFunctionObj<BigNumber[] ): ContractFunctionObj<BigNumber[]> {
> { const self = (this as any) as IERC20BridgeSamplerContract;
const self = this as any as IERC20BridgeSamplerContract;
assert.isString('registryAddress', registryAddress); assert.isString('registryAddress', registryAddress);
assert.isString('takerToken', takerToken); assert.isString('takerToken', takerToken);
assert.isString('makerToken', makerToken); assert.isString('makerToken', makerToken);
@ -878,27 +894,26 @@ public static async deployFrom0xArtifactAsync(
const functionSignature = 'sampleBuysFromLiquidityProviderRegistry(address,address,address,uint256[])'; const functionSignature = 'sampleBuysFromLiquidityProviderRegistry(address,address,address,uint256[])';
return { return {
async callAsync( async callAsync(callData: Partial<CallData> = {}, defaultBlock?: BlockParam): Promise<BigNumber[]> {
callData: Partial<CallData> = {},
defaultBlock?: BlockParam,
): Promise<BigNumber[]
> {
BaseContract._assertCallParams(callData, defaultBlock); BaseContract._assertCallParams(callData, defaultBlock);
const rawCallResult = await self._performCallAsync({ ...callData, data: this.getABIEncodedTransactionData() }, defaultBlock); const rawCallResult = await self._performCallAsync(
{ ...callData, data: this.getABIEncodedTransactionData() },
defaultBlock,
);
const abiEncoder = self._lookupAbiEncoder(functionSignature); const abiEncoder = self._lookupAbiEncoder(functionSignature);
BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder); BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder);
return abiEncoder.strictDecodeReturnValue<BigNumber[] return abiEncoder.strictDecodeReturnValue<BigNumber[]>(rawCallResult);
>(rawCallResult);
}, },
getABIEncodedTransactionData(): string { getABIEncodedTransactionData(): string {
return self._strictEncodeArguments(functionSignature, [registryAddress.toLowerCase(), return self._strictEncodeArguments(functionSignature, [
registryAddress.toLowerCase(),
takerToken.toLowerCase(), takerToken.toLowerCase(),
makerToken.toLowerCase(), makerToken.toLowerCase(),
makerTokenAmounts makerTokenAmounts,
]); ]);
}, },
}
}; };
}
/** /**
* Sample buy quotes from Uniswap. * Sample buy quotes from Uniswap.
* @param takerToken Address of the taker token (what to sell). * @param takerToken Address of the taker token (what to sell).
@ -910,35 +925,33 @@ public static async deployFrom0xArtifactAsync(
takerToken: string, takerToken: string,
makerToken: string, makerToken: string,
makerTokenAmounts: BigNumber[], makerTokenAmounts: BigNumber[],
): ContractFunctionObj<BigNumber[] ): ContractFunctionObj<BigNumber[]> {
> { const self = (this as any) as IERC20BridgeSamplerContract;
const self = this as any as IERC20BridgeSamplerContract;
assert.isString('takerToken', takerToken); assert.isString('takerToken', takerToken);
assert.isString('makerToken', makerToken); assert.isString('makerToken', makerToken);
assert.isArray('makerTokenAmounts', makerTokenAmounts); assert.isArray('makerTokenAmounts', makerTokenAmounts);
const functionSignature = 'sampleBuysFromUniswap(address,address,uint256[])'; const functionSignature = 'sampleBuysFromUniswap(address,address,uint256[])';
return { return {
async callAsync( async callAsync(callData: Partial<CallData> = {}, defaultBlock?: BlockParam): Promise<BigNumber[]> {
callData: Partial<CallData> = {},
defaultBlock?: BlockParam,
): Promise<BigNumber[]
> {
BaseContract._assertCallParams(callData, defaultBlock); BaseContract._assertCallParams(callData, defaultBlock);
const rawCallResult = await self._performCallAsync({ ...callData, data: this.getABIEncodedTransactionData() }, defaultBlock); const rawCallResult = await self._performCallAsync(
{ ...callData, data: this.getABIEncodedTransactionData() },
defaultBlock,
);
const abiEncoder = self._lookupAbiEncoder(functionSignature); const abiEncoder = self._lookupAbiEncoder(functionSignature);
BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder); BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder);
return abiEncoder.strictDecodeReturnValue<BigNumber[] return abiEncoder.strictDecodeReturnValue<BigNumber[]>(rawCallResult);
>(rawCallResult);
}, },
getABIEncodedTransactionData(): string { getABIEncodedTransactionData(): string {
return self._strictEncodeArguments(functionSignature, [takerToken.toLowerCase(), return self._strictEncodeArguments(functionSignature, [
takerToken.toLowerCase(),
makerToken.toLowerCase(), makerToken.toLowerCase(),
makerTokenAmounts makerTokenAmounts,
]); ]);
}, },
}
}; };
}
/** /**
* Sample sell quotes from Curve. * Sample sell quotes from Curve.
* @param curveAddress Address of the Curve contract. * @param curveAddress Address of the Curve contract.
@ -952,9 +965,8 @@ public static async deployFrom0xArtifactAsync(
fromTokenIdx: BigNumber, fromTokenIdx: BigNumber,
toTokenIdx: BigNumber, toTokenIdx: BigNumber,
takerTokenAmounts: BigNumber[], takerTokenAmounts: BigNumber[],
): ContractFunctionObj<BigNumber[] ): ContractFunctionObj<BigNumber[]> {
> { const self = (this as any) as IERC20BridgeSamplerContract;
const self = this as any as IERC20BridgeSamplerContract;
assert.isString('curveAddress', curveAddress); assert.isString('curveAddress', curveAddress);
assert.isBigNumber('fromTokenIdx', fromTokenIdx); assert.isBigNumber('fromTokenIdx', fromTokenIdx);
assert.isBigNumber('toTokenIdx', toTokenIdx); assert.isBigNumber('toTokenIdx', toTokenIdx);
@ -962,27 +974,26 @@ public static async deployFrom0xArtifactAsync(
const functionSignature = 'sampleSellsFromCurve(address,int128,int128,uint256[])'; const functionSignature = 'sampleSellsFromCurve(address,int128,int128,uint256[])';
return { return {
async callAsync( async callAsync(callData: Partial<CallData> = {}, defaultBlock?: BlockParam): Promise<BigNumber[]> {
callData: Partial<CallData> = {},
defaultBlock?: BlockParam,
): Promise<BigNumber[]
> {
BaseContract._assertCallParams(callData, defaultBlock); BaseContract._assertCallParams(callData, defaultBlock);
const rawCallResult = await self._performCallAsync({ ...callData, data: this.getABIEncodedTransactionData() }, defaultBlock); const rawCallResult = await self._performCallAsync(
{ ...callData, data: this.getABIEncodedTransactionData() },
defaultBlock,
);
const abiEncoder = self._lookupAbiEncoder(functionSignature); const abiEncoder = self._lookupAbiEncoder(functionSignature);
BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder); BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder);
return abiEncoder.strictDecodeReturnValue<BigNumber[] return abiEncoder.strictDecodeReturnValue<BigNumber[]>(rawCallResult);
>(rawCallResult);
}, },
getABIEncodedTransactionData(): string { getABIEncodedTransactionData(): string {
return self._strictEncodeArguments(functionSignature, [curveAddress.toLowerCase(), return self._strictEncodeArguments(functionSignature, [
curveAddress.toLowerCase(),
fromTokenIdx, fromTokenIdx,
toTokenIdx, toTokenIdx,
takerTokenAmounts takerTokenAmounts,
]); ]);
}, },
}
}; };
}
/** /**
* Sample sell quotes from Eth2Dai/Oasis. * Sample sell quotes from Eth2Dai/Oasis.
* @param takerToken Address of the taker token (what to sell). * @param takerToken Address of the taker token (what to sell).
@ -994,35 +1005,33 @@ public static async deployFrom0xArtifactAsync(
takerToken: string, takerToken: string,
makerToken: string, makerToken: string,
takerTokenAmounts: BigNumber[], takerTokenAmounts: BigNumber[],
): ContractFunctionObj<BigNumber[] ): ContractFunctionObj<BigNumber[]> {
> { const self = (this as any) as IERC20BridgeSamplerContract;
const self = this as any as IERC20BridgeSamplerContract;
assert.isString('takerToken', takerToken); assert.isString('takerToken', takerToken);
assert.isString('makerToken', makerToken); assert.isString('makerToken', makerToken);
assert.isArray('takerTokenAmounts', takerTokenAmounts); assert.isArray('takerTokenAmounts', takerTokenAmounts);
const functionSignature = 'sampleSellsFromEth2Dai(address,address,uint256[])'; const functionSignature = 'sampleSellsFromEth2Dai(address,address,uint256[])';
return { return {
async callAsync( async callAsync(callData: Partial<CallData> = {}, defaultBlock?: BlockParam): Promise<BigNumber[]> {
callData: Partial<CallData> = {},
defaultBlock?: BlockParam,
): Promise<BigNumber[]
> {
BaseContract._assertCallParams(callData, defaultBlock); BaseContract._assertCallParams(callData, defaultBlock);
const rawCallResult = await self._performCallAsync({ ...callData, data: this.getABIEncodedTransactionData() }, defaultBlock); const rawCallResult = await self._performCallAsync(
{ ...callData, data: this.getABIEncodedTransactionData() },
defaultBlock,
);
const abiEncoder = self._lookupAbiEncoder(functionSignature); const abiEncoder = self._lookupAbiEncoder(functionSignature);
BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder); BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder);
return abiEncoder.strictDecodeReturnValue<BigNumber[] return abiEncoder.strictDecodeReturnValue<BigNumber[]>(rawCallResult);
>(rawCallResult);
}, },
getABIEncodedTransactionData(): string { getABIEncodedTransactionData(): string {
return self._strictEncodeArguments(functionSignature, [takerToken.toLowerCase(), return self._strictEncodeArguments(functionSignature, [
takerToken.toLowerCase(),
makerToken.toLowerCase(), makerToken.toLowerCase(),
takerTokenAmounts takerTokenAmounts,
]); ]);
}, },
}
}; };
}
/** /**
* Sample sell quotes from Kyber. * Sample sell quotes from Kyber.
* @param takerToken Address of the taker token (what to sell). * @param takerToken Address of the taker token (what to sell).
@ -1034,35 +1043,33 @@ public static async deployFrom0xArtifactAsync(
takerToken: string, takerToken: string,
makerToken: string, makerToken: string,
takerTokenAmounts: BigNumber[], takerTokenAmounts: BigNumber[],
): ContractFunctionObj<BigNumber[] ): ContractFunctionObj<BigNumber[]> {
> { const self = (this as any) as IERC20BridgeSamplerContract;
const self = this as any as IERC20BridgeSamplerContract;
assert.isString('takerToken', takerToken); assert.isString('takerToken', takerToken);
assert.isString('makerToken', makerToken); assert.isString('makerToken', makerToken);
assert.isArray('takerTokenAmounts', takerTokenAmounts); assert.isArray('takerTokenAmounts', takerTokenAmounts);
const functionSignature = 'sampleSellsFromKyberNetwork(address,address,uint256[])'; const functionSignature = 'sampleSellsFromKyberNetwork(address,address,uint256[])';
return { return {
async callAsync( async callAsync(callData: Partial<CallData> = {}, defaultBlock?: BlockParam): Promise<BigNumber[]> {
callData: Partial<CallData> = {},
defaultBlock?: BlockParam,
): Promise<BigNumber[]
> {
BaseContract._assertCallParams(callData, defaultBlock); BaseContract._assertCallParams(callData, defaultBlock);
const rawCallResult = await self._performCallAsync({ ...callData, data: this.getABIEncodedTransactionData() }, defaultBlock); const rawCallResult = await self._performCallAsync(
{ ...callData, data: this.getABIEncodedTransactionData() },
defaultBlock,
);
const abiEncoder = self._lookupAbiEncoder(functionSignature); const abiEncoder = self._lookupAbiEncoder(functionSignature);
BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder); BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder);
return abiEncoder.strictDecodeReturnValue<BigNumber[] return abiEncoder.strictDecodeReturnValue<BigNumber[]>(rawCallResult);
>(rawCallResult);
}, },
getABIEncodedTransactionData(): string { getABIEncodedTransactionData(): string {
return self._strictEncodeArguments(functionSignature, [takerToken.toLowerCase(), return self._strictEncodeArguments(functionSignature, [
takerToken.toLowerCase(),
makerToken.toLowerCase(), makerToken.toLowerCase(),
takerTokenAmounts takerTokenAmounts,
]); ]);
}, },
}
}; };
}
/** /**
* Sample sell quotes from an arbitrary on-chain liquidity provider. * Sample sell quotes from an arbitrary on-chain liquidity provider.
* @param registryAddress Address of the liquidity provider registry contract. * @param registryAddress Address of the liquidity provider registry contract.
@ -1076,9 +1083,8 @@ public static async deployFrom0xArtifactAsync(
takerToken: string, takerToken: string,
makerToken: string, makerToken: string,
takerTokenAmounts: BigNumber[], takerTokenAmounts: BigNumber[],
): ContractFunctionObj<BigNumber[] ): ContractFunctionObj<BigNumber[]> {
> { const self = (this as any) as IERC20BridgeSamplerContract;
const self = this as any as IERC20BridgeSamplerContract;
assert.isString('registryAddress', registryAddress); assert.isString('registryAddress', registryAddress);
assert.isString('takerToken', takerToken); assert.isString('takerToken', takerToken);
assert.isString('makerToken', makerToken); assert.isString('makerToken', makerToken);
@ -1086,27 +1092,26 @@ public static async deployFrom0xArtifactAsync(
const functionSignature = 'sampleSellsFromLiquidityProviderRegistry(address,address,address,uint256[])'; const functionSignature = 'sampleSellsFromLiquidityProviderRegistry(address,address,address,uint256[])';
return { return {
async callAsync( async callAsync(callData: Partial<CallData> = {}, defaultBlock?: BlockParam): Promise<BigNumber[]> {
callData: Partial<CallData> = {},
defaultBlock?: BlockParam,
): Promise<BigNumber[]
> {
BaseContract._assertCallParams(callData, defaultBlock); BaseContract._assertCallParams(callData, defaultBlock);
const rawCallResult = await self._performCallAsync({ ...callData, data: this.getABIEncodedTransactionData() }, defaultBlock); const rawCallResult = await self._performCallAsync(
{ ...callData, data: this.getABIEncodedTransactionData() },
defaultBlock,
);
const abiEncoder = self._lookupAbiEncoder(functionSignature); const abiEncoder = self._lookupAbiEncoder(functionSignature);
BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder); BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder);
return abiEncoder.strictDecodeReturnValue<BigNumber[] return abiEncoder.strictDecodeReturnValue<BigNumber[]>(rawCallResult);
>(rawCallResult);
}, },
getABIEncodedTransactionData(): string { getABIEncodedTransactionData(): string {
return self._strictEncodeArguments(functionSignature, [registryAddress.toLowerCase(), return self._strictEncodeArguments(functionSignature, [
registryAddress.toLowerCase(),
takerToken.toLowerCase(), takerToken.toLowerCase(),
makerToken.toLowerCase(), makerToken.toLowerCase(),
takerTokenAmounts takerTokenAmounts,
]); ]);
}, },
}
}; };
}
/** /**
* Sample sell quotes from Uniswap. * Sample sell quotes from Uniswap.
* @param takerToken Address of the taker token (what to sell). * @param takerToken Address of the taker token (what to sell).
@ -1118,37 +1123,33 @@ public static async deployFrom0xArtifactAsync(
takerToken: string, takerToken: string,
makerToken: string, makerToken: string,
takerTokenAmounts: BigNumber[], takerTokenAmounts: BigNumber[],
): ContractFunctionObj<BigNumber[] ): ContractFunctionObj<BigNumber[]> {
> { const self = (this as any) as IERC20BridgeSamplerContract;
const self = this as any as IERC20BridgeSamplerContract;
assert.isString('takerToken', takerToken); assert.isString('takerToken', takerToken);
assert.isString('makerToken', makerToken); assert.isString('makerToken', makerToken);
assert.isArray('takerTokenAmounts', takerTokenAmounts); assert.isArray('takerTokenAmounts', takerTokenAmounts);
const functionSignature = 'sampleSellsFromUniswap(address,address,uint256[])'; const functionSignature = 'sampleSellsFromUniswap(address,address,uint256[])';
return { return {
async callAsync( async callAsync(callData: Partial<CallData> = {}, defaultBlock?: BlockParam): Promise<BigNumber[]> {
callData: Partial<CallData> = {},
defaultBlock?: BlockParam,
): Promise<BigNumber[]
> {
BaseContract._assertCallParams(callData, defaultBlock); BaseContract._assertCallParams(callData, defaultBlock);
const rawCallResult = await self._performCallAsync({ ...callData, data: this.getABIEncodedTransactionData() }, defaultBlock); const rawCallResult = await self._performCallAsync(
{ ...callData, data: this.getABIEncodedTransactionData() },
defaultBlock,
);
const abiEncoder = self._lookupAbiEncoder(functionSignature); const abiEncoder = self._lookupAbiEncoder(functionSignature);
BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder); BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder);
return abiEncoder.strictDecodeReturnValue<BigNumber[] return abiEncoder.strictDecodeReturnValue<BigNumber[]>(rawCallResult);
>(rawCallResult);
}, },
getABIEncodedTransactionData(): string { getABIEncodedTransactionData(): string {
return self._strictEncodeArguments(functionSignature, [takerToken.toLowerCase(), return self._strictEncodeArguments(functionSignature, [
takerToken.toLowerCase(),
makerToken.toLowerCase(), makerToken.toLowerCase(),
takerTokenAmounts takerTokenAmounts,
]); ]);
}, },
}
}; };
}
constructor( constructor(
address: string, address: string,
@ -1157,7 +1158,15 @@ public static async deployFrom0xArtifactAsync(
logDecodeDependencies?: { [contractName: string]: ContractAbi }, logDecodeDependencies?: { [contractName: string]: ContractAbi },
deployedBytecode: string | undefined = IERC20BridgeSamplerContract.deployedBytecode, deployedBytecode: string | undefined = IERC20BridgeSamplerContract.deployedBytecode,
) { ) {
super('IERC20BridgeSampler', IERC20BridgeSamplerContract.ABI(), address, supportedProvider, txDefaults, logDecodeDependencies, deployedBytecode); super(
'IERC20BridgeSampler',
IERC20BridgeSamplerContract.ABI(),
address,
supportedProvider,
txDefaults,
logDecodeDependencies,
deployedBytecode,
);
classUtils.bindAll(this, ['_abiEncoderByFunctionSignature', 'address', '_web3Wrapper']); classUtils.bindAll(this, ['_abiEncoderByFunctionSignature', 'address', '_web3Wrapper']);
IERC20BridgeSamplerContract.ABI().forEach((item, index) => { IERC20BridgeSamplerContract.ABI().forEach((item, index) => {
if (item.type === 'function') { if (item.type === 'function') {

View File

@ -33,8 +33,6 @@ import { assert } from '@0x/assert';
import * as ethers from 'ethers'; import * as ethers from 'ethers';
// tslint:enable:no-unused-variable // tslint:enable:no-unused-variable
/* istanbul ignore next */ /* istanbul ignore next */
// tslint:disable:array-type // tslint:disable:array-type
// tslint:disable:no-parameter-reassignment // tslint:disable:no-parameter-reassignment
@ -50,7 +48,7 @@ public static async deployFrom0xArtifactAsync(
artifact: ContractArtifact | SimpleContractArtifact, artifact: ContractArtifact | SimpleContractArtifact,
supportedProvider: SupportedProvider, supportedProvider: SupportedProvider,
txDefaults: Partial<TxData>, txDefaults: Partial<TxData>,
logDecodeDependencies: { [contractName: string]: (ContractArtifact | SimpleContractArtifact) }, logDecodeDependencies: { [contractName: string]: ContractArtifact | SimpleContractArtifact },
): Promise<ILiquidityProviderContract> { ): Promise<ILiquidityProviderContract> {
assert.doesConformToSchema('txDefaults', txDefaults, schemas.txDataSchema, [ assert.doesConformToSchema('txDefaults', txDefaults, schemas.txDataSchema, [
schemas.addressSchema, schemas.addressSchema,
@ -69,7 +67,13 @@ public static async deployFrom0xArtifactAsync(
logDecodeDependenciesAbiOnly[key] = logDecodeDependencies[key].compilerOutput.abi; logDecodeDependenciesAbiOnly[key] = logDecodeDependencies[key].compilerOutput.abi;
} }
} }
return ILiquidityProviderContract.deployAsync(bytecode, abi, provider, txDefaults, logDecodeDependenciesAbiOnly, ); return ILiquidityProviderContract.deployAsync(
bytecode,
abi,
provider,
txDefaults,
logDecodeDependenciesAbiOnly,
);
} }
public static async deployWithLibrariesFrom0xArtifactAsync( public static async deployWithLibrariesFrom0xArtifactAsync(
@ -77,7 +81,7 @@ public static async deployFrom0xArtifactAsync(
libraryArtifacts: { [libraryName: string]: ContractArtifact }, libraryArtifacts: { [libraryName: string]: ContractArtifact },
supportedProvider: SupportedProvider, supportedProvider: SupportedProvider,
txDefaults: Partial<TxData>, txDefaults: Partial<TxData>,
logDecodeDependencies: { [contractName: string]: (ContractArtifact | SimpleContractArtifact) }, logDecodeDependencies: { [contractName: string]: ContractArtifact | SimpleContractArtifact },
): Promise<ILiquidityProviderContract> { ): Promise<ILiquidityProviderContract> {
assert.doesConformToSchema('txDefaults', txDefaults, schemas.txDataSchema, [ assert.doesConformToSchema('txDefaults', txDefaults, schemas.txDataSchema, [
schemas.addressSchema, schemas.addressSchema,
@ -99,13 +103,16 @@ public static async deployFrom0xArtifactAsync(
artifact, artifact,
libraryArtifacts, libraryArtifacts,
new Web3Wrapper(provider), new Web3Wrapper(provider),
txDefaults txDefaults,
); );
const bytecode = linkLibrariesInBytecode( const bytecode = linkLibrariesInBytecode(artifact, libraryAddresses);
artifact, return ILiquidityProviderContract.deployAsync(
libraryAddresses, bytecode,
abi,
provider,
txDefaults,
logDecodeDependenciesAbiOnly,
); );
return ILiquidityProviderContract.deployAsync(bytecode, abi, provider, txDefaults, logDecodeDependenciesAbiOnly, );
} }
public static async deployAsync( public static async deployAsync(
@ -123,11 +130,7 @@ public static async deployFrom0xArtifactAsync(
]); ]);
const provider = providerUtils.standardizeOrThrow(supportedProvider); const provider = providerUtils.standardizeOrThrow(supportedProvider);
const constructorAbi = BaseContract._lookupConstructorAbi(abi); const constructorAbi = BaseContract._lookupConstructorAbi(abi);
[] = BaseContract._formatABIDataItemList( [] = BaseContract._formatABIDataItemList(constructorAbi.inputs, [], BaseContract._bigNumberToString);
constructorAbi.inputs,
[],
BaseContract._bigNumberToString,
);
const iface = new ethers.utils.Interface(abi); const iface = new ethers.utils.Interface(abi);
const deployInfo = iface.deployFunction; const deployInfo = iface.deployFunction;
const txData = deployInfo.encode(bytecode, []); const txData = deployInfo.encode(bytecode, []);
@ -143,7 +146,12 @@ public static async deployFrom0xArtifactAsync(
logUtils.log(`transactionHash: ${txHash}`); logUtils.log(`transactionHash: ${txHash}`);
const txReceipt = await web3Wrapper.awaitTransactionSuccessAsync(txHash); const txReceipt = await web3Wrapper.awaitTransactionSuccessAsync(txHash);
logUtils.log(`ILiquidityProvider successfully deployed at ${txReceipt.contractAddress}`); logUtils.log(`ILiquidityProvider successfully deployed at ${txReceipt.contractAddress}`);
const contractInstance = new ILiquidityProviderContract(txReceipt.contractAddress as string, provider, txDefaults, logDecodeDependencies); const contractInstance = new ILiquidityProviderContract(
txReceipt.contractAddress as string,
provider,
txDefaults,
logDecodeDependencies,
);
contractInstance.constructorArgs = []; contractInstance.constructorArgs = [];
return contractInstance; return contractInstance;
} }
@ -272,10 +280,7 @@ public static async deployFrom0xArtifactAsync(
libraryAddresses, libraryAddresses,
); );
// Deploy this library. // Deploy this library.
const linkedLibraryBytecode = linkLibrariesInBytecode( const linkedLibraryBytecode = linkLibrariesInBytecode(libraryArtifact, libraryAddresses);
libraryArtifact,
libraryAddresses,
);
const txDataWithDefaults = await BaseContract._applyDefaultsToContractTxDataAsync( const txDataWithDefaults = await BaseContract._applyDefaultsToContractTxDataAsync(
{ {
data: linkedLibraryBytecode, data: linkedLibraryBytecode,
@ -339,9 +344,8 @@ public static async deployFrom0xArtifactAsync(
to: string, to: string,
amount: BigNumber, amount: BigNumber,
bridgeData: string, bridgeData: string,
): ContractTxFunctionObj<string ): ContractTxFunctionObj<string> {
> { const self = (this as any) as ILiquidityProviderContract;
const self = this as any as ILiquidityProviderContract;
assert.isString('tokenAddress', tokenAddress); assert.isString('tokenAddress', tokenAddress);
assert.isString('from', from); assert.isString('from', from);
assert.isString('to', to); assert.isString('to', to);
@ -369,36 +373,34 @@ public static async deployFrom0xArtifactAsync(
): PromiseWithTransactionHash<TransactionReceiptWithDecodedLogs> { ): PromiseWithTransactionHash<TransactionReceiptWithDecodedLogs> {
return self._promiseWithTransactionHash(this.sendTransactionAsync(txData, opts), opts); return self._promiseWithTransactionHash(this.sendTransactionAsync(txData, opts), opts);
}, },
async estimateGasAsync( async estimateGasAsync(txData?: Partial<TxData> | undefined): Promise<number> {
txData?: Partial<TxData> | undefined, const txDataWithDefaults = await self._applyDefaultsToTxDataAsync({
): Promise<number> { ...txData,
const txDataWithDefaults = await self._applyDefaultsToTxDataAsync( data: this.getABIEncodedTransactionData(),
{ ...txData, data: this.getABIEncodedTransactionData() } });
);
return self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return self._web3Wrapper.estimateGasAsync(txDataWithDefaults);
}, },
async callAsync( async callAsync(callData: Partial<CallData> = {}, defaultBlock?: BlockParam): Promise<string> {
callData: Partial<CallData> = {},
defaultBlock?: BlockParam,
): Promise<string
> {
BaseContract._assertCallParams(callData, defaultBlock); BaseContract._assertCallParams(callData, defaultBlock);
const rawCallResult = await self._performCallAsync({ ...callData, data: this.getABIEncodedTransactionData() }, defaultBlock); const rawCallResult = await self._performCallAsync(
{ ...callData, data: this.getABIEncodedTransactionData() },
defaultBlock,
);
const abiEncoder = self._lookupAbiEncoder(functionSignature); const abiEncoder = self._lookupAbiEncoder(functionSignature);
BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder); BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder);
return abiEncoder.strictDecodeReturnValue<string return abiEncoder.strictDecodeReturnValue<string>(rawCallResult);
>(rawCallResult);
}, },
getABIEncodedTransactionData(): string { getABIEncodedTransactionData(): string {
return self._strictEncodeArguments(functionSignature, [tokenAddress.toLowerCase(), return self._strictEncodeArguments(functionSignature, [
tokenAddress.toLowerCase(),
from.toLowerCase(), from.toLowerCase(),
to.toLowerCase(), to.toLowerCase(),
amount, amount,
bridgeData bridgeData,
]); ]);
}, },
}
}; };
}
/** /**
* Quotes the amount of `takerToken` that would need to be sold in * Quotes the amount of `takerToken` that would need to be sold in
* order to obtain `buyAmount` of `makerToken`. * order to obtain `buyAmount` of `makerToken`.
@ -407,39 +409,33 @@ public static async deployFrom0xArtifactAsync(
* @param buyAmount Amount of `makerToken` to buy. * @param buyAmount Amount of `makerToken` to buy.
* @returns takerTokenAmount Amount of &#x60;takerToken&#x60; that would need to be sold. * @returns takerTokenAmount Amount of &#x60;takerToken&#x60; that would need to be sold.
*/ */
public getBuyQuote( public getBuyQuote(takerToken: string, makerToken: string, buyAmount: BigNumber): ContractFunctionObj<BigNumber> {
takerToken: string, const self = (this as any) as ILiquidityProviderContract;
makerToken: string,
buyAmount: BigNumber,
): ContractFunctionObj<BigNumber
> {
const self = this as any as ILiquidityProviderContract;
assert.isString('takerToken', takerToken); assert.isString('takerToken', takerToken);
assert.isString('makerToken', makerToken); assert.isString('makerToken', makerToken);
assert.isBigNumber('buyAmount', buyAmount); assert.isBigNumber('buyAmount', buyAmount);
const functionSignature = 'getBuyQuote(address,address,uint256)'; const functionSignature = 'getBuyQuote(address,address,uint256)';
return { return {
async callAsync( async callAsync(callData: Partial<CallData> = {}, defaultBlock?: BlockParam): Promise<BigNumber> {
callData: Partial<CallData> = {},
defaultBlock?: BlockParam,
): Promise<BigNumber
> {
BaseContract._assertCallParams(callData, defaultBlock); BaseContract._assertCallParams(callData, defaultBlock);
const rawCallResult = await self._performCallAsync({ ...callData, data: this.getABIEncodedTransactionData() }, defaultBlock); const rawCallResult = await self._performCallAsync(
{ ...callData, data: this.getABIEncodedTransactionData() },
defaultBlock,
);
const abiEncoder = self._lookupAbiEncoder(functionSignature); const abiEncoder = self._lookupAbiEncoder(functionSignature);
BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder); BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder);
return abiEncoder.strictDecodeReturnValue<BigNumber return abiEncoder.strictDecodeReturnValue<BigNumber>(rawCallResult);
>(rawCallResult);
}, },
getABIEncodedTransactionData(): string { getABIEncodedTransactionData(): string {
return self._strictEncodeArguments(functionSignature, [takerToken.toLowerCase(), return self._strictEncodeArguments(functionSignature, [
takerToken.toLowerCase(),
makerToken.toLowerCase(), makerToken.toLowerCase(),
buyAmount buyAmount,
]); ]);
}, },
}
}; };
}
/** /**
* Quotes the amount of `makerToken` that would be obtained by * Quotes the amount of `makerToken` that would be obtained by
* selling `sellAmount` of `takerToken`. * selling `sellAmount` of `takerToken`.
@ -448,41 +444,33 @@ public static async deployFrom0xArtifactAsync(
* @param sellAmount Amount of `takerToken` to sell. * @param sellAmount Amount of `takerToken` to sell.
* @returns makerTokenAmount Amount of &#x60;makerToken&#x60; that would be obtained. * @returns makerTokenAmount Amount of &#x60;makerToken&#x60; that would be obtained.
*/ */
public getSellQuote( public getSellQuote(takerToken: string, makerToken: string, sellAmount: BigNumber): ContractFunctionObj<BigNumber> {
takerToken: string, const self = (this as any) as ILiquidityProviderContract;
makerToken: string,
sellAmount: BigNumber,
): ContractFunctionObj<BigNumber
> {
const self = this as any as ILiquidityProviderContract;
assert.isString('takerToken', takerToken); assert.isString('takerToken', takerToken);
assert.isString('makerToken', makerToken); assert.isString('makerToken', makerToken);
assert.isBigNumber('sellAmount', sellAmount); assert.isBigNumber('sellAmount', sellAmount);
const functionSignature = 'getSellQuote(address,address,uint256)'; const functionSignature = 'getSellQuote(address,address,uint256)';
return { return {
async callAsync( async callAsync(callData: Partial<CallData> = {}, defaultBlock?: BlockParam): Promise<BigNumber> {
callData: Partial<CallData> = {},
defaultBlock?: BlockParam,
): Promise<BigNumber
> {
BaseContract._assertCallParams(callData, defaultBlock); BaseContract._assertCallParams(callData, defaultBlock);
const rawCallResult = await self._performCallAsync({ ...callData, data: this.getABIEncodedTransactionData() }, defaultBlock); const rawCallResult = await self._performCallAsync(
{ ...callData, data: this.getABIEncodedTransactionData() },
defaultBlock,
);
const abiEncoder = self._lookupAbiEncoder(functionSignature); const abiEncoder = self._lookupAbiEncoder(functionSignature);
BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder); BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder);
return abiEncoder.strictDecodeReturnValue<BigNumber return abiEncoder.strictDecodeReturnValue<BigNumber>(rawCallResult);
>(rawCallResult);
}, },
getABIEncodedTransactionData(): string { getABIEncodedTransactionData(): string {
return self._strictEncodeArguments(functionSignature, [takerToken.toLowerCase(), return self._strictEncodeArguments(functionSignature, [
takerToken.toLowerCase(),
makerToken.toLowerCase(), makerToken.toLowerCase(),
sellAmount sellAmount,
]); ]);
}, },
}
}; };
}
constructor( constructor(
address: string, address: string,
@ -491,7 +479,15 @@ public static async deployFrom0xArtifactAsync(
logDecodeDependencies?: { [contractName: string]: ContractAbi }, logDecodeDependencies?: { [contractName: string]: ContractAbi },
deployedBytecode: string | undefined = ILiquidityProviderContract.deployedBytecode, deployedBytecode: string | undefined = ILiquidityProviderContract.deployedBytecode,
) { ) {
super('ILiquidityProvider', ILiquidityProviderContract.ABI(), address, supportedProvider, txDefaults, logDecodeDependencies, deployedBytecode); super(
'ILiquidityProvider',
ILiquidityProviderContract.ABI(),
address,
supportedProvider,
txDefaults,
logDecodeDependencies,
deployedBytecode,
);
classUtils.bindAll(this, ['_abiEncoderByFunctionSignature', 'address', '_web3Wrapper']); classUtils.bindAll(this, ['_abiEncoderByFunctionSignature', 'address', '_web3Wrapper']);
ILiquidityProviderContract.ABI().forEach((item, index) => { ILiquidityProviderContract.ABI().forEach((item, index) => {
if (item.type === 'function') { if (item.type === 'function') {

View File

@ -33,8 +33,6 @@ import { assert } from '@0x/assert';
import * as ethers from 'ethers'; import * as ethers from 'ethers';
// tslint:enable:no-unused-variable // tslint:enable:no-unused-variable
/* istanbul ignore next */ /* istanbul ignore next */
// tslint:disable:array-type // tslint:disable:array-type
// tslint:disable:no-parameter-reassignment // tslint:disable:no-parameter-reassignment
@ -50,7 +48,7 @@ public static async deployFrom0xArtifactAsync(
artifact: ContractArtifact | SimpleContractArtifact, artifact: ContractArtifact | SimpleContractArtifact,
supportedProvider: SupportedProvider, supportedProvider: SupportedProvider,
txDefaults: Partial<TxData>, txDefaults: Partial<TxData>,
logDecodeDependencies: { [contractName: string]: (ContractArtifact | SimpleContractArtifact) }, logDecodeDependencies: { [contractName: string]: ContractArtifact | SimpleContractArtifact },
): Promise<ILiquidityProviderRegistryContract> { ): Promise<ILiquidityProviderRegistryContract> {
assert.doesConformToSchema('txDefaults', txDefaults, schemas.txDataSchema, [ assert.doesConformToSchema('txDefaults', txDefaults, schemas.txDataSchema, [
schemas.addressSchema, schemas.addressSchema,
@ -69,7 +67,13 @@ public static async deployFrom0xArtifactAsync(
logDecodeDependenciesAbiOnly[key] = logDecodeDependencies[key].compilerOutput.abi; logDecodeDependenciesAbiOnly[key] = logDecodeDependencies[key].compilerOutput.abi;
} }
} }
return ILiquidityProviderRegistryContract.deployAsync(bytecode, abi, provider, txDefaults, logDecodeDependenciesAbiOnly, ); return ILiquidityProviderRegistryContract.deployAsync(
bytecode,
abi,
provider,
txDefaults,
logDecodeDependenciesAbiOnly,
);
} }
public static async deployWithLibrariesFrom0xArtifactAsync( public static async deployWithLibrariesFrom0xArtifactAsync(
@ -77,7 +81,7 @@ public static async deployFrom0xArtifactAsync(
libraryArtifacts: { [libraryName: string]: ContractArtifact }, libraryArtifacts: { [libraryName: string]: ContractArtifact },
supportedProvider: SupportedProvider, supportedProvider: SupportedProvider,
txDefaults: Partial<TxData>, txDefaults: Partial<TxData>,
logDecodeDependencies: { [contractName: string]: (ContractArtifact | SimpleContractArtifact) }, logDecodeDependencies: { [contractName: string]: ContractArtifact | SimpleContractArtifact },
): Promise<ILiquidityProviderRegistryContract> { ): Promise<ILiquidityProviderRegistryContract> {
assert.doesConformToSchema('txDefaults', txDefaults, schemas.txDataSchema, [ assert.doesConformToSchema('txDefaults', txDefaults, schemas.txDataSchema, [
schemas.addressSchema, schemas.addressSchema,
@ -99,13 +103,16 @@ public static async deployFrom0xArtifactAsync(
artifact, artifact,
libraryArtifacts, libraryArtifacts,
new Web3Wrapper(provider), new Web3Wrapper(provider),
txDefaults txDefaults,
); );
const bytecode = linkLibrariesInBytecode( const bytecode = linkLibrariesInBytecode(artifact, libraryAddresses);
artifact, return ILiquidityProviderRegistryContract.deployAsync(
libraryAddresses, bytecode,
abi,
provider,
txDefaults,
logDecodeDependenciesAbiOnly,
); );
return ILiquidityProviderRegistryContract.deployAsync(bytecode, abi, provider, txDefaults, logDecodeDependenciesAbiOnly, );
} }
public static async deployAsync( public static async deployAsync(
@ -123,11 +130,7 @@ public static async deployFrom0xArtifactAsync(
]); ]);
const provider = providerUtils.standardizeOrThrow(supportedProvider); const provider = providerUtils.standardizeOrThrow(supportedProvider);
const constructorAbi = BaseContract._lookupConstructorAbi(abi); const constructorAbi = BaseContract._lookupConstructorAbi(abi);
[] = BaseContract._formatABIDataItemList( [] = BaseContract._formatABIDataItemList(constructorAbi.inputs, [], BaseContract._bigNumberToString);
constructorAbi.inputs,
[],
BaseContract._bigNumberToString,
);
const iface = new ethers.utils.Interface(abi); const iface = new ethers.utils.Interface(abi);
const deployInfo = iface.deployFunction; const deployInfo = iface.deployFunction;
const txData = deployInfo.encode(bytecode, []); const txData = deployInfo.encode(bytecode, []);
@ -143,7 +146,12 @@ public static async deployFrom0xArtifactAsync(
logUtils.log(`transactionHash: ${txHash}`); logUtils.log(`transactionHash: ${txHash}`);
const txReceipt = await web3Wrapper.awaitTransactionSuccessAsync(txHash); const txReceipt = await web3Wrapper.awaitTransactionSuccessAsync(txHash);
logUtils.log(`ILiquidityProviderRegistry successfully deployed at ${txReceipt.contractAddress}`); logUtils.log(`ILiquidityProviderRegistry successfully deployed at ${txReceipt.contractAddress}`);
const contractInstance = new ILiquidityProviderRegistryContract(txReceipt.contractAddress as string, provider, txDefaults, logDecodeDependencies); const contractInstance = new ILiquidityProviderRegistryContract(
txReceipt.contractAddress as string,
provider,
txDefaults,
logDecodeDependencies,
);
contractInstance.constructorArgs = []; contractInstance.constructorArgs = [];
return contractInstance; return contractInstance;
} }
@ -206,10 +214,7 @@ public static async deployFrom0xArtifactAsync(
libraryAddresses, libraryAddresses,
); );
// Deploy this library. // Deploy this library.
const linkedLibraryBytecode = linkLibrariesInBytecode( const linkedLibraryBytecode = linkLibrariesInBytecode(libraryArtifact, libraryAddresses);
libraryArtifact,
libraryAddresses,
);
const txDataWithDefaults = await BaseContract._applyDefaultsToContractTxDataAsync( const txDataWithDefaults = await BaseContract._applyDefaultsToContractTxDataAsync(
{ {
data: linkedLibraryBytecode, data: linkedLibraryBytecode,
@ -265,38 +270,31 @@ public static async deployFrom0xArtifactAsync(
* @param makerToken Maker asset managed by liquidity provider. * @param makerToken Maker asset managed by liquidity provider.
* @returns Address of the liquidity provider. * @returns Address of the liquidity provider.
*/ */
public getLiquidityProviderForMarket( public getLiquidityProviderForMarket(takerToken: string, makerToken: string): ContractFunctionObj<string> {
takerToken: string, const self = (this as any) as ILiquidityProviderRegistryContract;
makerToken: string,
): ContractFunctionObj<string
> {
const self = this as any as ILiquidityProviderRegistryContract;
assert.isString('takerToken', takerToken); assert.isString('takerToken', takerToken);
assert.isString('makerToken', makerToken); assert.isString('makerToken', makerToken);
const functionSignature = 'getLiquidityProviderForMarket(address,address)'; const functionSignature = 'getLiquidityProviderForMarket(address,address)';
return { return {
async callAsync( async callAsync(callData: Partial<CallData> = {}, defaultBlock?: BlockParam): Promise<string> {
callData: Partial<CallData> = {},
defaultBlock?: BlockParam,
): Promise<string
> {
BaseContract._assertCallParams(callData, defaultBlock); BaseContract._assertCallParams(callData, defaultBlock);
const rawCallResult = await self._performCallAsync({ ...callData, data: this.getABIEncodedTransactionData() }, defaultBlock); const rawCallResult = await self._performCallAsync(
{ ...callData, data: this.getABIEncodedTransactionData() },
defaultBlock,
);
const abiEncoder = self._lookupAbiEncoder(functionSignature); const abiEncoder = self._lookupAbiEncoder(functionSignature);
BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder); BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder);
return abiEncoder.strictDecodeReturnValue<string return abiEncoder.strictDecodeReturnValue<string>(rawCallResult);
>(rawCallResult);
}, },
getABIEncodedTransactionData(): string { getABIEncodedTransactionData(): string {
return self._strictEncodeArguments(functionSignature, [takerToken.toLowerCase(), return self._strictEncodeArguments(functionSignature, [
makerToken.toLowerCase() takerToken.toLowerCase(),
makerToken.toLowerCase(),
]); ]);
}, },
}
}; };
}
constructor( constructor(
address: string, address: string,
@ -305,7 +303,15 @@ public static async deployFrom0xArtifactAsync(
logDecodeDependencies?: { [contractName: string]: ContractAbi }, logDecodeDependencies?: { [contractName: string]: ContractAbi },
deployedBytecode: string | undefined = ILiquidityProviderRegistryContract.deployedBytecode, deployedBytecode: string | undefined = ILiquidityProviderRegistryContract.deployedBytecode,
) { ) {
super('ILiquidityProviderRegistry', ILiquidityProviderRegistryContract.ABI(), address, supportedProvider, txDefaults, logDecodeDependencies, deployedBytecode); super(
'ILiquidityProviderRegistry',
ILiquidityProviderRegistryContract.ABI(),
address,
supportedProvider,
txDefaults,
logDecodeDependencies,
deployedBytecode,
);
classUtils.bindAll(this, ['_abiEncoderByFunctionSignature', 'address', '_web3Wrapper']); classUtils.bindAll(this, ['_abiEncoderByFunctionSignature', 'address', '_web3Wrapper']);
ILiquidityProviderRegistryContract.ABI().forEach((item, index) => { ILiquidityProviderRegistryContract.ABI().forEach((item, index) => {
if (item.type === 'function') { if (item.type === 'function') {