Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function findOrdersThatCoverAssetFillAmount(
orders: T[],
assetFillAmount: BigNumber,
operation: MarketOperation,
opts?: FindOrdersThatCoverTakerAssetFillAmountOpts | FindOrdersThatCoverMakerAssetFillAmountOpts,
): OrdersAndRemainingTakerFillAmount | OrdersAndRemainingMakerFillAmount {
const variablePrefix = operation === MarketOperation.Buy ? 'Maker' : 'Taker';
assert.doesConformToSchema('orders', orders, schemas.ordersSchema);
assert.isValidBaseUnitAmount('assetFillAmount', assetFillAmount);
// try to get remainingFillableTakerAssetAmounts from opts, if it's not there, use takerAssetAmount values from orders
const remainingFillableAssetAmounts = _.get(
opts,
`remainingFillable${variablePrefix}AssetAmounts`,
_.map(orders, order => (operation === MarketOperation.Buy ? order.makerAssetAmount : order.takerAssetAmount)),
) as BigNumber[];
_.forEach(remainingFillableAssetAmounts, (amount, index) =>
assert.isValidBaseUnitAmount(`remainingFillable${variablePrefix}AssetAmount[${index}]`, amount),
);
assert.assert(
orders.length === remainingFillableAssetAmounts.length,
`Expected orders.length to equal opts.remainingFillable${variablePrefix}AssetAmounts.length`,
);
// try to get slippageBufferAmount from opts, if it's not there, default to 0
const slippageBufferAmount = _.get(opts, 'slippageBufferAmount', constants.ZERO_AMOUNT) as BigNumber;
private async _batchFillAsync(
exchangeFn: ExchangeFunctionName,
orders: Order[],
takerAssetFillAmounts: BigNumber[],
signatures: string[],
txData: TxData,
sendTxOpts: SendTransactionOpts = { shouldValidate: true },
): Promise {
assert.doesConformToSchema('orders', orders, schemas.ordersSchema);
takerAssetFillAmounts.forEach(takerAssetFillAmount =>
assert.isValidBaseUnitAmount('takerAssetFillAmount', takerAssetFillAmount),
);
return this._executeTxThroughCoordinatorAsync(
exchangeFn,
txData,
sendTxOpts,
orders,
orders,
takerAssetFillAmounts,
signatures,
);
}
sortFeeOrdersByFeeAdjustedRate(feeOrders: T[]): T[] {
assert.doesConformToSchema('feeOrders', feeOrders, schemas.ordersSchema);
const rateCalculator = rateUtils.getFeeAdjustedRateOfFeeOrder.bind(rateUtils);
const sortedOrders = sortOrders(feeOrders, rateCalculator);
return sortedOrders;
},
};
sortOrdersByFeeAdjustedRate(orders: T[], feeRate: BigNumber = constants.ZERO_AMOUNT): T[] {
assert.doesConformToSchema('orders', orders, schemas.ordersSchema);
assert.isBigNumber('feeRate', feeRate);
const rateCalculator = (order: Order) => rateUtils.getFeeAdjustedRateOfOrder(order, feeRate);
const sortedOrders = sortOrders(orders, rateCalculator);
return sortedOrders;
},
/**
public async batchCancelOrdersAsync(
orders: Array,
orderTransactionOpts: OrderTransactionOpts = { shouldValidate: true },
): Promise {
assert.doesConformToSchema('orders', orders, schemas.ordersSchema);
assert.doesConformToSchema('orderTransactionOpts', orderTransactionOpts, orderTxOptsSchema, [txOptsSchema]);
const makerAddresses = _.map(orders, order => order.makerAddress);
const makerAddress = makerAddresses[0];
await assert.isSenderAddressAsync('makerAddress', makerAddress, this._web3Wrapper);
const normalizedMakerAddress = makerAddress.toLowerCase();
if (orderTransactionOpts.shouldValidate) {
await this._exchangeContract.batchCancelOrders.callAsync(orders, {
from: normalizedMakerAddress,
gas: orderTransactionOpts.gasLimit,
gasPrice: orderTransactionOpts.gasPrice,
nonce: orderTransactionOpts.nonce,
});
}
const txHash = await this._exchangeContract.batchCancelOrders.sendTransactionAsync(orders, {
from: normalizedMakerAddress,